mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Refactor package to new namespace
This commit is contained in:
1 parent
089759dbad
commit
fd1e5232e0
55 files changed
+5632
-5624
No files matched your search
+10
-10
@@ -16,18 +16,18 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat;
|
||||
package net.gravitydevelopment.anticheat;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.event.*;
|
||||
import net.h31ix.anticheat.manage.AnticheatManager;
|
||||
import net.h31ix.anticheat.manage.PacketManager;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.update.Updater;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.h31ix.anticheat.xray.XRayListener;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.event.*;
|
||||
import net.gravitydevelopment.anticheat.manage.AnticheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.PacketManager;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.update.Updater;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayListener;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
+489
-489
@@ -1,489 +1,489 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat;
|
||||
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.manage.UserManager;
|
||||
import net.h31ix.anticheat.util.*;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
private static final Configuration CONFIG = AntiCheat.getManager().getConfiguration();
|
||||
private static final UserManager USER_MANAGER = AntiCheat.getManager().getUserManager();
|
||||
private static final XRayTracker XRAY_TRACKER = AntiCheat.getManager().getXRayTracker();
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static final ChatColor YELLOW = ChatColor.YELLOW;
|
||||
private static final ChatColor GREEN = ChatColor.GREEN;
|
||||
private static final ChatColor WHITE = ChatColor.WHITE;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private List<String> high = new ArrayList<String>();
|
||||
private List<String> med = new ArrayList<String>();
|
||||
private List<String> low = new ArrayList<String>();
|
||||
private static final Server SERVER = Bukkit.getServer();
|
||||
private static final int MED_THRESHOLD = 20;
|
||||
private static final int HIGH_THRESHOLD = 50;
|
||||
private static final String PERMISSIONS_ERROR = RED + "Insufficient Permissions.";
|
||||
private static final String MENU_END = "-----------------------------------------------------";
|
||||
|
||||
public void handleLog(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_LOG)) {
|
||||
if (args[1].equalsIgnoreCase("enable")) {
|
||||
if (!CONFIG.getConfig().logToConsole.getValue()) {
|
||||
CONFIG.getConfig().logToConsole.setValue(true);
|
||||
cs.sendMessage(GREEN + "Console logging enabled.");
|
||||
CONFIG.getConfig().reload();
|
||||
} else {
|
||||
cs.sendMessage(GREEN + "Console logging is already enabled!");
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("disable")) {
|
||||
if (CONFIG.getConfig().logToConsole.getValue()) {
|
||||
CONFIG.getConfig().logToConsole.setValue(false);
|
||||
cs.sendMessage(GREEN + "Console logging disabled.");
|
||||
CONFIG.getConfig().reload();
|
||||
} else {
|
||||
cs.sendMessage(GREEN + "Console logging is already disabled!");
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "Usage: /anticheat log [enable/disable]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDebug(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_DEBUG)) {
|
||||
cs.sendMessage(GRAY + "Please wait while I collect some data...");
|
||||
PastebinReport report = new PastebinReport(cs);
|
||||
cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL());
|
||||
cs.sendMessage(GREEN + "Please include this link when making bug reports.");
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDebug(CommandSender cs, Player tp) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
cs.sendMessage(GRAY + "Please wait while I collect some data...");
|
||||
PastebinReport report = new PastebinReport(cs, tp);
|
||||
cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL());
|
||||
cs.sendMessage(GREEN + "Please include this link when making bug reports.");
|
||||
}
|
||||
}
|
||||
|
||||
public void handleXRay(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_XRAY)) {
|
||||
if (CONFIG.getConfig().logXRayStats.getValue()) {
|
||||
List<Player> list = SERVER.matchPlayer(args[1]);
|
||||
if (list.size() == 1) {
|
||||
Player player = list.get(0);
|
||||
if (XRAY_TRACKER.sufficientData(player.getName())) {
|
||||
XRAY_TRACKER.sendStats(cs, player.getName());
|
||||
} else {
|
||||
cs.sendMessage(RED + "Insufficient data collected from " + WHITE + args[1] + RED + ".");
|
||||
cs.sendMessage(RED + "Please wait until more info is collected before predictions are calculated.");
|
||||
}
|
||||
} else if (list.size() > 1) {
|
||||
cs.sendMessage(RED + "Multiple players found by name: " + WHITE + args[1] + RED + ".");
|
||||
} else if (XRAY_TRACKER.sufficientData(args[1])) {
|
||||
XRAY_TRACKER.sendStats(cs, args[1]);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Insufficient data collected from " + WHITE + args[1] + RED + ".");
|
||||
cs.sendMessage(RED + "Please wait until more info is collected before predictions are calculated.");
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "XRay logging is off in the config.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleReset(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_RESET)) {
|
||||
List<Player> list = SERVER.matchPlayer(args[1]);
|
||||
if (list.size() == 1) {
|
||||
Player player = list.get(0);
|
||||
User user = USER_MANAGER.getUser(player.getName());
|
||||
if (user != null) {
|
||||
user.resetLevel();
|
||||
XRAY_TRACKER.reset(player.getName());
|
||||
user.clearMessages();
|
||||
AntiCheat.getManager().getBackend().resetChatLevel(player);
|
||||
cs.sendMessage(player.getName() + GREEN + " has been reset.");
|
||||
} else {
|
||||
|
||||
}
|
||||
} else if (list.size() > 1) {
|
||||
cs.sendMessage(RED + "Multiple players found by name: " + WHITE + args[1] + RED + ".");
|
||||
} else {
|
||||
cs.sendMessage(RED + "Player: " + WHITE + args[1] + RED + " not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleSpy(CommandSender cs, String[] args) {
|
||||
if (cs instanceof Player) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_SPY)) {
|
||||
Player sender = (Player) cs;
|
||||
if (!args[1].equalsIgnoreCase("off")) {
|
||||
List<Player> list = SERVER.matchPlayer(args[1]);
|
||||
if (list.size() == 1) {
|
||||
Player player = list.get(0);
|
||||
for (Player p : cs.getServer().getOnlinePlayers()) {
|
||||
if (!Permission.SYSTEM_SPY.get(p)) {
|
||||
p.hidePlayer(sender);
|
||||
}
|
||||
}
|
||||
if (!sender.hasMetadata(Utilities.SPY_METADATA)) // Maintain ORIGINAL location and other data
|
||||
{
|
||||
SpyState state = new SpyState(sender.getAllowFlight(), sender.isFlying(), sender.getLocation());
|
||||
sender.setMetadata(Utilities.SPY_METADATA, new FixedMetadataValue(AntiCheat.getPlugin(), state));
|
||||
}
|
||||
sender.setAllowFlight(true);
|
||||
sender.setFlying(true);
|
||||
sender.teleport(player);
|
||||
sender.sendMessage(GREEN + "You have been teleported to " + player.getName() + " and made invisible.");
|
||||
sender.sendMessage(GREEN + "To stop spying, type " + WHITE + " /AntiCheat spy off");
|
||||
} else if (list.size() > 1) {
|
||||
cs.sendMessage(RED + "Multiple players found by name: " + WHITE + args[1] + RED + ".");
|
||||
} else {
|
||||
cs.sendMessage(RED + "Player: " + WHITE + args[1] + RED + " not found.");
|
||||
}
|
||||
} else {
|
||||
if (sender.hasMetadata(Utilities.SPY_METADATA)) {
|
||||
SpyState state = ((SpyState) sender.getMetadata(Utilities.SPY_METADATA).get(0).value());
|
||||
sender.setAllowFlight(state.getAllowFlight());
|
||||
sender.setFlying(state.getFlying());
|
||||
sender.teleport(state.getLocation());
|
||||
sender.removeMetadata(Utilities.SPY_METADATA, AntiCheat.getPlugin());
|
||||
for (Player p : cs.getServer().getOnlinePlayers()) {
|
||||
p.showPlayer(sender);
|
||||
}
|
||||
sender.sendMessage(GREEN + "Done spying! Brought you back to where you started!");
|
||||
} else {
|
||||
sender.sendMessage(RED + "You were not spying.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "Sorry, but you can't spy on a player from the console.");
|
||||
}
|
||||
}
|
||||
|
||||
public void handleHelp(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_HELP)) {
|
||||
String base = "/AntiCheat ";
|
||||
String[] lines = {
|
||||
"log [Enable/Disable]" + WHITE + " - toggle logging",
|
||||
"report [low/medium/high]" + WHITE + " - show users in groups",
|
||||
"report [user]" + WHITE + " - get a player's cheat report",
|
||||
"reload" + WHITE + " - reload AntiCheat configuration",
|
||||
"reset [user]" + WHITE + " - reset user's hack level",
|
||||
"xray [user]" + WHITE + " - check user's xray levels",
|
||||
"spy [user]" + WHITE + " - spy on a user in secret",
|
||||
"help" + WHITE + " - access this page",
|
||||
"debug" + WHITE + " - post debug information",
|
||||
"update" + WHITE + " - check update status",
|
||||
};
|
||||
|
||||
cs.sendMessage("----------------------[" + GREEN + "AntiCheat" + WHITE + "]----------------------");
|
||||
for (String s : lines) {
|
||||
cs.sendMessage(base + GREEN + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleUpdate(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_UPDATE)) {
|
||||
cs.sendMessage("Running " + GREEN + "AntiCheat " + WHITE + "v" + GREEN + AntiCheat.getVersion());
|
||||
cs.sendMessage(MENU_END);
|
||||
if (!AntiCheat.isUpdated()) {
|
||||
cs.sendMessage(GRAY + "There " + GREEN + "IS" + GRAY + " a newer version avaliable.");
|
||||
if (CONFIG.getConfig().autoUpdate.getValue()) {
|
||||
cs.sendMessage(GRAY + "It will be installed automatically for you on next launch.");
|
||||
} else {
|
||||
cs.sendMessage(GRAY + "Due to your config settings, we " + RED + "can not" + GRAY + " auto update.");
|
||||
cs.sendMessage(GRAY + "Please visit http://dev.bukkit.org/server-mods/anticheat/");
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(GRAY + "AntiCheat is " + GREEN + "UP TO DATE!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleCalibrate(CommandSender cs) {
|
||||
if (cs instanceof Player) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_CALIBRATE)) {
|
||||
Calibrator c = new Calibrator((Player) cs);
|
||||
SERVER.getPluginManager().registerEvents(c, AntiCheat.getPlugin());
|
||||
c.calibrate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleReport(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
getPlayers();
|
||||
if (args.length > 1) {
|
||||
String group = args[1];
|
||||
if (group.equalsIgnoreCase("low")) {
|
||||
int num = getReportPageNum(args);
|
||||
if (num > 0) {
|
||||
sendReport(cs, low, "Low", GREEN, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
} else if (group.equalsIgnoreCase("medium")) {
|
||||
int num = getReportPageNum(args);
|
||||
if (num > 0) {
|
||||
sendReport(cs, med, "Medium", YELLOW, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
}
|
||||
if (group.equalsIgnoreCase("high")) {
|
||||
int num = getReportPageNum(args);
|
||||
if (num > 0) {
|
||||
sendReport(cs, high, "High", RED, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getReportPageNum(String[] args) {
|
||||
if (args.length == 2) {
|
||||
return 1;
|
||||
} else if (Utilities.isInt(args[2])) {
|
||||
return Integer.parseInt(args[2]);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendReport(CommandSender cs, List<String> players, String group, ChatColor color, int page) {
|
||||
int pages = (int) Math.ceil(((float) players.size()) / 7);
|
||||
if (page <= pages && page > 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Group: " + color + group);
|
||||
for (int x = 0; x < 7; x++) {
|
||||
int index = ((page - 1) * 6) + (x + ((page - 1) * 1));
|
||||
if (index < players.size()) {
|
||||
String player = players.get(index);
|
||||
cs.sendMessage(GRAY + player);
|
||||
}
|
||||
}
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
if (pages == 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[1/1]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Group: " + color + group);
|
||||
cs.sendMessage(GRAY + "There are no users in this group.");
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Page not found. Requested " + WHITE + page + RED + ", Max " + WHITE + pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePlayerReport(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
User user = AntiCheat.getManager().getUserManager().getUser(args[1]);
|
||||
boolean cont = false;
|
||||
if (user == null) {
|
||||
if ((user = AntiCheat.getManager().getUserManager().getUser(args[1])) == null) {
|
||||
cs.sendMessage(RED + "Player: " + WHITE + args[1] + RED + " not found.");
|
||||
} else {
|
||||
cont = true;
|
||||
}
|
||||
} else {
|
||||
cont = true;
|
||||
}
|
||||
if (cont) {
|
||||
List<CheckType> l = new ArrayList<CheckType>();
|
||||
for (CheckType type : CheckType.values()) {
|
||||
if (type.getUses(user.getName()) > 0) {
|
||||
l.add(type);
|
||||
}
|
||||
}
|
||||
if (args.length == 2) {
|
||||
sendPlayerReport(cs, l, user, 1);
|
||||
} else if (Utilities.isInt(args[2])) {
|
||||
int num = Integer.parseInt(args[2]);
|
||||
sendPlayerReport(cs, l, user, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDeveloper(CommandSender cs) {
|
||||
AntiCheat.setDeveloperMode(!AntiCheat.developerMode());
|
||||
cs.sendMessage(ChatColor.GREEN + "Developer mode " + (AntiCheat.developerMode() ? "ON" : "OFF"));
|
||||
}
|
||||
|
||||
public void sendPlayerReport(CommandSender cs, List<CheckType> types, User user, int page) {
|
||||
String name = user.getName();
|
||||
int pages = (int) Math.ceil(((float) types.size()) / 6);
|
||||
|
||||
Level level = user.getNamedLevel();
|
||||
String levelString = ChatColor.GREEN + "Low";
|
||||
|
||||
if (level != null) {
|
||||
levelString = level.getColor() + level.getName();
|
||||
}
|
||||
levelString += " (" + user.getLevel() + ")";
|
||||
|
||||
if (page <= pages && page > 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Player: " + WHITE + name);
|
||||
cs.sendMessage(GRAY + "Level: " + levelString);
|
||||
for (int x = 0; x < 6; x++) {
|
||||
int index = ((page - 1) * 5) + (x + ((page - 1)));
|
||||
if (index < types.size()) {
|
||||
int use = types.get(index).getUses(name);
|
||||
ChatColor color = WHITE;
|
||||
if (use >= 20) {
|
||||
color = YELLOW;
|
||||
} else if (use > 50) {
|
||||
color = RED;
|
||||
}
|
||||
cs.sendMessage(GRAY + CheckType.getName(types.get(index)) + ": " + color + use);
|
||||
}
|
||||
}
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
if (pages == 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[1/1]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Player: " + WHITE + name);
|
||||
cs.sendMessage(GRAY + "Level: " + levelString);
|
||||
cs.sendMessage(GRAY + "This user has not failed any checks.");
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Page not found. Requested " + WHITE + page + RED + ", Max " + WHITE + pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleReload(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_RELOAD)) {
|
||||
CONFIG.load();
|
||||
cs.sendMessage(GREEN + "AntiCheat configuration reloaded.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
|
||||
if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("report")) {
|
||||
for (Level level : CONFIG.getEvents().getLevels()) {
|
||||
if (args[1].equalsIgnoreCase(level.getName())) {
|
||||
handleReport(cs, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
handlePlayerReport(cs, args);
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("log")) {
|
||||
handleLog(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("xray")) {
|
||||
handleXRay(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("debug")) {
|
||||
handleDebug(cs, Bukkit.getPlayer(args[1]));
|
||||
} else if (args[0].equalsIgnoreCase("reset")) {
|
||||
handleReset(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("spy")) {
|
||||
handleSpy(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("report")) {
|
||||
if (args[1].equalsIgnoreCase("low") || args[1].equalsIgnoreCase("medium") || args[1].equalsIgnoreCase("high")) {
|
||||
handleReport(cs, args);
|
||||
} else {
|
||||
handlePlayerReport(cs, args);
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "Unrecognized command.");
|
||||
}
|
||||
} else if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
handleHelp(cs);
|
||||
} else if (args[0].equalsIgnoreCase("debug")) {
|
||||
handleDebug(cs);
|
||||
} else if (args[0].equalsIgnoreCase("report")) {
|
||||
cs.sendMessage(ChatColor.GREEN + "To see the report of a specific user, type their name, like so:");
|
||||
cs.sendMessage(ChatColor.WHITE + "/anticheat report [user]");
|
||||
cs.sendMessage(ChatColor.GRAY + " - This will allow you to see the checks that user has failed.");
|
||||
cs.sendMessage(ChatColor.GREEN + "To see the report of an AntiCheat group, type it's name, like so:");
|
||||
cs.sendMessage(ChatColor.WHITE + "/anticheat report [low/medium/high]");
|
||||
cs.sendMessage(ChatColor.GRAY + " - This will allow you to see which players are good, and which could be hacking.");
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
handleReload(cs);
|
||||
} else if (args[0].equalsIgnoreCase("update")) {
|
||||
handleUpdate(cs);
|
||||
} else if (args[0].equalsIgnoreCase("developer")) {
|
||||
handleDeveloper(cs);
|
||||
}
|
||||
/**
|
||||
* else if (args[0].equalsIgnoreCase("calibrate")) { handleCalibrate(cs); }
|
||||
*/
|
||||
else {
|
||||
cs.sendMessage(RED + "Unrecognized command.");
|
||||
}
|
||||
} else {
|
||||
handleHelp(cs); // Handle no args as alias of help
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void getPlayers() {
|
||||
high.clear();
|
||||
med.clear();
|
||||
low.clear();
|
||||
for (Player player : SERVER.getOnlinePlayers()) {
|
||||
int level = USER_MANAGER.safeGetLevel(player.getName());
|
||||
if (level <= MED_THRESHOLD) {
|
||||
low.add(player.getName());
|
||||
} else if (level <= HIGH_THRESHOLD) {
|
||||
med.add(player.getName());
|
||||
} else {
|
||||
high.add(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender cs, Permission perm) {
|
||||
if (perm.get(cs)) {
|
||||
return true;
|
||||
} else {
|
||||
cs.sendMessage(PERMISSIONS_ERROR + " (" + WHITE + perm.toString() + RED + ")");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat;
|
||||
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.manage.UserManager;
|
||||
import net.gravitydevelopment.anticheat.util.*;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandHandler implements CommandExecutor {
|
||||
private static final Configuration CONFIG = AntiCheat.getManager().getConfiguration();
|
||||
private static final UserManager USER_MANAGER = AntiCheat.getManager().getUserManager();
|
||||
private static final XRayTracker XRAY_TRACKER = AntiCheat.getManager().getXRayTracker();
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static final ChatColor YELLOW = ChatColor.YELLOW;
|
||||
private static final ChatColor GREEN = ChatColor.GREEN;
|
||||
private static final ChatColor WHITE = ChatColor.WHITE;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private List<String> high = new ArrayList<String>();
|
||||
private List<String> med = new ArrayList<String>();
|
||||
private List<String> low = new ArrayList<String>();
|
||||
private static final Server SERVER = Bukkit.getServer();
|
||||
private static final int MED_THRESHOLD = 20;
|
||||
private static final int HIGH_THRESHOLD = 50;
|
||||
private static final String PERMISSIONS_ERROR = RED + "Insufficient Permissions.";
|
||||
private static final String MENU_END = "-----------------------------------------------------";
|
||||
|
||||
public void handleLog(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_LOG)) {
|
||||
if (args[1].equalsIgnoreCase("enable")) {
|
||||
if (!CONFIG.getConfig().logToConsole.getValue()) {
|
||||
CONFIG.getConfig().logToConsole.setValue(true);
|
||||
cs.sendMessage(GREEN + "Console logging enabled.");
|
||||
CONFIG.getConfig().reload();
|
||||
} else {
|
||||
cs.sendMessage(GREEN + "Console logging is already enabled!");
|
||||
}
|
||||
} else if (args[1].equalsIgnoreCase("disable")) {
|
||||
if (CONFIG.getConfig().logToConsole.getValue()) {
|
||||
CONFIG.getConfig().logToConsole.setValue(false);
|
||||
cs.sendMessage(GREEN + "Console logging disabled.");
|
||||
CONFIG.getConfig().reload();
|
||||
} else {
|
||||
cs.sendMessage(GREEN + "Console logging is already disabled!");
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "Usage: /anticheat log [enable/disable]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDebug(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_DEBUG)) {
|
||||
cs.sendMessage(GRAY + "Please wait while I collect some data...");
|
||||
PastebinReport report = new PastebinReport(cs);
|
||||
cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL());
|
||||
cs.sendMessage(GREEN + "Please include this link when making bug reports.");
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDebug(CommandSender cs, Player tp) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
cs.sendMessage(GRAY + "Please wait while I collect some data...");
|
||||
PastebinReport report = new PastebinReport(cs, tp);
|
||||
cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL());
|
||||
cs.sendMessage(GREEN + "Please include this link when making bug reports.");
|
||||
}
|
||||
}
|
||||
|
||||
public void handleXRay(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_XRAY)) {
|
||||
if (CONFIG.getConfig().logXRayStats.getValue()) {
|
||||
List<Player> list = SERVER.matchPlayer(args[1]);
|
||||
if (list.size() == 1) {
|
||||
Player player = list.get(0);
|
||||
if (XRAY_TRACKER.sufficientData(player.getName())) {
|
||||
XRAY_TRACKER.sendStats(cs, player.getName());
|
||||
} else {
|
||||
cs.sendMessage(RED + "Insufficient data collected from " + WHITE + args[1] + RED + ".");
|
||||
cs.sendMessage(RED + "Please wait until more info is collected before predictions are calculated.");
|
||||
}
|
||||
} else if (list.size() > 1) {
|
||||
cs.sendMessage(RED + "Multiple players found by name: " + WHITE + args[1] + RED + ".");
|
||||
} else if (XRAY_TRACKER.sufficientData(args[1])) {
|
||||
XRAY_TRACKER.sendStats(cs, args[1]);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Insufficient data collected from " + WHITE + args[1] + RED + ".");
|
||||
cs.sendMessage(RED + "Please wait until more info is collected before predictions are calculated.");
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "XRay logging is off in the config.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleReset(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_RESET)) {
|
||||
List<Player> list = SERVER.matchPlayer(args[1]);
|
||||
if (list.size() == 1) {
|
||||
Player player = list.get(0);
|
||||
User user = USER_MANAGER.getUser(player.getName());
|
||||
if (user != null) {
|
||||
user.resetLevel();
|
||||
XRAY_TRACKER.reset(player.getName());
|
||||
user.clearMessages();
|
||||
AntiCheat.getManager().getBackend().resetChatLevel(player);
|
||||
cs.sendMessage(player.getName() + GREEN + " has been reset.");
|
||||
} else {
|
||||
|
||||
}
|
||||
} else if (list.size() > 1) {
|
||||
cs.sendMessage(RED + "Multiple players found by name: " + WHITE + args[1] + RED + ".");
|
||||
} else {
|
||||
cs.sendMessage(RED + "Player: " + WHITE + args[1] + RED + " not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleSpy(CommandSender cs, String[] args) {
|
||||
if (cs instanceof Player) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_SPY)) {
|
||||
Player sender = (Player) cs;
|
||||
if (!args[1].equalsIgnoreCase("off")) {
|
||||
List<Player> list = SERVER.matchPlayer(args[1]);
|
||||
if (list.size() == 1) {
|
||||
Player player = list.get(0);
|
||||
for (Player p : cs.getServer().getOnlinePlayers()) {
|
||||
if (!Permission.SYSTEM_SPY.get(p)) {
|
||||
p.hidePlayer(sender);
|
||||
}
|
||||
}
|
||||
if (!sender.hasMetadata(Utilities.SPY_METADATA)) // Maintain ORIGINAL location and other data
|
||||
{
|
||||
SpyState state = new SpyState(sender.getAllowFlight(), sender.isFlying(), sender.getLocation());
|
||||
sender.setMetadata(Utilities.SPY_METADATA, new FixedMetadataValue(AntiCheat.getPlugin(), state));
|
||||
}
|
||||
sender.setAllowFlight(true);
|
||||
sender.setFlying(true);
|
||||
sender.teleport(player);
|
||||
sender.sendMessage(GREEN + "You have been teleported to " + player.getName() + " and made invisible.");
|
||||
sender.sendMessage(GREEN + "To stop spying, type " + WHITE + " /AntiCheat spy off");
|
||||
} else if (list.size() > 1) {
|
||||
cs.sendMessage(RED + "Multiple players found by name: " + WHITE + args[1] + RED + ".");
|
||||
} else {
|
||||
cs.sendMessage(RED + "Player: " + WHITE + args[1] + RED + " not found.");
|
||||
}
|
||||
} else {
|
||||
if (sender.hasMetadata(Utilities.SPY_METADATA)) {
|
||||
SpyState state = ((SpyState) sender.getMetadata(Utilities.SPY_METADATA).get(0).value());
|
||||
sender.setAllowFlight(state.getAllowFlight());
|
||||
sender.setFlying(state.getFlying());
|
||||
sender.teleport(state.getLocation());
|
||||
sender.removeMetadata(Utilities.SPY_METADATA, AntiCheat.getPlugin());
|
||||
for (Player p : cs.getServer().getOnlinePlayers()) {
|
||||
p.showPlayer(sender);
|
||||
}
|
||||
sender.sendMessage(GREEN + "Done spying! Brought you back to where you started!");
|
||||
} else {
|
||||
sender.sendMessage(RED + "You were not spying.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "Sorry, but you can't spy on a player from the console.");
|
||||
}
|
||||
}
|
||||
|
||||
public void handleHelp(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_HELP)) {
|
||||
String base = "/AntiCheat ";
|
||||
String[] lines = {
|
||||
"log [Enable/Disable]" + WHITE + " - toggle logging",
|
||||
"report [low/medium/high]" + WHITE + " - show users in groups",
|
||||
"report [user]" + WHITE + " - get a player's cheat report",
|
||||
"reload" + WHITE + " - reload AntiCheat configuration",
|
||||
"reset [user]" + WHITE + " - reset user's hack level",
|
||||
"xray [user]" + WHITE + " - check user's xray levels",
|
||||
"spy [user]" + WHITE + " - spy on a user in secret",
|
||||
"help" + WHITE + " - access this page",
|
||||
"debug" + WHITE + " - post debug information",
|
||||
"update" + WHITE + " - check update status",
|
||||
};
|
||||
|
||||
cs.sendMessage("----------------------[" + GREEN + "AntiCheat" + WHITE + "]----------------------");
|
||||
for (String s : lines) {
|
||||
cs.sendMessage(base + GREEN + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleUpdate(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_UPDATE)) {
|
||||
cs.sendMessage("Running " + GREEN + "AntiCheat " + WHITE + "v" + GREEN + AntiCheat.getVersion());
|
||||
cs.sendMessage(MENU_END);
|
||||
if (!AntiCheat.isUpdated()) {
|
||||
cs.sendMessage(GRAY + "There " + GREEN + "IS" + GRAY + " a newer version avaliable.");
|
||||
if (CONFIG.getConfig().autoUpdate.getValue()) {
|
||||
cs.sendMessage(GRAY + "It will be installed automatically for you on next launch.");
|
||||
} else {
|
||||
cs.sendMessage(GRAY + "Due to your config settings, we " + RED + "can not" + GRAY + " auto update.");
|
||||
cs.sendMessage(GRAY + "Please visit http://dev.bukkit.org/server-mods/anticheat/");
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(GRAY + "AntiCheat is " + GREEN + "UP TO DATE!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleCalibrate(CommandSender cs) {
|
||||
if (cs instanceof Player) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_CALIBRATE)) {
|
||||
Calibrator c = new Calibrator((Player) cs);
|
||||
SERVER.getPluginManager().registerEvents(c, AntiCheat.getPlugin());
|
||||
c.calibrate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleReport(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
getPlayers();
|
||||
if (args.length > 1) {
|
||||
String group = args[1];
|
||||
if (group.equalsIgnoreCase("low")) {
|
||||
int num = getReportPageNum(args);
|
||||
if (num > 0) {
|
||||
sendReport(cs, low, "Low", GREEN, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
} else if (group.equalsIgnoreCase("medium")) {
|
||||
int num = getReportPageNum(args);
|
||||
if (num > 0) {
|
||||
sendReport(cs, med, "Medium", YELLOW, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
}
|
||||
if (group.equalsIgnoreCase("high")) {
|
||||
int num = getReportPageNum(args);
|
||||
if (num > 0) {
|
||||
sendReport(cs, high, "High", RED, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getReportPageNum(String[] args) {
|
||||
if (args.length == 2) {
|
||||
return 1;
|
||||
} else if (Utilities.isInt(args[2])) {
|
||||
return Integer.parseInt(args[2]);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendReport(CommandSender cs, List<String> players, String group, ChatColor color, int page) {
|
||||
int pages = (int) Math.ceil(((float) players.size()) / 7);
|
||||
if (page <= pages && page > 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Group: " + color + group);
|
||||
for (int x = 0; x < 7; x++) {
|
||||
int index = ((page - 1) * 6) + (x + ((page - 1) * 1));
|
||||
if (index < players.size()) {
|
||||
String player = players.get(index);
|
||||
cs.sendMessage(GRAY + player);
|
||||
}
|
||||
}
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
if (pages == 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[1/1]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Group: " + color + group);
|
||||
cs.sendMessage(GRAY + "There are no users in this group.");
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Page not found. Requested " + WHITE + page + RED + ", Max " + WHITE + pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePlayerReport(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
User user = AntiCheat.getManager().getUserManager().getUser(args[1]);
|
||||
boolean cont = false;
|
||||
if (user == null) {
|
||||
if ((user = AntiCheat.getManager().getUserManager().getUser(args[1])) == null) {
|
||||
cs.sendMessage(RED + "Player: " + WHITE + args[1] + RED + " not found.");
|
||||
} else {
|
||||
cont = true;
|
||||
}
|
||||
} else {
|
||||
cont = true;
|
||||
}
|
||||
if (cont) {
|
||||
List<CheckType> l = new ArrayList<CheckType>();
|
||||
for (CheckType type : CheckType.values()) {
|
||||
if (type.getUses(user.getName()) > 0) {
|
||||
l.add(type);
|
||||
}
|
||||
}
|
||||
if (args.length == 2) {
|
||||
sendPlayerReport(cs, l, user, 1);
|
||||
} else if (Utilities.isInt(args[2])) {
|
||||
int num = Integer.parseInt(args[2]);
|
||||
sendPlayerReport(cs, l, user, num);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Not a valid page number: " + WHITE + args[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDeveloper(CommandSender cs) {
|
||||
AntiCheat.setDeveloperMode(!AntiCheat.developerMode());
|
||||
cs.sendMessage(ChatColor.GREEN + "Developer mode " + (AntiCheat.developerMode() ? "ON" : "OFF"));
|
||||
}
|
||||
|
||||
public void sendPlayerReport(CommandSender cs, List<CheckType> types, User user, int page) {
|
||||
String name = user.getName();
|
||||
int pages = (int) Math.ceil(((float) types.size()) / 6);
|
||||
|
||||
Level level = user.getNamedLevel();
|
||||
String levelString = ChatColor.GREEN + "Low";
|
||||
|
||||
if (level != null) {
|
||||
levelString = level.getColor() + level.getName();
|
||||
}
|
||||
levelString += " (" + user.getLevel() + ")";
|
||||
|
||||
if (page <= pages && page > 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Player: " + WHITE + name);
|
||||
cs.sendMessage(GRAY + "Level: " + levelString);
|
||||
for (int x = 0; x < 6; x++) {
|
||||
int index = ((page - 1) * 5) + (x + ((page - 1)));
|
||||
if (index < types.size()) {
|
||||
int use = types.get(index).getUses(name);
|
||||
ChatColor color = WHITE;
|
||||
if (use >= 20) {
|
||||
color = YELLOW;
|
||||
} else if (use > 50) {
|
||||
color = RED;
|
||||
}
|
||||
cs.sendMessage(GRAY + CheckType.getName(types.get(index)) + ": " + color + use);
|
||||
}
|
||||
}
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
if (pages == 0) {
|
||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[1/1]" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Player: " + WHITE + name);
|
||||
cs.sendMessage(GRAY + "Level: " + levelString);
|
||||
cs.sendMessage(GRAY + "This user has not failed any checks.");
|
||||
cs.sendMessage(MENU_END);
|
||||
} else {
|
||||
cs.sendMessage(RED + "Page not found. Requested " + WHITE + page + RED + ", Max " + WHITE + pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleReload(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_RELOAD)) {
|
||||
CONFIG.load();
|
||||
cs.sendMessage(GREEN + "AntiCheat configuration reloaded.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
|
||||
if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("report")) {
|
||||
for (Level level : CONFIG.getEvents().getLevels()) {
|
||||
if (args[1].equalsIgnoreCase(level.getName())) {
|
||||
handleReport(cs, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
handlePlayerReport(cs, args);
|
||||
}
|
||||
} else if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("log")) {
|
||||
handleLog(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("xray")) {
|
||||
handleXRay(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("debug")) {
|
||||
handleDebug(cs, Bukkit.getPlayer(args[1]));
|
||||
} else if (args[0].equalsIgnoreCase("reset")) {
|
||||
handleReset(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("spy")) {
|
||||
handleSpy(cs, args);
|
||||
} else if (args[0].equalsIgnoreCase("report")) {
|
||||
if (args[1].equalsIgnoreCase("low") || args[1].equalsIgnoreCase("medium") || args[1].equalsIgnoreCase("high")) {
|
||||
handleReport(cs, args);
|
||||
} else {
|
||||
handlePlayerReport(cs, args);
|
||||
}
|
||||
} else {
|
||||
cs.sendMessage(RED + "Unrecognized command.");
|
||||
}
|
||||
} else if (args.length == 1) {
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
handleHelp(cs);
|
||||
} else if (args[0].equalsIgnoreCase("debug")) {
|
||||
handleDebug(cs);
|
||||
} else if (args[0].equalsIgnoreCase("report")) {
|
||||
cs.sendMessage(ChatColor.GREEN + "To see the report of a specific user, type their name, like so:");
|
||||
cs.sendMessage(ChatColor.WHITE + "/anticheat report [user]");
|
||||
cs.sendMessage(ChatColor.GRAY + " - This will allow you to see the checks that user has failed.");
|
||||
cs.sendMessage(ChatColor.GREEN + "To see the report of an AntiCheat group, type it's name, like so:");
|
||||
cs.sendMessage(ChatColor.WHITE + "/anticheat report [low/medium/high]");
|
||||
cs.sendMessage(ChatColor.GRAY + " - This will allow you to see which players are good, and which could be hacking.");
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
handleReload(cs);
|
||||
} else if (args[0].equalsIgnoreCase("update")) {
|
||||
handleUpdate(cs);
|
||||
} else if (args[0].equalsIgnoreCase("developer")) {
|
||||
handleDeveloper(cs);
|
||||
}
|
||||
/**
|
||||
* else if (args[0].equalsIgnoreCase("calibrate")) { handleCalibrate(cs); }
|
||||
*/
|
||||
else {
|
||||
cs.sendMessage(RED + "Unrecognized command.");
|
||||
}
|
||||
} else {
|
||||
handleHelp(cs); // Handle no args as alias of help
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void getPlayers() {
|
||||
high.clear();
|
||||
med.clear();
|
||||
low.clear();
|
||||
for (Player player : SERVER.getOnlinePlayers()) {
|
||||
int level = USER_MANAGER.safeGetLevel(player.getName());
|
||||
if (level <= MED_THRESHOLD) {
|
||||
low.add(player.getName());
|
||||
} else if (level <= HIGH_THRESHOLD) {
|
||||
med.add(player.getName());
|
||||
} else {
|
||||
high.add(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender cs, Permission perm) {
|
||||
if (perm.get(cs)) {
|
||||
return true;
|
||||
} else {
|
||||
cs.sendMessage(PERMISSIONS_ERROR + " (" + WHITE + perm.toString() + RED + ")");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+156
-156
@@ -1,156 +1,156 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.api;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.AnticheatManager;
|
||||
import net.h31ix.anticheat.manage.CheckManager;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.UserManager;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Developer's interface for all things AntiCheat.
|
||||
*/
|
||||
|
||||
public class AnticheatAPI {
|
||||
private static CheckManager chk = AntiCheat.getManager().getCheckManager();
|
||||
private static UserManager umr = AntiCheat.getManager().getUserManager();
|
||||
private static XRayTracker xtracker = AntiCheat.getManager().getXRayTracker();
|
||||
|
||||
// CheckManager API
|
||||
|
||||
/**
|
||||
* Start running a certain check
|
||||
*
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
public static void activateCheck(CheckType type) {
|
||||
chk.activateCheck(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop running a certain check
|
||||
*
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void deactivateCheck(CheckType type) {
|
||||
chk.deactivateCheck(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if a check is currently being watched for
|
||||
*
|
||||
* @param type Type to check
|
||||
* @return true if plugin is watching for this check
|
||||
*/
|
||||
public static boolean isActive(CheckType type) {
|
||||
return chk.isActive(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow a player to skip a certain check
|
||||
*
|
||||
* @param player Player to stop watching
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void exemptPlayer(Player player, CheckType type) {
|
||||
chk.exemptPlayer(player, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop allowing a player to skip a certain check
|
||||
*
|
||||
* @param player Player to start watching
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
public static void unexemptPlayer(Player player, CheckType type) {
|
||||
chk.unexemptPlayer(player, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if a player is currently exempt from a certain check
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param type Type to check
|
||||
* @return true if plugin is ignoring this check on this player
|
||||
*/
|
||||
public static boolean isExempt(Player player, CheckType type) {
|
||||
return chk.isExempt(player, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if a check will occur for a player. This checks if they are being tracked, the check is active, the player isn't exempt from the check, and the player doesn't have override permission.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param type Type to check
|
||||
* @return true if plugin will check this player, and that all things allow it to happen.
|
||||
*/
|
||||
public boolean willCheck(Player player, CheckType type) {
|
||||
return chk.willCheck(player, type);
|
||||
}
|
||||
|
||||
// PlayerManager API
|
||||
|
||||
/**
|
||||
* Get a player's integer hack level
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return player's hack level
|
||||
*/
|
||||
public static int getLevel(Player player) {
|
||||
return umr.safeGetLevel(player.getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a player's hack level (Min = 0, Max = 50)
|
||||
*
|
||||
* @param player Player to set
|
||||
* @param level Level to set to
|
||||
*/
|
||||
public static void setLevel(Player player, int level) {
|
||||
umr.safeSetLevel(player.getName(), level);
|
||||
}
|
||||
|
||||
// XrayTracker API
|
||||
|
||||
/**
|
||||
* Find out if a player is detected as using xray hacks (on any ore)
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player has any xray anomalies.
|
||||
*/
|
||||
public static boolean isXrayer(Player player) {
|
||||
String name = player.getName();
|
||||
return xtracker.sufficientData(name) && xtracker.hasAbnormal(name);
|
||||
}
|
||||
|
||||
// Advanced Users Only API.
|
||||
|
||||
/**
|
||||
* Get access to all the other managers, advanced users ONLY
|
||||
*
|
||||
* @return the AntiCheat Manager
|
||||
*/
|
||||
public static AnticheatManager getManager() {
|
||||
return AntiCheat.getManager();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.api;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.AnticheatManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.UserManager;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Developer's interface for all things AntiCheat.
|
||||
*/
|
||||
|
||||
public class AnticheatAPI {
|
||||
private static CheckManager chk = AntiCheat.getManager().getCheckManager();
|
||||
private static UserManager umr = AntiCheat.getManager().getUserManager();
|
||||
private static XRayTracker xtracker = AntiCheat.getManager().getXRayTracker();
|
||||
|
||||
// CheckManager API
|
||||
|
||||
/**
|
||||
* Start running a certain check
|
||||
*
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
public static void activateCheck(CheckType type) {
|
||||
chk.activateCheck(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop running a certain check
|
||||
*
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void deactivateCheck(CheckType type) {
|
||||
chk.deactivateCheck(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if a check is currently being watched for
|
||||
*
|
||||
* @param type Type to check
|
||||
* @return true if plugin is watching for this check
|
||||
*/
|
||||
public static boolean isActive(CheckType type) {
|
||||
return chk.isActive(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow a player to skip a certain check
|
||||
*
|
||||
* @param player Player to stop watching
|
||||
* @param type Check to stop watching for
|
||||
*/
|
||||
public static void exemptPlayer(Player player, CheckType type) {
|
||||
chk.exemptPlayer(player, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop allowing a player to skip a certain check
|
||||
*
|
||||
* @param player Player to start watching
|
||||
* @param type Check to start watching for
|
||||
*/
|
||||
public static void unexemptPlayer(Player player, CheckType type) {
|
||||
chk.unexemptPlayer(player, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if a player is currently exempt from a certain check
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param type Type to check
|
||||
* @return true if plugin is ignoring this check on this player
|
||||
*/
|
||||
public static boolean isExempt(Player player, CheckType type) {
|
||||
return chk.isExempt(player, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if a check will occur for a player. This checks if they are being tracked, the check is active, the player isn't exempt from the check, and the player doesn't have override permission.
|
||||
*
|
||||
* @param player Player to check
|
||||
* @param type Type to check
|
||||
* @return true if plugin will check this player, and that all things allow it to happen.
|
||||
*/
|
||||
public boolean willCheck(Player player, CheckType type) {
|
||||
return chk.willCheck(player, type);
|
||||
}
|
||||
|
||||
// PlayerManager API
|
||||
|
||||
/**
|
||||
* Get a player's integer hack level
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return player's hack level
|
||||
*/
|
||||
public static int getLevel(Player player) {
|
||||
return umr.safeGetLevel(player.getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a player's hack level (Min = 0, Max = 50)
|
||||
*
|
||||
* @param player Player to set
|
||||
* @param level Level to set to
|
||||
*/
|
||||
public static void setLevel(Player player, int level) {
|
||||
umr.safeSetLevel(player.getName(), level);
|
||||
}
|
||||
|
||||
// XrayTracker API
|
||||
|
||||
/**
|
||||
* Find out if a player is detected as using xray hacks (on any ore)
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player has any xray anomalies.
|
||||
*/
|
||||
public static boolean isXrayer(Player player) {
|
||||
String name = player.getName();
|
||||
return xtracker.sufficientData(name) && xtracker.hasAbnormal(name);
|
||||
}
|
||||
|
||||
// Advanced Users Only API.
|
||||
|
||||
/**
|
||||
* Get access to all the other managers, advanced users ONLY
|
||||
*
|
||||
* @return the AntiCheat Manager
|
||||
*/
|
||||
public static AnticheatManager getManager() {
|
||||
return AntiCheat.getManager();
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -16,10 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.api;
|
||||
package net.gravitydevelopment.anticheat.api;
|
||||
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@@ -40,18 +40,18 @@ public class CheckFailEvent extends Event {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link net.h31ix.anticheat.manage.User} who failed the check
|
||||
* Get the {@link net.gravitydevelopment.anticheat.manage.User} who failed the check
|
||||
*
|
||||
* @return a {@link net.h31ix.anticheat.manage.User}
|
||||
* @return a {@link net.gravitydevelopment.anticheat.manage.User}
|
||||
*/
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link net.h31ix.anticheat.manage.CheckType} failed
|
||||
* Get the {@link net.gravitydevelopment.anticheat.manage.CheckType} failed
|
||||
*
|
||||
* @return a {@link net.h31ix.anticheat.manage.CheckType}
|
||||
* @return a {@link net.gravitydevelopment.anticheat.manage.CheckType}
|
||||
*/
|
||||
public CheckType getCheck() {
|
||||
return type;
|
||||
+15
-15
@@ -16,22 +16,22 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config;
|
||||
package net.gravitydevelopment.anticheat.config;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.files.Config;
|
||||
import net.h31ix.anticheat.config.files.Enterprise;
|
||||
import net.h31ix.anticheat.config.files.Lang;
|
||||
import net.h31ix.anticheat.config.files.Magic;
|
||||
import net.h31ix.anticheat.config.holders.mysql.MySQLEventsHolder;
|
||||
import net.h31ix.anticheat.config.holders.mysql.MySQLLevelsHolder;
|
||||
import net.h31ix.anticheat.config.holders.mysql.MySQLRulesHolder;
|
||||
import net.h31ix.anticheat.config.holders.yaml.YamlEventsHolder;
|
||||
import net.h31ix.anticheat.config.holders.yaml.YamlLevelsHolder;
|
||||
import net.h31ix.anticheat.config.holders.yaml.YamlRulesHolder;
|
||||
import net.h31ix.anticheat.config.providers.Events;
|
||||
import net.h31ix.anticheat.config.providers.Levels;
|
||||
import net.h31ix.anticheat.config.providers.Rules;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.files.Config;
|
||||
import net.gravitydevelopment.anticheat.config.files.Enterprise;
|
||||
import net.gravitydevelopment.anticheat.config.files.Lang;
|
||||
import net.gravitydevelopment.anticheat.config.files.Magic;
|
||||
import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLEventsHolder;
|
||||
import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLLevelsHolder;
|
||||
import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLRulesHolder;
|
||||
import net.gravitydevelopment.anticheat.config.holders.yaml.YamlEventsHolder;
|
||||
import net.gravitydevelopment.anticheat.config.holders.yaml.YamlLevelsHolder;
|
||||
import net.gravitydevelopment.anticheat.config.holders.yaml.YamlRulesHolder;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Events;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
+3
-3
@@ -16,10 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config;
|
||||
package net.gravitydevelopment.anticheat.config;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.yaml.CommentedConfiguration;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.yaml.CommentedConfiguration;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
+2
-2
@@ -16,9 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config;
|
||||
package net.gravitydevelopment.anticheat.config;
|
||||
|
||||
import net.h31ix.anticheat.util.enterprise.Database;
|
||||
import net.gravitydevelopment.anticheat.util.enterprise.Database;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
+4
-4
@@ -16,11 +16,11 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.files;
|
||||
package net.gravitydevelopment.anticheat.config.files;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+5
-5
@@ -16,12 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.files;
|
||||
package net.gravitydevelopment.anticheat.config.files;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
import net.h31ix.anticheat.util.enterprise.Database;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.util.enterprise.Database;
|
||||
|
||||
public class Enterprise extends ConfigurationFile {
|
||||
|
||||
+4
-4
@@ -16,11 +16,11 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.files;
|
||||
package net.gravitydevelopment.anticheat.config.files;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+4
-4
@@ -16,11 +16,11 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.files;
|
||||
package net.gravitydevelopment.anticheat.config.files;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
|
||||
/**
|
||||
* Magic number class. Modifications to values in magic.yml will be accepted here.
|
||||
+5
-5
@@ -16,12 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.holders.mysql;
|
||||
package net.gravitydevelopment.anticheat.config.holders.mysql;
|
||||
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationTable;
|
||||
import net.h31ix.anticheat.config.providers.Events;
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Events;
|
||||
import net.gravitydevelopment.anticheat.util.Level;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
+6
-6
@@ -16,13 +16,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.holders.mysql;
|
||||
package net.gravitydevelopment.anticheat.config.holders.mysql;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationTable;
|
||||
import net.h31ix.anticheat.config.providers.Levels;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
+6
-6
@@ -16,13 +16,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.holders.mysql;
|
||||
package net.gravitydevelopment.anticheat.config.holders.mysql;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationTable;
|
||||
import net.h31ix.anticheat.config.providers.Rules;
|
||||
import net.h31ix.anticheat.util.rule.Rule;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Rules;
|
||||
import net.gravitydevelopment.anticheat.util.rule.Rule;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
+6
-6
@@ -16,13 +16,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.holders.yaml;
|
||||
package net.gravitydevelopment.anticheat.config.holders.yaml;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
import net.h31ix.anticheat.config.providers.Events;
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Events;
|
||||
import net.gravitydevelopment.anticheat.util.Level;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
+6
-6
@@ -16,13 +16,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.holders.yaml;
|
||||
package net.gravitydevelopment.anticheat.config.holders.yaml;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
import net.h31ix.anticheat.config.providers.Levels;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+6
-6
@@ -16,13 +16,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.holders.yaml;
|
||||
package net.gravitydevelopment.anticheat.config.holders.yaml;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
import net.h31ix.anticheat.config.providers.Rules;
|
||||
import net.h31ix.anticheat.util.rule.Rule;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Rules;
|
||||
import net.gravitydevelopment.anticheat.util.rule.Rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
+2
-2
@@ -16,9 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.providers;
|
||||
package net.gravitydevelopment.anticheat.config.providers;
|
||||
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
import net.gravitydevelopment.anticheat.util.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+2
-2
@@ -16,9 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.providers;
|
||||
package net.gravitydevelopment.anticheat.config.providers;
|
||||
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+2
-2
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
|
||||
|
||||
package net.h31ix.anticheat.config.providers;
|
||||
package net.gravitydevelopment.anticheat.config.providers;
|
||||
|
||||
import net.h31ix.anticheat.util.rule.Rule;
|
||||
import net.gravitydevelopment.anticheat.util.rule.Rule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.config.yaml;
|
||||
package net.gravitydevelopment.anticheat.config.yaml;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
+108
-108
@@ -1,108 +1,108 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.util.CheckResult;
|
||||
import net.h31ix.anticheat.util.Distance;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class BlockListener extends EventListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getInstaBreak() || Utilities.isInstantBreak(event.getBlock().getType())) {
|
||||
getBackend().logInstantBreak(player);
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.AUTOTOOL)) {
|
||||
CheckResult result = getBackend().checkAutoTool(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.AUTOTOOL);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player != null && getCheckManager().willCheck(player, CheckType.FAST_PLACE)) {
|
||||
CheckResult result = getBackend().checkFastPlace(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_PLACE);
|
||||
} else {
|
||||
decrease(player);
|
||||
getBackend().logBlockPlace(player);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Block block = event.getBlock();
|
||||
boolean noHack = true;
|
||||
if (player != null) {
|
||||
CheckResult result;
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_BREAK)) {
|
||||
result = getBackend().checkFastBreak(player, block);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_BREAK);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.NO_SWING)) {
|
||||
result = getBackend().checkSwing(player, block);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.NO_SWING);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.LONG_REACH)) {
|
||||
Distance distance = new Distance(player.getLocation(), block.getLocation());
|
||||
result = getBackend().checkLongReachBlock(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.LONG_REACH);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (noHack) {
|
||||
decrease(player);
|
||||
}
|
||||
getBackend().logBlockBreak(player);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.util.Distance;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
public class BlockListener extends EventListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.getInstaBreak() || Utilities.isInstantBreak(event.getBlock().getType())) {
|
||||
getBackend().logInstantBreak(player);
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.AUTOTOOL)) {
|
||||
CheckResult result = getBackend().checkAutoTool(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.AUTOTOOL);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player != null && getCheckManager().willCheck(player, CheckType.FAST_PLACE)) {
|
||||
CheckResult result = getBackend().checkFastPlace(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_PLACE);
|
||||
} else {
|
||||
decrease(player);
|
||||
getBackend().logBlockPlace(player);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Block block = event.getBlock();
|
||||
boolean noHack = true;
|
||||
if (player != null) {
|
||||
CheckResult result;
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_BREAK)) {
|
||||
result = getBackend().checkFastBreak(player, block);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_BREAK);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.NO_SWING)) {
|
||||
result = getBackend().checkSwing(player, block);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.NO_SWING);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.LONG_REACH)) {
|
||||
Distance distance = new Distance(player.getLocation(), block.getLocation());
|
||||
result = getBackend().checkLongReachBlock(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.LONG_REACH);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (noHack) {
|
||||
decrease(player);
|
||||
}
|
||||
getBackend().logBlockBreak(player);
|
||||
}
|
||||
}
|
||||
+175
-175
@@ -1,175 +1,175 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.util.CheckResult;
|
||||
import net.h31ix.anticheat.util.Distance;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
|
||||
public class EntityListener extends EventListener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_BOW)) {
|
||||
CheckResult result = getBackend().checkFastBow(player, event.getForce());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_BOW);
|
||||
} else {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_HEAL)) {
|
||||
CheckResult result = getBackend().checkFastHeal(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_HEAL);
|
||||
} else {
|
||||
decrease(player);
|
||||
getBackend().logHeal(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (player.getFoodLevel() < event.getFoodLevel() && getCheckManager().willCheck(player, CheckType.FAST_EAT)) // Make sure it's them actually gaining a food level
|
||||
{
|
||||
CheckResult result = getBackend().checkFastEat(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_EAT);
|
||||
} else {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
boolean noHack = true;
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
// Keep players from shooting an arrow at themselves in order to fly
|
||||
if (e.getDamager() instanceof Arrow) {
|
||||
Arrow arrow = (Arrow) e.getDamager();
|
||||
if (arrow.getShooter() instanceof Player && event.getEntity() == arrow.getShooter()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (Utilities.hasArmorEnchantment(player, Enchantment.THORNS)) {
|
||||
getBackend().logAnimation(player);
|
||||
}
|
||||
if (e.getDamager() instanceof Player) {
|
||||
Player p = (Player) e.getDamager();
|
||||
getBackend().logDamage(p, 1);
|
||||
int value = p.getInventory().getItemInHand().containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1;
|
||||
getBackend().logDamage(player, value);
|
||||
if (getCheckManager().willCheck(p, CheckType.LONG_REACH)) {
|
||||
Distance distance = new Distance(player.getLocation(), p.getLocation());
|
||||
CheckResult result = getBackend().checkLongReachDamage(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), p, CheckType.LONG_REACH);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (e.getDamager() instanceof TNTPrimed || e.getDamager() instanceof Creeper) {
|
||||
getBackend().logDamage(player, 3);
|
||||
} else {
|
||||
getBackend().logDamage(player, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getDamager() instanceof Player) {
|
||||
Player player = (Player) e.getDamager();
|
||||
getBackend().logDamage(player, 1);
|
||||
if (getCheckManager().willCheck(player, CheckType.AUTOTOOL)) {
|
||||
CheckResult result = getBackend().checkAutoTool(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.AUTOTOOL);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.FORCEFIELD)) {
|
||||
CheckResult result = getBackend().checkSprintDamage(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FORCEFIELD);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.NO_SWING)) {
|
||||
CheckResult result = getBackend().checkAnimation(player, event.getEntity());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.NO_SWING);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.FORCEFIELD)) {
|
||||
CheckResult result = getBackend().checkSight(player, e.getEntity());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FORCEFIELD);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (noHack) {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.util.Distance;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
|
||||
public class EntityListener extends EventListener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_BOW)) {
|
||||
CheckResult result = getBackend().checkFastBow(player, event.getForce());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_BOW);
|
||||
} else {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_HEAL)) {
|
||||
CheckResult result = getBackend().checkFastHeal(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_HEAL);
|
||||
} else {
|
||||
decrease(player);
|
||||
getBackend().logHeal(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (player.getFoodLevel() < event.getFoodLevel() && getCheckManager().willCheck(player, CheckType.FAST_EAT)) // Make sure it's them actually gaining a food level
|
||||
{
|
||||
CheckResult result = getBackend().checkFastEat(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_EAT);
|
||||
} else {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
boolean noHack = true;
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
|
||||
if (event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
// Keep players from shooting an arrow at themselves in order to fly
|
||||
if (e.getDamager() instanceof Arrow) {
|
||||
Arrow arrow = (Arrow) e.getDamager();
|
||||
if (arrow.getShooter() instanceof Player && event.getEntity() == arrow.getShooter()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (Utilities.hasArmorEnchantment(player, Enchantment.THORNS)) {
|
||||
getBackend().logAnimation(player);
|
||||
}
|
||||
if (e.getDamager() instanceof Player) {
|
||||
Player p = (Player) e.getDamager();
|
||||
getBackend().logDamage(p, 1);
|
||||
int value = p.getInventory().getItemInHand().containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1;
|
||||
getBackend().logDamage(player, value);
|
||||
if (getCheckManager().willCheck(p, CheckType.LONG_REACH)) {
|
||||
Distance distance = new Distance(player.getLocation(), p.getLocation());
|
||||
CheckResult result = getBackend().checkLongReachDamage(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), p, CheckType.LONG_REACH);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (e.getDamager() instanceof TNTPrimed || e.getDamager() instanceof Creeper) {
|
||||
getBackend().logDamage(player, 3);
|
||||
} else {
|
||||
getBackend().logDamage(player, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.getDamager() instanceof Player) {
|
||||
Player player = (Player) e.getDamager();
|
||||
getBackend().logDamage(player, 1);
|
||||
if (getCheckManager().willCheck(player, CheckType.AUTOTOOL)) {
|
||||
CheckResult result = getBackend().checkAutoTool(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.AUTOTOOL);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.FORCEFIELD)) {
|
||||
CheckResult result = getBackend().checkSprintDamage(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FORCEFIELD);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.NO_SWING)) {
|
||||
CheckResult result = getBackend().checkAnimation(player, event.getEntity());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.NO_SWING);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.FORCEFIELD)) {
|
||||
CheckResult result = getBackend().checkSight(player, e.getEntity());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FORCEFIELD);
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (noHack) {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
}
|
||||
+139
-139
@@ -1,139 +1,139 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.manage.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EventListener implements Listener {
|
||||
private static final Map<CheckType, Integer> USAGE_LIST = new EnumMap<CheckType, Integer>(CheckType.class);
|
||||
private static final Map<String, Integer> DECREASE_LIST = new HashMap<String, Integer>();
|
||||
private static final CheckManager CHECK_MANAGER = AntiCheat.getManager().getCheckManager();
|
||||
private static final Backend BACKEND = AntiCheat.getManager().getBackend();
|
||||
private static final AntiCheat PLUGIN = AntiCheat.getManager().getPlugin();
|
||||
private static final UserManager USER_MANAGER = AntiCheat.getManager().getUserManager();
|
||||
private static final Configuration CONFIG = AntiCheat.getManager().getConfiguration();
|
||||
|
||||
public static void log(String message, Player player, CheckType type) {
|
||||
User user = getUserManager().getUser(player.getName());
|
||||
if (user != null) { // npc
|
||||
logCheat(type, user);
|
||||
if (user.increaseLevel(type) && message != null) {
|
||||
AntiCheat.getManager().log(message);
|
||||
}
|
||||
removeDecrease(user);
|
||||
}
|
||||
}
|
||||
|
||||
private static void logCheat(CheckType type, User user) {
|
||||
USAGE_LIST.put(type, getCheats(type) + 1);
|
||||
// Ignore plugins that are creating NPCs with no names (why the hell)
|
||||
if (user != null && user.getName() != null) {
|
||||
type.logUse(user);
|
||||
if (CONFIG.getConfig().enterprise.getValue() && CONFIG.getEnterprise().loggingEnabled.getValue()) {
|
||||
CONFIG.getEnterprise().database.logEvent(user, type);
|
||||
}
|
||||
if (CONFIG.getConfig().fileLogLevel.getValue() == 2 && type.getUses(user.getName()) % 10 == 0) {
|
||||
AntiCheat.getManager().fileLog(user.getName() + " has triggered multiple " + type + " checks.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCheck(CheckType type) {
|
||||
USAGE_LIST.put(type, 0);
|
||||
}
|
||||
|
||||
public static int getCheats(CheckType type) {
|
||||
int x = 0;
|
||||
if (USAGE_LIST.get(type) != null) {
|
||||
x = USAGE_LIST.get(type);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
private static void removeDecrease(User user) {
|
||||
int x = 0;
|
||||
// Ignore plugins that are creating NPCs with no names
|
||||
if (user.getName() != null) {
|
||||
if (DECREASE_LIST.get(user.getName()) != null) {
|
||||
x = DECREASE_LIST.get(user.getName());
|
||||
x -= 2;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
DECREASE_LIST.put(user.getName(), x);
|
||||
}
|
||||
}
|
||||
|
||||
public static void decrease(Player player) {
|
||||
User user = getUserManager().getUser(player.getName());
|
||||
// Ignore plugins that are creating NPCs with no names
|
||||
if (user.getName() != null) {
|
||||
int x = 0;
|
||||
|
||||
if (DECREASE_LIST.get(user.getName()) != null) {
|
||||
x = DECREASE_LIST.get(user.getName());
|
||||
}
|
||||
|
||||
x += 1;
|
||||
DECREASE_LIST.put(user.getName(), x);
|
||||
|
||||
if (x >= 10) {
|
||||
user.decreaseLevel();
|
||||
DECREASE_LIST.put(user.getName(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CheckManager getCheckManager() {
|
||||
return CHECK_MANAGER;
|
||||
}
|
||||
|
||||
public static AnticheatManager getManager() {
|
||||
return AntiCheat.getManager();
|
||||
}
|
||||
|
||||
public static Backend getBackend() {
|
||||
return BACKEND;
|
||||
}
|
||||
|
||||
public static UserManager getUserManager() {
|
||||
return USER_MANAGER;
|
||||
}
|
||||
|
||||
public static AntiCheat getPlugin() {
|
||||
return PLUGIN;
|
||||
}
|
||||
|
||||
public static Configuration getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
public static boolean silentMode() {
|
||||
return CONFIG.getConfig().silentMode.getValue();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.manage.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EventListener implements Listener {
|
||||
private static final Map<CheckType, Integer> USAGE_LIST = new EnumMap<CheckType, Integer>(CheckType.class);
|
||||
private static final Map<String, Integer> DECREASE_LIST = new HashMap<String, Integer>();
|
||||
private static final CheckManager CHECK_MANAGER = AntiCheat.getManager().getCheckManager();
|
||||
private static final Backend BACKEND = AntiCheat.getManager().getBackend();
|
||||
private static final AntiCheat PLUGIN = AntiCheat.getManager().getPlugin();
|
||||
private static final UserManager USER_MANAGER = AntiCheat.getManager().getUserManager();
|
||||
private static final Configuration CONFIG = AntiCheat.getManager().getConfiguration();
|
||||
|
||||
public static void log(String message, Player player, CheckType type) {
|
||||
User user = getUserManager().getUser(player.getName());
|
||||
if (user != null) { // npc
|
||||
logCheat(type, user);
|
||||
if (user.increaseLevel(type) && message != null) {
|
||||
AntiCheat.getManager().log(message);
|
||||
}
|
||||
removeDecrease(user);
|
||||
}
|
||||
}
|
||||
|
||||
private static void logCheat(CheckType type, User user) {
|
||||
USAGE_LIST.put(type, getCheats(type) + 1);
|
||||
// Ignore plugins that are creating NPCs with no names (why the hell)
|
||||
if (user != null && user.getName() != null) {
|
||||
type.logUse(user);
|
||||
if (CONFIG.getConfig().enterprise.getValue() && CONFIG.getEnterprise().loggingEnabled.getValue()) {
|
||||
CONFIG.getEnterprise().database.logEvent(user, type);
|
||||
}
|
||||
if (CONFIG.getConfig().fileLogLevel.getValue() == 2 && type.getUses(user.getName()) % 10 == 0) {
|
||||
AntiCheat.getManager().fileLog(user.getName() + " has triggered multiple " + type + " checks.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resetCheck(CheckType type) {
|
||||
USAGE_LIST.put(type, 0);
|
||||
}
|
||||
|
||||
public static int getCheats(CheckType type) {
|
||||
int x = 0;
|
||||
if (USAGE_LIST.get(type) != null) {
|
||||
x = USAGE_LIST.get(type);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
private static void removeDecrease(User user) {
|
||||
int x = 0;
|
||||
// Ignore plugins that are creating NPCs with no names
|
||||
if (user.getName() != null) {
|
||||
if (DECREASE_LIST.get(user.getName()) != null) {
|
||||
x = DECREASE_LIST.get(user.getName());
|
||||
x -= 2;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
DECREASE_LIST.put(user.getName(), x);
|
||||
}
|
||||
}
|
||||
|
||||
public static void decrease(Player player) {
|
||||
User user = getUserManager().getUser(player.getName());
|
||||
// Ignore plugins that are creating NPCs with no names
|
||||
if (user.getName() != null) {
|
||||
int x = 0;
|
||||
|
||||
if (DECREASE_LIST.get(user.getName()) != null) {
|
||||
x = DECREASE_LIST.get(user.getName());
|
||||
}
|
||||
|
||||
x += 1;
|
||||
DECREASE_LIST.put(user.getName(), x);
|
||||
|
||||
if (x >= 10) {
|
||||
user.decreaseLevel();
|
||||
DECREASE_LIST.put(user.getName(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CheckManager getCheckManager() {
|
||||
return CHECK_MANAGER;
|
||||
}
|
||||
|
||||
public static AnticheatManager getManager() {
|
||||
return AntiCheat.getManager();
|
||||
}
|
||||
|
||||
public static Backend getBackend() {
|
||||
return BACKEND;
|
||||
}
|
||||
|
||||
public static UserManager getUserManager() {
|
||||
return USER_MANAGER;
|
||||
}
|
||||
|
||||
public static AntiCheat getPlugin() {
|
||||
return PLUGIN;
|
||||
}
|
||||
|
||||
public static Configuration getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
public static boolean silentMode() {
|
||||
return CONFIG.getConfig().silentMode.getValue();
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -16,12 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
+459
-459
@@ -1,459 +1,459 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.util.CheckResult;
|
||||
import net.h31ix.anticheat.util.Distance;
|
||||
import net.h31ix.anticheat.util.Permission;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public class PlayerListener extends EventListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.SPAM) && getConfig().getConfig().blockCommandSpam.getValue()) {
|
||||
CheckResult result = getBackend().checkSpam(player, event.getMessage());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
player.sendMessage(ChatColor.RED + result.getMessage());
|
||||
getBackend().processChatSpammer(player);
|
||||
log(null, player, CheckType.SPAM);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||
if (!event.isFlying()) {
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
if (event.getNewGameMode() != GameMode.CREATIVE) {
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||
if (event.getEntity().getShooter() instanceof Player) {
|
||||
Player player = (Player) event.getEntity().getShooter();
|
||||
|
||||
if (event.getEntity() instanceof Arrow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_PROJECTILE)) {
|
||||
CheckResult result = getBackend().checkProjectile(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_PROJECTILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (event.getCause() == TeleportCause.ENDER_PEARL || event.getCause() == TeleportCause.PLUGIN) {
|
||||
getBackend().logTeleport(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangeWorlds(PlayerChangedWorldEvent event) {
|
||||
getBackend().logTeleport(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (event.isSneaking()) {
|
||||
getBackend().logToggleSneak(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.FLY)) {
|
||||
if (getBackend().justVelocity(player) && getBackend().extendVelocityTime(player)) {
|
||||
event.setCancelled(!silentMode());
|
||||
return; // don't log it lol.
|
||||
}
|
||||
getBackend().logVelocity(player);
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (getCheckManager().willCheck(player, CheckType.SPAM) && getConfig().getConfig().blockChatSpam.getValue()) {
|
||||
CheckResult result = getBackend().checkSpam(player, event.getMessage());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
if (!result.getMessage().equals("")) {
|
||||
player.sendMessage(ChatColor.RED + result.getMessage());
|
||||
}
|
||||
getBackend().processChatSpammer(player);
|
||||
log(null, player, CheckType.SPAM);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
getBackend().clearChatLevel(event.getPlayer());
|
||||
getBackend().garbageClean(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
getBackend().garbageClean(event.getPlayer());
|
||||
|
||||
User user = getUserManager().getUser(event.getPlayer().getName());
|
||||
|
||||
getConfig().getLevels().saveLevelFromUser(user);
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSprint(PlayerToggleSprintEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!event.isSprinting()) {
|
||||
getBackend().logEnterExit(player);
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.SPRINT)) {
|
||||
CheckResult result = getBackend().checkSprintHungry(event);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.SPRINT);
|
||||
} else {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlayerInventory inv = player.getInventory();
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Material m = inv.getItemInHand().getType();
|
||||
if (m == Material.BOW) {
|
||||
getBackend().logBowWindUp(player);
|
||||
} else if (Utilities.isFood(m)) {
|
||||
getBackend().logEatingStart(player);
|
||||
}
|
||||
}
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (block != null) {
|
||||
Distance distance = new Distance(player.getLocation(), block.getLocation());
|
||||
getBackend().checkLongReachBlock(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.ITEM_SPAM)) {
|
||||
CheckResult result = getBackend().checkFastDrop(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.ITEM_SPAM);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerEnterBed(PlayerBedEnterEvent event) {
|
||||
if (event.getBed().getType() != Material.BED) return;
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerExitBed(PlayerBedLeaveEvent event) {
|
||||
if (event.getBed().getType() != Material.BED) return;
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_ANIMATION)) {
|
||||
CheckResult result = getBackend().checkFastAnimation(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_ANIMATION);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String section = "\u00a7";
|
||||
if (getCheckManager().willCheck(player, CheckType.ZOMBE_FLY)) {
|
||||
player.sendMessage(section + "f " + section + "f " + section + "1 " + section + "0 " + section + "2 " + section + "4");
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.ZOMBE_CHEAT)) {
|
||||
player.sendMessage(section + "f " + section + "f " + section + "2 " + section + "0 " + section + "4 " + section + "8");
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.ZOMBE_NOCLIP)) {
|
||||
player.sendMessage(section + "f " + section + "f " + section + "4 " + section + "0 " + section + "9 " + section + "6");
|
||||
}
|
||||
|
||||
getBackend().logJoin(player);
|
||||
|
||||
User user = new User(player.getName());
|
||||
user.setIsWaitingOnLevelSync(true);
|
||||
getConfig().getLevels().loadLevelToUser(user);
|
||||
getUserManager().addUser(user);
|
||||
|
||||
if (player.hasMetadata(Utilities.SPY_METADATA)) {
|
||||
for (Player p : player.getServer().getOnlinePlayers()) {
|
||||
if (!Permission.SYSTEM_SPY.get(p)) {
|
||||
p.hidePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (getCheckManager().checkInWorld(player) && !getCheckManager().isOpExempt(player)) {
|
||||
final Location from = event.getFrom();
|
||||
final Location to = event.getTo();
|
||||
|
||||
final Distance distance = new Distance(from, to);
|
||||
final double y = distance.getYDifference();
|
||||
getBackend().logAscension(player, from.getY(), to.getY());
|
||||
|
||||
final User user = getUserManager().getUser(player.getName());
|
||||
user.setTo(to.getX(), to.getY(), to.getZ());
|
||||
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPEED)) {
|
||||
CheckResult result = getBackend().checkFreeze(player, from.getY(), to.getY());
|
||||
if (result.failed()) {
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
if (!silentMode()) {
|
||||
player.kickPlayer("Freezing client");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPRINT)) {
|
||||
CheckResult result = getBackend().checkSprintStill(player, from, to);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.SPRINT);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !player.isFlying()) {
|
||||
CheckResult result = getBackend().checkFlight(player, distance);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.FLY);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.VCLIP) && event.getFrom().getY() > event.getTo().getY()) {
|
||||
CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo()));
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
int data = result.getData() > 3 ? 3 : result.getData();
|
||||
Location newloc = new Location(player.getWorld(), event.getFrom().getX(), event.getFrom().getY() + data, event.getFrom().getZ());
|
||||
if (newloc.getBlock().getTypeId() == 0) {
|
||||
event.setTo(newloc);
|
||||
} else {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
player.damage(3);
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.VCLIP);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.NOFALL) && getCheckManager().willCheck(player, CheckType.FLY) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && event.getFrom().getY() > event.getTo().getY()) {
|
||||
CheckResult result = getBackend().checkNoFall(player, y);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
player.damage(1); // I added this in here so the player would still receive damage.
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.NOFALL);
|
||||
}
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
if (event.getTo() != event.getFrom()) {
|
||||
double x = distance.getXDifference();
|
||||
double z = distance.getZDifference();
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPEED) && getCheckManager().willCheck(player, CheckType.FLY)) {
|
||||
if (event.getFrom().getY() < event.getTo().getY()) {
|
||||
CheckResult result = getBackend().checkYSpeed(player, y);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
CheckResult result = getBackend().checkXZSpeed(player, x, z);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
/*if ((event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ())) {
|
||||
result = backend.checkTimer(player);
|
||||
if(result.failed()) {
|
||||
if (!config.silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log("tried to alter their timer.", player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.WATER_WALK)) {
|
||||
CheckResult result = getBackend().checkWaterWalk(player, x, y, z);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
player.teleport(user.getGoodLocation(player.getLocation().add(0, -1, 0)));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.WATER_WALK);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SNEAK)) {
|
||||
CheckResult result = getBackend().checkSneak(player, x, z);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
player.setSneaking(false);
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SNEAK);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPIDER)) {
|
||||
CheckResult result = getBackend().checkSpider(player, y);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SPIDER);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (!changed) {
|
||||
user.setGoodLocation(event.getFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void checkFly(PlayerMoveEvent event) {
|
||||
// Check flight on highest to make sure other plugins have a chance to change the values first.
|
||||
final Player player = event.getPlayer();
|
||||
final User user = getUserManager().getUser(player.getName());
|
||||
final Location from = event.getFrom();
|
||||
final Location to = event.getTo();
|
||||
|
||||
if (!user.checkTo(to.getX(), to.getY(), to.getZ())) {
|
||||
// The to value has been modified by another plugin
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCheckManager().willCheck(player, CheckType.FLY) && !player.isFlying()) {
|
||||
CheckResult result1 = getBackend().checkYAxis(player, new Distance(from, to));
|
||||
CheckResult result2 = getBackend().checkAscension(player, from.getY(), to.getY());
|
||||
String log = result1.failed() ? result1.getMessage() : result2.failed() ? result2.getMessage() : "";
|
||||
if (!log.equals("")) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(log, player, CheckType.FLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.CheckResult;
|
||||
import net.gravitydevelopment.anticheat.util.Distance;
|
||||
import net.gravitydevelopment.anticheat.util.Permission;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public class PlayerListener extends EventListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.SPAM) && getConfig().getConfig().blockCommandSpam.getValue()) {
|
||||
CheckResult result = getBackend().checkSpam(player, event.getMessage());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
player.sendMessage(ChatColor.RED + result.getMessage());
|
||||
getBackend().processChatSpammer(player);
|
||||
log(null, player, CheckType.SPAM);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||
if (!event.isFlying()) {
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
if (event.getNewGameMode() != GameMode.CREATIVE) {
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onProjectileLaunch(ProjectileLaunchEvent event) {
|
||||
if (event.getEntity().getShooter() instanceof Player) {
|
||||
Player player = (Player) event.getEntity().getShooter();
|
||||
|
||||
if (event.getEntity() instanceof Arrow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_PROJECTILE)) {
|
||||
CheckResult result = getBackend().checkProjectile(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_PROJECTILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (event.getCause() == TeleportCause.ENDER_PEARL || event.getCause() == TeleportCause.PLUGIN) {
|
||||
getBackend().logTeleport(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangeWorlds(PlayerChangedWorldEvent event) {
|
||||
getBackend().logTeleport(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (event.isSneaking()) {
|
||||
getBackend().logToggleSneak(event.getPlayer());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.FLY)) {
|
||||
if (getBackend().justVelocity(player) && getBackend().extendVelocityTime(player)) {
|
||||
event.setCancelled(!silentMode());
|
||||
return; // don't log it lol.
|
||||
}
|
||||
getBackend().logVelocity(player);
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (getCheckManager().willCheck(player, CheckType.SPAM) && getConfig().getConfig().blockChatSpam.getValue()) {
|
||||
CheckResult result = getBackend().checkSpam(player, event.getMessage());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
if (!result.getMessage().equals("")) {
|
||||
player.sendMessage(ChatColor.RED + result.getMessage());
|
||||
}
|
||||
getBackend().processChatSpammer(player);
|
||||
log(null, player, CheckType.SPAM);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
getBackend().clearChatLevel(event.getPlayer());
|
||||
getBackend().garbageClean(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
getBackend().garbageClean(event.getPlayer());
|
||||
|
||||
User user = getUserManager().getUser(event.getPlayer().getName());
|
||||
|
||||
getConfig().getLevels().saveLevelFromUser(user);
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleSprint(PlayerToggleSprintEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!event.isSprinting()) {
|
||||
getBackend().logEnterExit(player);
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.SPRINT)) {
|
||||
CheckResult result = getBackend().checkSprintHungry(event);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.SPRINT);
|
||||
} else {
|
||||
decrease(player);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlayerInventory inv = player.getInventory();
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Material m = inv.getItemInHand().getType();
|
||||
if (m == Material.BOW) {
|
||||
getBackend().logBowWindUp(player);
|
||||
} else if (Utilities.isFood(m)) {
|
||||
getBackend().logEatingStart(player);
|
||||
}
|
||||
}
|
||||
Block block = event.getClickedBlock();
|
||||
|
||||
if (block != null) {
|
||||
Distance distance = new Distance(player.getLocation(), block.getLocation());
|
||||
getBackend().checkLongReachBlock(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.ITEM_SPAM)) {
|
||||
CheckResult result = getBackend().checkFastDrop(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.ITEM_SPAM);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerEnterBed(PlayerBedEnterEvent event) {
|
||||
if (event.getBed().getType() != Material.BED) return;
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerExitBed(PlayerBedLeaveEvent event) {
|
||||
if (event.getBed().getType() != Material.BED) return;
|
||||
getBackend().logEnterExit(event.getPlayer());
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_ANIMATION)) {
|
||||
CheckResult result = getBackend().checkFastAnimation(player);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_ANIMATION);
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
String section = "\u00a7";
|
||||
if (getCheckManager().willCheck(player, CheckType.ZOMBE_FLY)) {
|
||||
player.sendMessage(section + "f " + section + "f " + section + "1 " + section + "0 " + section + "2 " + section + "4");
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.ZOMBE_CHEAT)) {
|
||||
player.sendMessage(section + "f " + section + "f " + section + "2 " + section + "0 " + section + "4 " + section + "8");
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.ZOMBE_NOCLIP)) {
|
||||
player.sendMessage(section + "f " + section + "f " + section + "4 " + section + "0 " + section + "9 " + section + "6");
|
||||
}
|
||||
|
||||
getBackend().logJoin(player);
|
||||
|
||||
User user = new User(player.getName());
|
||||
user.setIsWaitingOnLevelSync(true);
|
||||
getConfig().getLevels().loadLevelToUser(user);
|
||||
getUserManager().addUser(user);
|
||||
|
||||
if (player.hasMetadata(Utilities.SPY_METADATA)) {
|
||||
for (Player p : player.getServer().getOnlinePlayers()) {
|
||||
if (!Permission.SYSTEM_SPY.get(p)) {
|
||||
p.hidePlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (getCheckManager().checkInWorld(player) && !getCheckManager().isOpExempt(player)) {
|
||||
final Location from = event.getFrom();
|
||||
final Location to = event.getTo();
|
||||
|
||||
final Distance distance = new Distance(from, to);
|
||||
final double y = distance.getYDifference();
|
||||
getBackend().logAscension(player, from.getY(), to.getY());
|
||||
|
||||
final User user = getUserManager().getUser(player.getName());
|
||||
user.setTo(to.getX(), to.getY(), to.getZ());
|
||||
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPEED)) {
|
||||
CheckResult result = getBackend().checkFreeze(player, from.getY(), to.getY());
|
||||
if (result.failed()) {
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
if (!silentMode()) {
|
||||
player.kickPlayer("Freezing client");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPRINT)) {
|
||||
CheckResult result = getBackend().checkSprintStill(player, from, to);
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.SPRINT);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !player.isFlying()) {
|
||||
CheckResult result = getBackend().checkFlight(player, distance);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.FLY);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.VCLIP) && event.getFrom().getY() > event.getTo().getY()) {
|
||||
CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo()));
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
int data = result.getData() > 3 ? 3 : result.getData();
|
||||
Location newloc = new Location(player.getWorld(), event.getFrom().getX(), event.getFrom().getY() + data, event.getFrom().getZ());
|
||||
if (newloc.getBlock().getTypeId() == 0) {
|
||||
event.setTo(newloc);
|
||||
} else {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
player.damage(3);
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.VCLIP);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.NOFALL) && getCheckManager().willCheck(player, CheckType.FLY) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && event.getFrom().getY() > event.getTo().getY()) {
|
||||
CheckResult result = getBackend().checkNoFall(player, y);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
player.damage(1); // I added this in here so the player would still receive damage.
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.NOFALL);
|
||||
}
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
if (event.getTo() != event.getFrom()) {
|
||||
double x = distance.getXDifference();
|
||||
double z = distance.getZDifference();
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPEED) && getCheckManager().willCheck(player, CheckType.FLY)) {
|
||||
if (event.getFrom().getY() < event.getTo().getY()) {
|
||||
CheckResult result = getBackend().checkYSpeed(player, y);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
CheckResult result = getBackend().checkXZSpeed(player, x, z);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
/*if ((event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ())) {
|
||||
result = backend.checkTimer(player);
|
||||
if(result.failed()) {
|
||||
if (!config.silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log("tried to alter their timer.", player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.WATER_WALK)) {
|
||||
CheckResult result = getBackend().checkWaterWalk(player, x, y, z);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
player.teleport(user.getGoodLocation(player.getLocation().add(0, -1, 0)));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.WATER_WALK);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SNEAK)) {
|
||||
CheckResult result = getBackend().checkSneak(player, x, z);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
player.setSneaking(false);
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SNEAK);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPIDER)) {
|
||||
CheckResult result = getBackend().checkSpider(player, y);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.SPIDER);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (!changed) {
|
||||
user.setGoodLocation(event.getFrom());
|
||||
}
|
||||
}
|
||||
}
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void checkFly(PlayerMoveEvent event) {
|
||||
// Check flight on highest to make sure other plugins have a chance to change the values first.
|
||||
final Player player = event.getPlayer();
|
||||
final User user = getUserManager().getUser(player.getName());
|
||||
final Location from = event.getFrom();
|
||||
final Location to = event.getTo();
|
||||
|
||||
if (!user.checkTo(to.getX(), to.getY(), to.getZ())) {
|
||||
// The to value has been modified by another plugin
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCheckManager().willCheck(player, CheckType.FLY) && !player.isFlying()) {
|
||||
CheckResult result1 = getBackend().checkYAxis(player, new Distance(from, to));
|
||||
CheckResult result2 = getBackend().checkAscension(player, from.getY(), to.getY());
|
||||
String log = result1.failed() ? result1.getMessage() : result2.failed() ? result2.getMessage() : "";
|
||||
if (!log.equals("")) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(log, player, CheckType.FLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+57
-57
@@ -1,57 +1,57 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
|
||||
public class VehicleListener extends EventListener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
if (event.getEntered() instanceof Player) {
|
||||
getBackend().logEnterExit((Player) event.getEntered());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onVehicleExit(VehicleExitEvent event) {
|
||||
if (event.getExited() instanceof Player) {
|
||||
getBackend().logEnterExit((Player) event.getExited());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
if (event.getVehicle().getPassenger() != null && event.getVehicle().getPassenger() instanceof Player) {
|
||||
getBackend().logEnterExit((Player) event.getVehicle().getPassenger());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
|
||||
public class VehicleListener extends EventListener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onVehicleEnter(VehicleEnterEvent event) {
|
||||
if (event.getEntered() instanceof Player) {
|
||||
getBackend().logEnterExit((Player) event.getEntered());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onVehicleExit(VehicleExitEvent event) {
|
||||
if (event.getExited() instanceof Player) {
|
||||
getBackend().logEnterExit((Player) event.getExited());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onVehicleDestroy(VehicleDestroyEvent event) {
|
||||
if (event.getVehicle().getPassenger() != null && event.getVehicle().getPassenger() instanceof Player) {
|
||||
getBackend().logEnterExit((Player) event.getVehicle().getPassenger());
|
||||
}
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
}
|
||||
+185
-185
@@ -1,185 +1,185 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.util.FileFormatter;
|
||||
import net.h31ix.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The internal hub for all managers.
|
||||
*/
|
||||
|
||||
public class AnticheatManager {
|
||||
private static AntiCheat plugin = null;
|
||||
private static Configuration configuration;
|
||||
private static XRayTracker xrayTracker = null;
|
||||
private static UserManager userManager = null;
|
||||
private static CheckManager checkManager = null;
|
||||
private static Backend backend = null;
|
||||
private final Logger fileLogger;
|
||||
private static Map<String, RegisteredListener[]> eventchains = new ConcurrentHashMap<String, RegisteredListener[]>();
|
||||
private static Map<String, Long> eventcache = new ConcurrentHashMap<String, Long>();
|
||||
private static List<String> logs = new CopyOnWriteArrayList<String>();
|
||||
private static Handler fileHandler;
|
||||
private static final int LOG_LEVEL_HIGH = 3;
|
||||
|
||||
public AnticheatManager(AntiCheat instance, Logger logger) {
|
||||
plugin = instance;
|
||||
// now load all the others!!!!!
|
||||
fileLogger = Logger.getLogger("net.h31ix.anticheat.AntiCheat");
|
||||
configuration = new Configuration(plugin);
|
||||
xrayTracker = new XRayTracker();
|
||||
userManager = new UserManager(configuration);
|
||||
checkManager = new CheckManager(this, configuration);
|
||||
backend = new Backend(this);
|
||||
try {
|
||||
File file = new File(plugin.getDataFolder(), "log");
|
||||
if (!file.exists()) {
|
||||
file.mkdir();
|
||||
}
|
||||
fileHandler = new FileHandler(plugin.getDataFolder() + "/log/anticheat.log", true);
|
||||
fileHandler.setFormatter(new FileFormatter());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
fileLogger.setUseParentHandlers(false);
|
||||
fileLogger.addHandler(fileHandler);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
log(message, 0);
|
||||
}
|
||||
|
||||
public void log(String message, int i) {
|
||||
if (i != 1 && getConfiguration().getConfig().logToConsole.getValue()) {
|
||||
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.RED + message);
|
||||
}
|
||||
if (i == 0 && getConfiguration().getConfig().fileLogLevel.getValue() == LOG_LEVEL_HIGH) // Not an alert, normal log message
|
||||
{
|
||||
fileLog(message);
|
||||
} else if (getConfiguration().getConfig().fileLogLevel.getValue() != 0) { // alert
|
||||
fileLog(message);
|
||||
}
|
||||
logs.add(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
public void fileLog(String message) {
|
||||
fileLogger.info(message);
|
||||
}
|
||||
|
||||
public List<String> getLastLogs() {
|
||||
List<String> log = new CopyOnWriteArrayList<String>();
|
||||
if (logs.size() < 30) {
|
||||
return logs;
|
||||
}
|
||||
for (int i = logs.size() - 1; i >= 0; i--) {
|
||||
log.add(logs.get(i));
|
||||
}
|
||||
logs.clear();
|
||||
return log;
|
||||
}
|
||||
|
||||
public void addEvent(String e, RegisteredListener[] arr) {
|
||||
if (!configuration.getConfig().eventChains.getValue())
|
||||
return;
|
||||
if (!eventcache.containsKey(e) || eventcache.get(e) > 30000L) {
|
||||
eventchains.put(e, arr);
|
||||
eventcache.put(e, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public String getEventChainReport() {
|
||||
String gen = "";
|
||||
if (!configuration.getConfig().eventChains.getValue()) {
|
||||
return "Event Chains is disabled by the configuration." + '\n';
|
||||
}
|
||||
|
||||
if (eventchains.entrySet().size() == 0) {
|
||||
return "No event chains found." + '\n';
|
||||
}
|
||||
|
||||
for (Entry<String, RegisteredListener[]> e : eventchains.entrySet()) {
|
||||
String toadd = "";
|
||||
String ename = e.getKey();
|
||||
|
||||
toadd += ename + ":" + '\n';
|
||||
|
||||
RegisteredListener[] reg = e.getValue();
|
||||
for (RegisteredListener plug : reg) {
|
||||
String pluginname = plug.getPlugin().getName();
|
||||
if (pluginname.equals("AntiCheat"))
|
||||
pluginname = "self";
|
||||
|
||||
toadd += "- " + pluginname + '\n';
|
||||
}
|
||||
|
||||
gen += toadd + '\n';
|
||||
}
|
||||
|
||||
return gen;
|
||||
}
|
||||
|
||||
public AntiCheat getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public XRayTracker getXRayTracker() {
|
||||
return xrayTracker;
|
||||
}
|
||||
|
||||
public UserManager getUserManager() {
|
||||
return userManager;
|
||||
}
|
||||
|
||||
public CheckManager getCheckManager() {
|
||||
return checkManager;
|
||||
}
|
||||
|
||||
public Backend getBackend() {
|
||||
return backend;
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
fileHandler.close();
|
||||
|
||||
if (configuration.getConfig().enterprise.getValue()) {
|
||||
configuration.getEnterprise().database.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.util.FileFormatter;
|
||||
import net.gravitydevelopment.anticheat.xray.XRayTracker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* The internal hub for all managers.
|
||||
*/
|
||||
|
||||
public class AnticheatManager {
|
||||
private static AntiCheat plugin = null;
|
||||
private static Configuration configuration;
|
||||
private static XRayTracker xrayTracker = null;
|
||||
private static UserManager userManager = null;
|
||||
private static CheckManager checkManager = null;
|
||||
private static Backend backend = null;
|
||||
private final Logger fileLogger;
|
||||
private static Map<String, RegisteredListener[]> eventchains = new ConcurrentHashMap<String, RegisteredListener[]>();
|
||||
private static Map<String, Long> eventcache = new ConcurrentHashMap<String, Long>();
|
||||
private static List<String> logs = new CopyOnWriteArrayList<String>();
|
||||
private static Handler fileHandler;
|
||||
private static final int LOG_LEVEL_HIGH = 3;
|
||||
|
||||
public AnticheatManager(AntiCheat instance, Logger logger) {
|
||||
plugin = instance;
|
||||
// now load all the others!!!!!
|
||||
fileLogger = Logger.getLogger("net.gravitydevelopment.anticheat.AntiCheat");
|
||||
configuration = new Configuration(plugin);
|
||||
xrayTracker = new XRayTracker();
|
||||
userManager = new UserManager(configuration);
|
||||
checkManager = new CheckManager(this, configuration);
|
||||
backend = new Backend(this);
|
||||
try {
|
||||
File file = new File(plugin.getDataFolder(), "log");
|
||||
if (!file.exists()) {
|
||||
file.mkdir();
|
||||
}
|
||||
fileHandler = new FileHandler(plugin.getDataFolder() + "/log/anticheat.log", true);
|
||||
fileHandler.setFormatter(new FileFormatter());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
fileLogger.setUseParentHandlers(false);
|
||||
fileLogger.addHandler(fileHandler);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
log(message, 0);
|
||||
}
|
||||
|
||||
public void log(String message, int i) {
|
||||
if (i != 1 && getConfiguration().getConfig().logToConsole.getValue()) {
|
||||
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.RED + message);
|
||||
}
|
||||
if (i == 0 && getConfiguration().getConfig().fileLogLevel.getValue() == LOG_LEVEL_HIGH) // Not an alert, normal log message
|
||||
{
|
||||
fileLog(message);
|
||||
} else if (getConfiguration().getConfig().fileLogLevel.getValue() != 0) { // alert
|
||||
fileLog(message);
|
||||
}
|
||||
logs.add(ChatColor.stripColor(message));
|
||||
}
|
||||
|
||||
public void fileLog(String message) {
|
||||
fileLogger.info(message);
|
||||
}
|
||||
|
||||
public List<String> getLastLogs() {
|
||||
List<String> log = new CopyOnWriteArrayList<String>();
|
||||
if (logs.size() < 30) {
|
||||
return logs;
|
||||
}
|
||||
for (int i = logs.size() - 1; i >= 0; i--) {
|
||||
log.add(logs.get(i));
|
||||
}
|
||||
logs.clear();
|
||||
return log;
|
||||
}
|
||||
|
||||
public void addEvent(String e, RegisteredListener[] arr) {
|
||||
if (!configuration.getConfig().eventChains.getValue())
|
||||
return;
|
||||
if (!eventcache.containsKey(e) || eventcache.get(e) > 30000L) {
|
||||
eventchains.put(e, arr);
|
||||
eventcache.put(e, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public String getEventChainReport() {
|
||||
String gen = "";
|
||||
if (!configuration.getConfig().eventChains.getValue()) {
|
||||
return "Event Chains is disabled by the configuration." + '\n';
|
||||
}
|
||||
|
||||
if (eventchains.entrySet().size() == 0) {
|
||||
return "No event chains found." + '\n';
|
||||
}
|
||||
|
||||
for (Entry<String, RegisteredListener[]> e : eventchains.entrySet()) {
|
||||
String toadd = "";
|
||||
String ename = e.getKey();
|
||||
|
||||
toadd += ename + ":" + '\n';
|
||||
|
||||
RegisteredListener[] reg = e.getValue();
|
||||
for (RegisteredListener plug : reg) {
|
||||
String pluginname = plug.getPlugin().getName();
|
||||
if (pluginname.equals("AntiCheat"))
|
||||
pluginname = "self";
|
||||
|
||||
toadd += "- " + pluginname + '\n';
|
||||
}
|
||||
|
||||
gen += toadd + '\n';
|
||||
}
|
||||
|
||||
return gen;
|
||||
}
|
||||
|
||||
public AntiCheat getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public XRayTracker getXRayTracker() {
|
||||
return xrayTracker;
|
||||
}
|
||||
|
||||
public UserManager getUserManager() {
|
||||
return userManager;
|
||||
}
|
||||
|
||||
public CheckManager getCheckManager() {
|
||||
return checkManager;
|
||||
}
|
||||
|
||||
public Backend getBackend() {
|
||||
return backend;
|
||||
}
|
||||
|
||||
public static void close() {
|
||||
fileHandler.close();
|
||||
|
||||
if (configuration.getConfig().enterprise.getValue()) {
|
||||
configuration.getEnterprise().database.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1079
-1079
File diff suppressed because it is too large.
Load diff
+211
-211
@@ -1,211 +1,211 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* The manager that AntiCheat will check with to see if it should watch certain checks and certain players.
|
||||
*/
|
||||
|
||||
public class CheckManager {
|
||||
private AnticheatManager manager = null;
|
||||
private Configuration config;
|
||||
private static List<CheckType> checkIgnoreList = new ArrayList<CheckType>();
|
||||
private static Map<String, List<CheckType>> exemptList = new HashMap<String, List<CheckType>>();
|
||||
private static int disabled = 0;
|
||||
private static int exempt = 0;
|
||||
|
||||
public CheckManager(AnticheatManager instance, Configuration config) {
|
||||
manager = instance;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a check on
|
||||
*
|
||||
* @param type The CheckType to enable
|
||||
*/
|
||||
public void activateCheck(CheckType type) {
|
||||
if (isActive(type)) {
|
||||
manager.log("The " + type.toString() + " check was activated.");
|
||||
checkIgnoreList.remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a check off
|
||||
*
|
||||
* @param type The CheckType to disable
|
||||
*/
|
||||
public void deactivateCheck(CheckType type) {
|
||||
if (!isActive(type)) {
|
||||
manager.log("The " + type.toString() + " check was deactivated.");
|
||||
checkIgnoreList.add(type);
|
||||
disabled++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a check is enabled
|
||||
*
|
||||
* @param type The CheckType to check
|
||||
* @return true if the check is active
|
||||
*/
|
||||
public boolean isActive(CheckType type) {
|
||||
return !checkIgnoreList.contains(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exempt a player from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public void exemptPlayer(Player player, CheckType type) {
|
||||
if (!isExempt(player, type)) {
|
||||
if (!exemptList.containsKey(player.getName())) {
|
||||
exemptList.put(player.getName(), new ArrayList<CheckType>());
|
||||
}
|
||||
manager.log(player.getName() + " was exempted from the " + type.toString() + " check.");
|
||||
exemptList.get(player.getName()).add(type);
|
||||
exempt++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unexempt a player from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public void unexemptPlayer(Player player, CheckType type) {
|
||||
if (isExempt(player, type)) {
|
||||
manager.log(player.getName() + " was re-added to the " + type.toString() + " check.");
|
||||
exemptList.get(player.getName()).remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player is exempt from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public boolean isExempt(Player player, CheckType type) {
|
||||
return exemptList.containsKey(player.getName()) ? exemptList.get(player.getName()).contains(type) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player is exempt from all checks from op status
|
||||
*
|
||||
* @param player The player
|
||||
*/
|
||||
public boolean isOpExempt(Player player) {
|
||||
return (this.manager.getConfiguration().getConfig().exemptOp.getValue() && player.isOp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player should be checked in their world
|
||||
*
|
||||
* @param player The player
|
||||
* @return true if the player's world is enabled
|
||||
*/
|
||||
public boolean checkInWorld(Player player) {
|
||||
return !config.getConfig().exemptedWorlds.getValue().contains(player.getWorld().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a quick version of the "willCheck" method, using the other non-check-specific methods beforehand
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param type The check being run
|
||||
* @return true if the check should run
|
||||
*/
|
||||
public boolean willCheckQuick(Player player, CheckType type) {
|
||||
return
|
||||
isActive(type)
|
||||
&& !isExempt(player, type)
|
||||
&& !type.checkPermission(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a check should run on a player
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param type The check being run
|
||||
* @return true if the check should run
|
||||
*/
|
||||
public boolean willCheck(Player player, CheckType type) {
|
||||
boolean check = isActive(type)
|
||||
&& checkInWorld(player)
|
||||
&& !isExempt(player, type)
|
||||
&& !type.checkPermission(player)
|
||||
&& !isOpExempt(player);
|
||||
AntiCheat.debugLog("Check " + type + (check ? " run " : " not run ") + "on " + player.getName());
|
||||
return check;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player is actually online; not an NPC
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player is a real person
|
||||
*/
|
||||
public boolean isOnline(Player player) {
|
||||
// Check if the player is on the user list, e.g. is not an NPC
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.getName().equals(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of exempt players
|
||||
*
|
||||
* @return exempt players
|
||||
*/
|
||||
public int getExempt() {
|
||||
int x = exempt;
|
||||
exempt = 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of disabled checks
|
||||
*
|
||||
* @return disabled checks
|
||||
*/
|
||||
public int getDisabled() {
|
||||
int x = disabled;
|
||||
disabled = 0;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* The manager that AntiCheat will check with to see if it should watch certain checks and certain players.
|
||||
*/
|
||||
|
||||
public class CheckManager {
|
||||
private AnticheatManager manager = null;
|
||||
private Configuration config;
|
||||
private static List<CheckType> checkIgnoreList = new ArrayList<CheckType>();
|
||||
private static Map<String, List<CheckType>> exemptList = new HashMap<String, List<CheckType>>();
|
||||
private static int disabled = 0;
|
||||
private static int exempt = 0;
|
||||
|
||||
public CheckManager(AnticheatManager instance, Configuration config) {
|
||||
manager = instance;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a check on
|
||||
*
|
||||
* @param type The CheckType to enable
|
||||
*/
|
||||
public void activateCheck(CheckType type) {
|
||||
if (isActive(type)) {
|
||||
manager.log("The " + type.toString() + " check was activated.");
|
||||
checkIgnoreList.remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a check off
|
||||
*
|
||||
* @param type The CheckType to disable
|
||||
*/
|
||||
public void deactivateCheck(CheckType type) {
|
||||
if (!isActive(type)) {
|
||||
manager.log("The " + type.toString() + " check was deactivated.");
|
||||
checkIgnoreList.add(type);
|
||||
disabled++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a check is enabled
|
||||
*
|
||||
* @param type The CheckType to check
|
||||
* @return true if the check is active
|
||||
*/
|
||||
public boolean isActive(CheckType type) {
|
||||
return !checkIgnoreList.contains(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exempt a player from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public void exemptPlayer(Player player, CheckType type) {
|
||||
if (!isExempt(player, type)) {
|
||||
if (!exemptList.containsKey(player.getName())) {
|
||||
exemptList.put(player.getName(), new ArrayList<CheckType>());
|
||||
}
|
||||
manager.log(player.getName() + " was exempted from the " + type.toString() + " check.");
|
||||
exemptList.get(player.getName()).add(type);
|
||||
exempt++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unexempt a player from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public void unexemptPlayer(Player player, CheckType type) {
|
||||
if (isExempt(player, type)) {
|
||||
manager.log(player.getName() + " was re-added to the " + type.toString() + " check.");
|
||||
exemptList.get(player.getName()).remove(type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player is exempt from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
*/
|
||||
public boolean isExempt(Player player, CheckType type) {
|
||||
return exemptList.containsKey(player.getName()) ? exemptList.get(player.getName()).contains(type) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player is exempt from all checks from op status
|
||||
*
|
||||
* @param player The player
|
||||
*/
|
||||
public boolean isOpExempt(Player player) {
|
||||
return (this.manager.getConfiguration().getConfig().exemptOp.getValue() && player.isOp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player should be checked in their world
|
||||
*
|
||||
* @param player The player
|
||||
* @return true if the player's world is enabled
|
||||
*/
|
||||
public boolean checkInWorld(Player player) {
|
||||
return !config.getConfig().exemptedWorlds.getValue().contains(player.getWorld().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a quick version of the "willCheck" method, using the other non-check-specific methods beforehand
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param type The check being run
|
||||
* @return true if the check should run
|
||||
*/
|
||||
public boolean willCheckQuick(Player player, CheckType type) {
|
||||
return
|
||||
isActive(type)
|
||||
&& !isExempt(player, type)
|
||||
&& !type.checkPermission(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a check should run on a player
|
||||
*
|
||||
* @param player The player to check
|
||||
* @param type The check being run
|
||||
* @return true if the check should run
|
||||
*/
|
||||
public boolean willCheck(Player player, CheckType type) {
|
||||
boolean check = isActive(type)
|
||||
&& checkInWorld(player)
|
||||
&& !isExempt(player, type)
|
||||
&& !type.checkPermission(player)
|
||||
&& !isOpExempt(player);
|
||||
AntiCheat.debugLog("Check " + type + (check ? " run " : " not run ") + "on " + player.getName());
|
||||
return check;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player is actually online; not an NPC
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player is a real person
|
||||
*/
|
||||
public boolean isOnline(Player player) {
|
||||
// Check if the player is on the user list, e.g. is not an NPC
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.getName().equals(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of exempt players
|
||||
*
|
||||
* @return exempt players
|
||||
*/
|
||||
public int getExempt() {
|
||||
int x = exempt;
|
||||
exempt = 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of disabled checks
|
||||
*
|
||||
* @return disabled checks
|
||||
*/
|
||||
public int getDisabled() {
|
||||
int x = disabled;
|
||||
disabled = 0;
|
||||
return x;
|
||||
}
|
||||
}
|
||||
+125
-125
@@ -1,125 +1,125 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import net.h31ix.anticheat.api.CheckFailEvent;
|
||||
import net.h31ix.anticheat.util.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* All the types of checks and their corresponding permission nodes.
|
||||
*/
|
||||
|
||||
public enum CheckType {
|
||||
ZOMBE_FLY(Permission.CHECK_ZOMBE_FLY),
|
||||
ZOMBE_NOCLIP(Permission.CHECK_ZOMBE_NOCLIP),
|
||||
ZOMBE_CHEAT(Permission.CHECK_ZOMBE_CHEAT),
|
||||
FLY(Permission.CHECK_FLY),
|
||||
WATER_WALK(Permission.CHECK_WATERWALK),
|
||||
NO_SWING(Permission.CHECK_NOSWING),
|
||||
FAST_BREAK(Permission.CHECK_FASTBREAK),
|
||||
FAST_PLACE(Permission.CHECK_FASTPLACE),
|
||||
SPAM(Permission.CHECK_SPAM),
|
||||
SPRINT(Permission.CHECK_SPRINT),
|
||||
SNEAK(Permission.CHECK_SNEAK),
|
||||
SPEED(Permission.CHECK_SPEED),
|
||||
VCLIP(Permission.CHECK_VCLIP),
|
||||
SPIDER(Permission.CHECK_SPIDER),
|
||||
NOFALL(Permission.CHECK_NOFALL),
|
||||
FAST_BOW(Permission.CHECK_FASTBOW),
|
||||
FAST_EAT(Permission.CHECK_FASTEAT),
|
||||
FAST_HEAL(Permission.CHECK_FASTHEAL),
|
||||
FORCEFIELD(Permission.CHECK_FORCEFIELD),
|
||||
XRAY(Permission.CHECK_XRAY),
|
||||
LONG_REACH(Permission.CHECK_LONGREACH),
|
||||
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
|
||||
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY),
|
||||
FAST_ANIMATION(Permission.CHECK_FASTANIMATION),
|
||||
AUTOTOOL(Permission.CHECK_AUTOTOOL);
|
||||
|
||||
private final Permission permission;
|
||||
private final Map<String, Integer> level = new HashMap<String, Integer>();
|
||||
|
||||
/**
|
||||
* Initialize a CheckType
|
||||
*
|
||||
* @param perm Permission that applies to this check
|
||||
*/
|
||||
private CheckType(Permission perm) {
|
||||
this.permission = perm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player has permission to bypass this check
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player can bypass
|
||||
*/
|
||||
public boolean checkPermission(Player player) {
|
||||
return permission.get(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the failure of this check
|
||||
*
|
||||
* @param user User who failed the check
|
||||
*/
|
||||
public void logUse(User user) {
|
||||
int amount = level.get(user.getName()) == null ? 1 : level.get(user.getName()) + 1;
|
||||
level.put(user.getName(), amount);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new CheckFailEvent(user, this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear failure history of this check for a user
|
||||
*
|
||||
* @param name User's name to clear
|
||||
*/
|
||||
public void clearUse(String name) {
|
||||
level.put(name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how many times a user has failed this check
|
||||
*
|
||||
* @param name User's name
|
||||
* @return number of times failed
|
||||
*/
|
||||
public int getUses(String name) {
|
||||
return level.get(name) != null ? level.get(name) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reference name of a check
|
||||
*
|
||||
* @param type Type of check
|
||||
* @return reference name
|
||||
*/
|
||||
public static String getName(CheckType type) {
|
||||
char[] chars = type.toString().replaceAll("_", " ").toLowerCase().toCharArray();
|
||||
chars[0] = Character.toUpperCase(chars[0]);
|
||||
return new String(chars);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.api.CheckFailEvent;
|
||||
import net.gravitydevelopment.anticheat.util.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p/>
|
||||
* All the types of checks and their corresponding permission nodes.
|
||||
*/
|
||||
|
||||
public enum CheckType {
|
||||
ZOMBE_FLY(Permission.CHECK_ZOMBE_FLY),
|
||||
ZOMBE_NOCLIP(Permission.CHECK_ZOMBE_NOCLIP),
|
||||
ZOMBE_CHEAT(Permission.CHECK_ZOMBE_CHEAT),
|
||||
FLY(Permission.CHECK_FLY),
|
||||
WATER_WALK(Permission.CHECK_WATERWALK),
|
||||
NO_SWING(Permission.CHECK_NOSWING),
|
||||
FAST_BREAK(Permission.CHECK_FASTBREAK),
|
||||
FAST_PLACE(Permission.CHECK_FASTPLACE),
|
||||
SPAM(Permission.CHECK_SPAM),
|
||||
SPRINT(Permission.CHECK_SPRINT),
|
||||
SNEAK(Permission.CHECK_SNEAK),
|
||||
SPEED(Permission.CHECK_SPEED),
|
||||
VCLIP(Permission.CHECK_VCLIP),
|
||||
SPIDER(Permission.CHECK_SPIDER),
|
||||
NOFALL(Permission.CHECK_NOFALL),
|
||||
FAST_BOW(Permission.CHECK_FASTBOW),
|
||||
FAST_EAT(Permission.CHECK_FASTEAT),
|
||||
FAST_HEAL(Permission.CHECK_FASTHEAL),
|
||||
FORCEFIELD(Permission.CHECK_FORCEFIELD),
|
||||
XRAY(Permission.CHECK_XRAY),
|
||||
LONG_REACH(Permission.CHECK_LONGREACH),
|
||||
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
|
||||
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY),
|
||||
FAST_ANIMATION(Permission.CHECK_FASTANIMATION),
|
||||
AUTOTOOL(Permission.CHECK_AUTOTOOL);
|
||||
|
||||
private final Permission permission;
|
||||
private final Map<String, Integer> level = new HashMap<String, Integer>();
|
||||
|
||||
/**
|
||||
* Initialize a CheckType
|
||||
*
|
||||
* @param perm Permission that applies to this check
|
||||
*/
|
||||
private CheckType(Permission perm) {
|
||||
this.permission = perm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player has permission to bypass this check
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player can bypass
|
||||
*/
|
||||
public boolean checkPermission(Player player) {
|
||||
return permission.get(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the failure of this check
|
||||
*
|
||||
* @param user User who failed the check
|
||||
*/
|
||||
public void logUse(User user) {
|
||||
int amount = level.get(user.getName()) == null ? 1 : level.get(user.getName()) + 1;
|
||||
level.put(user.getName(), amount);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new CheckFailEvent(user, this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear failure history of this check for a user
|
||||
*
|
||||
* @param name User's name to clear
|
||||
*/
|
||||
public void clearUse(String name) {
|
||||
level.put(name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how many times a user has failed this check
|
||||
*
|
||||
* @param name User's name
|
||||
* @return number of times failed
|
||||
*/
|
||||
public int getUses(String name) {
|
||||
return level.get(name) != null ? level.get(name) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reference name of a check
|
||||
*
|
||||
* @param type Type of check
|
||||
* @return reference name
|
||||
*/
|
||||
public static String getName(CheckType type) {
|
||||
char[] chars = type.toString().replaceAll("_", " ").toLowerCase().toCharArray();
|
||||
chars[0] = Character.toUpperCase(chars[0]);
|
||||
return new String(chars);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package net.h31ix.anticheat.manage;
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.*;
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
+346
-346
@@ -1,346 +1,346 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.h31ix.anticheat.util.rule.Rule;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class User {
|
||||
private final String name;
|
||||
private final int id;
|
||||
private int level = 0;
|
||||
private Location goodLocation;
|
||||
private List<ItemStack> inventorySnapshot = null;
|
||||
private Configuration config = AntiCheat.getManager().getConfiguration();
|
||||
private int toX, toY, toZ;
|
||||
private String[] messages = new String[2];
|
||||
private Long[] messageTimes = new Long[2];
|
||||
|
||||
private boolean isWaitingOnLevelSync;
|
||||
private Timestamp levelSyncTimestamp;
|
||||
|
||||
/**
|
||||
* Initialize an AntiCheat user
|
||||
*
|
||||
* @param name Player's name
|
||||
*/
|
||||
public User(String name) {
|
||||
this.name = name;
|
||||
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's name
|
||||
*
|
||||
* @return Player name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's entity ID
|
||||
*
|
||||
* @return Entity id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bukkit player
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's level value
|
||||
*
|
||||
* @return level
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public Level getNamedLevel() {
|
||||
List<Level> levels = config.getEvents().getLevels();
|
||||
for (int i = 0; i < levels.size(); i++) {
|
||||
if (i == 0 && level < levels.get(i).getValue()) break;
|
||||
else if (i == levels.size() - 1) return levels.get(i);
|
||||
else if (level >= levels.get(i).getValue() && level < levels.get(i + 1).getValue()) return levels.get(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the player's level (from failing a check)
|
||||
*
|
||||
* @param type The check failed
|
||||
* @return true if the level was increased
|
||||
*/
|
||||
public boolean increaseLevel(CheckType type) {
|
||||
if (getPlayer() != null && getPlayer().isOnline()) {
|
||||
if (silentMode() && type.getUses(name) % 4 != 0) {
|
||||
// Prevent silent mode from increasing the level way too fast
|
||||
return false;
|
||||
} else {
|
||||
if (level < config.getEvents().getHighestLevel()) {
|
||||
level++;
|
||||
|
||||
// Check levels
|
||||
for (Level l : getLevels()) {
|
||||
if (l.getValue() == level) {
|
||||
AntiCheat.getManager().getUserManager().alert(this, l, type);
|
||||
if (l.getValue() == config.getEvents().getHighestLevel()) {
|
||||
level = l.getValue() - 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute rules
|
||||
for (Rule rule : config.getRules().getRules()) {
|
||||
rule.check(this, type);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the player's level by one value
|
||||
*/
|
||||
public void decreaseLevel() {
|
||||
level = level != 0 ? level - 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the users level to a specific value. Must be 0 < level < config-defined highest level
|
||||
*
|
||||
* @param level level to set
|
||||
* @return true if the level was valid and set properly
|
||||
*/
|
||||
public boolean setLevel(int level) {
|
||||
isWaitingOnLevelSync = false;
|
||||
if (level >= 0) {
|
||||
if (level <= config.getEvents().getHighestLevel()) {
|
||||
this.level = level;
|
||||
return true;
|
||||
} else {
|
||||
this.level = config.getEvents().getHighestLevel();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the user's level to zero and clear all check failures
|
||||
*/
|
||||
public void resetLevel() {
|
||||
level = 0;
|
||||
for (CheckType type : CheckType.values()) {
|
||||
type.clearUse(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last known valid location of the player for use in resetting
|
||||
*
|
||||
* @param location default value to be returned if no known good location exists
|
||||
* @return last known valid location
|
||||
*/
|
||||
public Location getGoodLocation(Location location) {
|
||||
if (goodLocation == null) {
|
||||
return location;
|
||||
}
|
||||
|
||||
return goodLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last known valid location of the player
|
||||
*
|
||||
* @param location location to be set
|
||||
* @return true if the location was valid and set properly
|
||||
*/
|
||||
public boolean setGoodLocation(Location location) {
|
||||
if (Utilities.cantStandAtExp(location) || (location.getBlock().isLiquid() && !Utilities.isFullyInWater(location))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
goodLocation = location;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a copy of the player's inventory, for use in resetting
|
||||
*
|
||||
* @param is ItemStack list to store
|
||||
*/
|
||||
public void setInventorySnapshot(ItemStack[] is) {
|
||||
inventorySnapshot = new ArrayList<ItemStack>();
|
||||
for (int i = 0; i < is.length; i++) {
|
||||
if (is[i] != null) {
|
||||
inventorySnapshot.add(is[i].clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the current inventory snapshot
|
||||
*/
|
||||
public void removeInventorySnapshot() {
|
||||
inventorySnapshot = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the player's inventory with the current inventory snapshot
|
||||
*
|
||||
* @param inventory Player's inventory
|
||||
*/
|
||||
public void restoreInventory(Inventory inventory) {
|
||||
if (inventorySnapshot != null) {
|
||||
inventory.clear();
|
||||
for (ItemStack is : inventorySnapshot) {
|
||||
if (is != null) {
|
||||
inventory.addItem(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the player's to location
|
||||
*
|
||||
* @param x X value
|
||||
* @param y Y value
|
||||
* @param z Z value
|
||||
*/
|
||||
public void setTo(double x, double y, double z) {
|
||||
toX = (int) x;
|
||||
toY = (int) y;
|
||||
toZ = (int) z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given to value is the same as the stored value
|
||||
*
|
||||
* @param x X value
|
||||
* @param y Y value
|
||||
* @param z Z value
|
||||
* @return true if coordinates are all equal
|
||||
*/
|
||||
public boolean checkTo(double x, double y, double z) {
|
||||
return (int) x == toX && (int) y == toY && (int) z == toZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a player's chat message
|
||||
*
|
||||
* @param message Message to log
|
||||
*/
|
||||
public void addMessage(String message) {
|
||||
messages[1] = messages[0];
|
||||
messages[0] = message;
|
||||
|
||||
messageTimes[1] = messageTimes[0];
|
||||
messageTimes[0] = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a stored chat message
|
||||
*
|
||||
* @param index Index of the chat in storage
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage(int index) {
|
||||
return messages[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time a message in storage was sent
|
||||
*
|
||||
* @param index Index of the chat in storage
|
||||
* @return time the message was sent
|
||||
*/
|
||||
public Long getMessageTime(int index) {
|
||||
return messageTimes[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all stored messages
|
||||
*/
|
||||
public void clearMessages() {
|
||||
messages = new String[2];
|
||||
messageTimes = new Long[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time the very last stored message was sent
|
||||
*
|
||||
* @return the last message's time
|
||||
*/
|
||||
public Long getLastMessageTime() {
|
||||
return getMessageTime(0) == null ? -1 : getMessageTime(0);
|
||||
}
|
||||
|
||||
private List<Level> getLevels() {
|
||||
return config.getEvents().getLevels();
|
||||
}
|
||||
|
||||
private boolean silentMode() {
|
||||
return config.getConfig().silentMode.getValue();
|
||||
}
|
||||
|
||||
public void setIsWaitingOnLevelSync(boolean b) {
|
||||
this.isWaitingOnLevelSync = b;
|
||||
}
|
||||
|
||||
public boolean isWaitingOnLevelSync() {
|
||||
return isWaitingOnLevelSync;
|
||||
}
|
||||
|
||||
public void setLevelSyncTimestamp(Timestamp timestamp) {
|
||||
levelSyncTimestamp = timestamp;
|
||||
}
|
||||
|
||||
public Timestamp getLevelSyncTimestamp() {
|
||||
return levelSyncTimestamp;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.util.Level;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import net.gravitydevelopment.anticheat.util.rule.Rule;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class User {
|
||||
private final String name;
|
||||
private final int id;
|
||||
private int level = 0;
|
||||
private Location goodLocation;
|
||||
private List<ItemStack> inventorySnapshot = null;
|
||||
private Configuration config = AntiCheat.getManager().getConfiguration();
|
||||
private int toX, toY, toZ;
|
||||
private String[] messages = new String[2];
|
||||
private Long[] messageTimes = new Long[2];
|
||||
|
||||
private boolean isWaitingOnLevelSync;
|
||||
private Timestamp levelSyncTimestamp;
|
||||
|
||||
/**
|
||||
* Initialize an AntiCheat user
|
||||
*
|
||||
* @param name Player's name
|
||||
*/
|
||||
public User(String name) {
|
||||
this.name = name;
|
||||
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's name
|
||||
*
|
||||
* @return Player name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's entity ID
|
||||
*
|
||||
* @return Entity id
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bukkit player
|
||||
*
|
||||
* @return Player
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's level value
|
||||
*
|
||||
* @return level
|
||||
*/
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public Level getNamedLevel() {
|
||||
List<Level> levels = config.getEvents().getLevels();
|
||||
for (int i = 0; i < levels.size(); i++) {
|
||||
if (i == 0 && level < levels.get(i).getValue()) break;
|
||||
else if (i == levels.size() - 1) return levels.get(i);
|
||||
else if (level >= levels.get(i).getValue() && level < levels.get(i + 1).getValue()) return levels.get(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the player's level (from failing a check)
|
||||
*
|
||||
* @param type The check failed
|
||||
* @return true if the level was increased
|
||||
*/
|
||||
public boolean increaseLevel(CheckType type) {
|
||||
if (getPlayer() != null && getPlayer().isOnline()) {
|
||||
if (silentMode() && type.getUses(name) % 4 != 0) {
|
||||
// Prevent silent mode from increasing the level way too fast
|
||||
return false;
|
||||
} else {
|
||||
if (level < config.getEvents().getHighestLevel()) {
|
||||
level++;
|
||||
|
||||
// Check levels
|
||||
for (Level l : getLevels()) {
|
||||
if (l.getValue() == level) {
|
||||
AntiCheat.getManager().getUserManager().alert(this, l, type);
|
||||
if (l.getValue() == config.getEvents().getHighestLevel()) {
|
||||
level = l.getValue() - 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute rules
|
||||
for (Rule rule : config.getRules().getRules()) {
|
||||
rule.check(this, type);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the player's level by one value
|
||||
*/
|
||||
public void decreaseLevel() {
|
||||
level = level != 0 ? level - 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the users level to a specific value. Must be 0 < level < config-defined highest level
|
||||
*
|
||||
* @param level level to set
|
||||
* @return true if the level was valid and set properly
|
||||
*/
|
||||
public boolean setLevel(int level) {
|
||||
isWaitingOnLevelSync = false;
|
||||
if (level >= 0) {
|
||||
if (level <= config.getEvents().getHighestLevel()) {
|
||||
this.level = level;
|
||||
return true;
|
||||
} else {
|
||||
this.level = config.getEvents().getHighestLevel();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the user's level to zero and clear all check failures
|
||||
*/
|
||||
public void resetLevel() {
|
||||
level = 0;
|
||||
for (CheckType type : CheckType.values()) {
|
||||
type.clearUse(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last known valid location of the player for use in resetting
|
||||
*
|
||||
* @param location default value to be returned if no known good location exists
|
||||
* @return last known valid location
|
||||
*/
|
||||
public Location getGoodLocation(Location location) {
|
||||
if (goodLocation == null) {
|
||||
return location;
|
||||
}
|
||||
|
||||
return goodLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last known valid location of the player
|
||||
*
|
||||
* @param location location to be set
|
||||
* @return true if the location was valid and set properly
|
||||
*/
|
||||
public boolean setGoodLocation(Location location) {
|
||||
if (Utilities.cantStandAtExp(location) || (location.getBlock().isLiquid() && !Utilities.isFullyInWater(location))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
goodLocation = location;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a copy of the player's inventory, for use in resetting
|
||||
*
|
||||
* @param is ItemStack list to store
|
||||
*/
|
||||
public void setInventorySnapshot(ItemStack[] is) {
|
||||
inventorySnapshot = new ArrayList<ItemStack>();
|
||||
for (int i = 0; i < is.length; i++) {
|
||||
if (is[i] != null) {
|
||||
inventorySnapshot.add(is[i].clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the current inventory snapshot
|
||||
*/
|
||||
public void removeInventorySnapshot() {
|
||||
inventorySnapshot = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the player's inventory with the current inventory snapshot
|
||||
*
|
||||
* @param inventory Player's inventory
|
||||
*/
|
||||
public void restoreInventory(Inventory inventory) {
|
||||
if (inventorySnapshot != null) {
|
||||
inventory.clear();
|
||||
for (ItemStack is : inventorySnapshot) {
|
||||
if (is != null) {
|
||||
inventory.addItem(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the player's to location
|
||||
*
|
||||
* @param x X value
|
||||
* @param y Y value
|
||||
* @param z Z value
|
||||
*/
|
||||
public void setTo(double x, double y, double z) {
|
||||
toX = (int) x;
|
||||
toY = (int) y;
|
||||
toZ = (int) z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given to value is the same as the stored value
|
||||
*
|
||||
* @param x X value
|
||||
* @param y Y value
|
||||
* @param z Z value
|
||||
* @return true if coordinates are all equal
|
||||
*/
|
||||
public boolean checkTo(double x, double y, double z) {
|
||||
return (int) x == toX && (int) y == toY && (int) z == toZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a player's chat message
|
||||
*
|
||||
* @param message Message to log
|
||||
*/
|
||||
public void addMessage(String message) {
|
||||
messages[1] = messages[0];
|
||||
messages[0] = message;
|
||||
|
||||
messageTimes[1] = messageTimes[0];
|
||||
messageTimes[0] = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a stored chat message
|
||||
*
|
||||
* @param index Index of the chat in storage
|
||||
* @return the message
|
||||
*/
|
||||
public String getMessage(int index) {
|
||||
return messages[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time a message in storage was sent
|
||||
*
|
||||
* @param index Index of the chat in storage
|
||||
* @return time the message was sent
|
||||
*/
|
||||
public Long getMessageTime(int index) {
|
||||
return messageTimes[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all stored messages
|
||||
*/
|
||||
public void clearMessages() {
|
||||
messages = new String[2];
|
||||
messageTimes = new Long[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time the very last stored message was sent
|
||||
*
|
||||
* @return the last message's time
|
||||
*/
|
||||
public Long getLastMessageTime() {
|
||||
return getMessageTime(0) == null ? -1 : getMessageTime(0);
|
||||
}
|
||||
|
||||
private List<Level> getLevels() {
|
||||
return config.getEvents().getLevels();
|
||||
}
|
||||
|
||||
private boolean silentMode() {
|
||||
return config.getConfig().silentMode.getValue();
|
||||
}
|
||||
|
||||
public void setIsWaitingOnLevelSync(boolean b) {
|
||||
this.isWaitingOnLevelSync = b;
|
||||
}
|
||||
|
||||
public boolean isWaitingOnLevelSync() {
|
||||
return isWaitingOnLevelSync;
|
||||
}
|
||||
|
||||
public void setLevelSyncTimestamp(Timestamp timestamp) {
|
||||
levelSyncTimestamp = timestamp;
|
||||
}
|
||||
|
||||
public Timestamp getLevelSyncTimestamp() {
|
||||
return levelSyncTimestamp;
|
||||
}
|
||||
}
|
||||
+229
-229
@@ -1,229 +1,229 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserManager {
|
||||
private List<User> users = new ArrayList<User>();
|
||||
private static Configuration config;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private static final ChatColor GOLD = ChatColor.GOLD;
|
||||
private static final ChatColor YELLOW = ChatColor.YELLOW;
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static List<String> alert;
|
||||
|
||||
/**
|
||||
* Initialize the user manager with a given configuration
|
||||
*
|
||||
* @param conf Configuration to use
|
||||
*/
|
||||
public UserManager(Configuration conf) {
|
||||
config = conf;
|
||||
alert = config.getLang().alert.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user with the given name
|
||||
*
|
||||
* @param name Name
|
||||
* @return User with name
|
||||
*/
|
||||
public User getUser(String name) {
|
||||
for (User user : users) {
|
||||
if (user.getName().equalsIgnoreCase(name)) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
// Otherwise try to load them
|
||||
User user = new User(name);
|
||||
user.setIsWaitingOnLevelSync(true);
|
||||
config.getLevels().loadLevelToUser(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users
|
||||
*
|
||||
* @return List of users
|
||||
*/
|
||||
public List<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user to the list
|
||||
*
|
||||
* @param user User to add
|
||||
*/
|
||||
public void addUser(User user) {
|
||||
users.add(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user from the list
|
||||
*
|
||||
* @param user User to remove
|
||||
*/
|
||||
public void remove(User user) {
|
||||
users.remove(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a user's level
|
||||
*
|
||||
* @param user User to save
|
||||
*/
|
||||
public void saveLevel(User user) {
|
||||
config.getLevels().saveLevelFromUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user's level, or 0 if the player isn't found
|
||||
*
|
||||
* @param name Name of the player
|
||||
* @return player level
|
||||
*/
|
||||
public int safeGetLevel(String name) {
|
||||
User user = getUser(name);
|
||||
if (user == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return user.getLevel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a user's level
|
||||
*
|
||||
* @param name Name of the player
|
||||
* @param level Level to set
|
||||
*/
|
||||
public void safeSetLevel(String name, int level) {
|
||||
User user = getUser(name);
|
||||
if (user != null) {
|
||||
user.setLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a user
|
||||
*
|
||||
* @param name Name of the user
|
||||
*/
|
||||
public void safeReset(String name) {
|
||||
User user = getUser(name);
|
||||
if (user != null) {
|
||||
user.resetLevel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an alert
|
||||
*
|
||||
* @param user The user to alert
|
||||
* @param level The user's level
|
||||
* @param type The CheckType that triggered the alert
|
||||
*/
|
||||
public void alert(User user, Level level, CheckType type) {
|
||||
ArrayList<String> messageArray = new ArrayList<String>();
|
||||
for (int i = 0; i < alert.size(); i++) {
|
||||
String message = alert.get(i);
|
||||
if (!message.equals("")) {
|
||||
message = message.replaceAll("&player", GOLD + user.getName() + GRAY);
|
||||
message = message.replaceAll("&check", GOLD + CheckType.getName(type) + GRAY);
|
||||
message = message.replaceAll("&level", level.getColor() + level.getName() + GRAY);
|
||||
messageArray.add(message);
|
||||
}
|
||||
}
|
||||
Utilities.alert(messageArray);
|
||||
execute(user, level.getActions(), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute configuration actions for an alert
|
||||
*
|
||||
* @param user The user
|
||||
* @param actions The list of actions to execute
|
||||
* @param type The CheckType that triggered the alert
|
||||
*/
|
||||
public void execute(User user, List<String> actions, CheckType type) {
|
||||
execute(user, actions, type, config.getLang().kickReason.getValue(), config.getLang().playerWarning.getValue(), config.getLang().banReason.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute configuration actions for an alert
|
||||
*
|
||||
* @param user The user
|
||||
* @param actions The list of actions to execute
|
||||
* @param type The CheckType that triggered the alert
|
||||
* @param kickReason The config's kick reason
|
||||
* @param warning The config's warning format
|
||||
* @param banReason The config's ban reason
|
||||
*/
|
||||
public void execute(final User user, final List<String> actions, final CheckType type, final String kickReason, final List<String> warning, final String banReason) {
|
||||
// Execute synchronously for thread safety when called from AsyncPlayerChatEvent
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String name = user.getName();
|
||||
for (String event : actions) {
|
||||
event = event.replaceAll("&player", name).replaceAll("&world", user.getPlayer().getWorld().getName()).replaceAll("&check", type.name());
|
||||
|
||||
if (event.startsWith("COMMAND[")) {
|
||||
for (String cmd : Utilities.getCommands(event)) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("KICK")) {
|
||||
user.getPlayer().kickPlayer(RED + kickReason);
|
||||
String msg = RED + config.getLang().kickBroadcast.getValue().replaceAll("&player", name);
|
||||
if (!msg.equals("")) {
|
||||
Bukkit.broadcastMessage(msg);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("WARN")) {
|
||||
List<String> message = warning;
|
||||
for (String string : message) {
|
||||
if (!string.equals("")) {
|
||||
user.getPlayer().sendMessage(RED + string);
|
||||
}
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("BAN")) {
|
||||
user.getPlayer().setBanned(true);
|
||||
user.getPlayer().kickPlayer(RED + banReason);
|
||||
String msg = RED + config.getLang().banBroadcast.getValue().replaceAll("&player", name);
|
||||
if (!msg.equals("")) {
|
||||
Bukkit.broadcastMessage(msg);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("RESET")) {
|
||||
user.resetLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.manage;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.util.Level;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class UserManager {
|
||||
private List<User> users = new ArrayList<User>();
|
||||
private static Configuration config;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private static final ChatColor GOLD = ChatColor.GOLD;
|
||||
private static final ChatColor YELLOW = ChatColor.YELLOW;
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static List<String> alert;
|
||||
|
||||
/**
|
||||
* Initialize the user manager with a given configuration
|
||||
*
|
||||
* @param conf Configuration to use
|
||||
*/
|
||||
public UserManager(Configuration conf) {
|
||||
config = conf;
|
||||
alert = config.getLang().alert.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user with the given name
|
||||
*
|
||||
* @param name Name
|
||||
* @return User with name
|
||||
*/
|
||||
public User getUser(String name) {
|
||||
for (User user : users) {
|
||||
if (user.getName().equalsIgnoreCase(name)) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
// Otherwise try to load them
|
||||
User user = new User(name);
|
||||
user.setIsWaitingOnLevelSync(true);
|
||||
config.getLevels().loadLevelToUser(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users
|
||||
*
|
||||
* @return List of users
|
||||
*/
|
||||
public List<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a user to the list
|
||||
*
|
||||
* @param user User to add
|
||||
*/
|
||||
public void addUser(User user) {
|
||||
users.add(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user from the list
|
||||
*
|
||||
* @param user User to remove
|
||||
*/
|
||||
public void remove(User user) {
|
||||
users.remove(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a user's level
|
||||
*
|
||||
* @param user User to save
|
||||
*/
|
||||
public void saveLevel(User user) {
|
||||
config.getLevels().saveLevelFromUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user's level, or 0 if the player isn't found
|
||||
*
|
||||
* @param name Name of the player
|
||||
* @return player level
|
||||
*/
|
||||
public int safeGetLevel(String name) {
|
||||
User user = getUser(name);
|
||||
if (user == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return user.getLevel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a user's level
|
||||
*
|
||||
* @param name Name of the player
|
||||
* @param level Level to set
|
||||
*/
|
||||
public void safeSetLevel(String name, int level) {
|
||||
User user = getUser(name);
|
||||
if (user != null) {
|
||||
user.setLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a user
|
||||
*
|
||||
* @param name Name of the user
|
||||
*/
|
||||
public void safeReset(String name) {
|
||||
User user = getUser(name);
|
||||
if (user != null) {
|
||||
user.resetLevel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an alert
|
||||
*
|
||||
* @param user The user to alert
|
||||
* @param level The user's level
|
||||
* @param type The CheckType that triggered the alert
|
||||
*/
|
||||
public void alert(User user, Level level, CheckType type) {
|
||||
ArrayList<String> messageArray = new ArrayList<String>();
|
||||
for (int i = 0; i < alert.size(); i++) {
|
||||
String message = alert.get(i);
|
||||
if (!message.equals("")) {
|
||||
message = message.replaceAll("&player", GOLD + user.getName() + GRAY);
|
||||
message = message.replaceAll("&check", GOLD + CheckType.getName(type) + GRAY);
|
||||
message = message.replaceAll("&level", level.getColor() + level.getName() + GRAY);
|
||||
messageArray.add(message);
|
||||
}
|
||||
}
|
||||
Utilities.alert(messageArray);
|
||||
execute(user, level.getActions(), type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute configuration actions for an alert
|
||||
*
|
||||
* @param user The user
|
||||
* @param actions The list of actions to execute
|
||||
* @param type The CheckType that triggered the alert
|
||||
*/
|
||||
public void execute(User user, List<String> actions, CheckType type) {
|
||||
execute(user, actions, type, config.getLang().kickReason.getValue(), config.getLang().playerWarning.getValue(), config.getLang().banReason.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute configuration actions for an alert
|
||||
*
|
||||
* @param user The user
|
||||
* @param actions The list of actions to execute
|
||||
* @param type The CheckType that triggered the alert
|
||||
* @param kickReason The config's kick reason
|
||||
* @param warning The config's warning format
|
||||
* @param banReason The config's ban reason
|
||||
*/
|
||||
public void execute(final User user, final List<String> actions, final CheckType type, final String kickReason, final List<String> warning, final String banReason) {
|
||||
// Execute synchronously for thread safety when called from AsyncPlayerChatEvent
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String name = user.getName();
|
||||
for (String event : actions) {
|
||||
event = event.replaceAll("&player", name).replaceAll("&world", user.getPlayer().getWorld().getName()).replaceAll("&check", type.name());
|
||||
|
||||
if (event.startsWith("COMMAND[")) {
|
||||
for (String cmd : Utilities.getCommands(event)) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("KICK")) {
|
||||
user.getPlayer().kickPlayer(RED + kickReason);
|
||||
String msg = RED + config.getLang().kickBroadcast.getValue().replaceAll("&player", name);
|
||||
if (!msg.equals("")) {
|
||||
Bukkit.broadcastMessage(msg);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("WARN")) {
|
||||
List<String> message = warning;
|
||||
for (String string : message) {
|
||||
if (!string.equals("")) {
|
||||
user.getPlayer().sendMessage(RED + string);
|
||||
}
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("BAN")) {
|
||||
user.getPlayer().setBanned(true);
|
||||
user.getPlayer().kickPlayer(RED + banReason);
|
||||
String msg = RED + config.getLang().banBroadcast.getValue().replaceAll("&player", name);
|
||||
if (!msg.equals("")) {
|
||||
Bukkit.broadcastMessage(msg);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("RESET")) {
|
||||
user.resetLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+515
-515
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
+239
-239
@@ -1,239 +1,239 @@
|
||||
// Not production code yet. Still experimental and needs a lot of work.
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Calibrator implements Listener {
|
||||
private final Player player;
|
||||
private int step = 0;
|
||||
private static final int TOTAL = 30;
|
||||
private long lastLong;
|
||||
private int lastInt;
|
||||
private int lastDouble;
|
||||
private long[] longs = new long[10];
|
||||
private double[] doubles = new double[10];
|
||||
private int[] ints = new int[10];
|
||||
private int times = 0;
|
||||
|
||||
// Value-specific calculations
|
||||
private long projectileTime;
|
||||
private long dropItemTime;
|
||||
private long punchAvg;
|
||||
private double blockBreakMax;
|
||||
private double blockPlaceMax;
|
||||
|
||||
public Calibrator(Player player) {
|
||||
this.player = player;
|
||||
player.sendMessage(ChatColor.GREEN + "----You have entered calibration mode.----");
|
||||
// Wait for listener to be registered and calibrate method called.
|
||||
}
|
||||
|
||||
public void calibrate() {
|
||||
switch (step) {
|
||||
case 0:
|
||||
sendStep();
|
||||
player.getInventory().setItemInHand(new ItemStack(Material.BOW));
|
||||
player.getInventory().addItem(new ItemStack(Material.ARROW, 64));
|
||||
player.sendMessage("Fire arrows as fast as possible (don't pull all the way back)");
|
||||
break;
|
||||
case 2:
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setItemInHand(new ItemStack(Material.DIRT, 64));
|
||||
player.sendMessage("Drop items as fast as possible.");
|
||||
/*
|
||||
* case 0: sendStep(); player.sendMessage("Spam the left mouse button as fast as possible."); break; case 2: player.setGameMode(GameMode.CREATIVE); player.sendMessage("Break blocks from as far away as you can possibly get from them."); break; case 3:
|
||||
* player.sendMessage("Place blocks from as far away as you can possibly get from them."); break;
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getLongCount() {
|
||||
int fill = 0;
|
||||
for (long l : longs) {
|
||||
if (l != 0) {
|
||||
fill++;
|
||||
}
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
private int getDoubleCount() {
|
||||
int fill = 0;
|
||||
for (double d : doubles) {
|
||||
if (d != 0) {
|
||||
fill++;
|
||||
}
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
for (int i = 0; i < longs.length; i++) {
|
||||
longs[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
ints[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < doubles.length; i++) {
|
||||
doubles[i] = 0;
|
||||
}
|
||||
lastInt = 0;
|
||||
lastDouble = 0;
|
||||
lastLong = 0;
|
||||
times = 0;
|
||||
|
||||
}
|
||||
|
||||
private void sendStep() {
|
||||
step++;
|
||||
player.sendMessage(ChatColor.GREEN + "Step " + step + "/" + TOTAL);
|
||||
}
|
||||
|
||||
// Find the average time it takes to do a task
|
||||
private long getAvgLong() {
|
||||
int count = getLongCount();
|
||||
if (count < 10) {
|
||||
if (lastLong == 0) {
|
||||
lastLong = System.currentTimeMillis();
|
||||
} else {
|
||||
longs[count] = System.currentTimeMillis() - lastLong;
|
||||
lastLong = System.currentTimeMillis();
|
||||
}
|
||||
} else {
|
||||
long avg = 0;
|
||||
for (long l : longs) {
|
||||
avg += l;
|
||||
}
|
||||
clear();
|
||||
avg /= 10;
|
||||
player.sendMessage(ChatColor.AQUA + "Done. Average calculated at " + ChatColor.WHITE + avg);
|
||||
sendStep();
|
||||
calibrate();
|
||||
return avg;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Find the maximum time it takes to do a task
|
||||
private double getMaxDouble(double length) {
|
||||
int count = getDoubleCount();
|
||||
if (count < 10) {
|
||||
doubles[count] = length;
|
||||
} else {
|
||||
double max = 0;
|
||||
for (double d : doubles) {
|
||||
if (max == 0 || d > max) {
|
||||
max = d;
|
||||
}
|
||||
}
|
||||
clear();
|
||||
player.sendMessage(ChatColor.AQUA + "Done. Maximum calculated at " + ChatColor.WHITE + max);
|
||||
sendStep();
|
||||
calibrate();
|
||||
return max;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the absolute time it takes to do something X times
|
||||
private long getAbsoluteLong() {
|
||||
int count = getLongCount();
|
||||
if (count < 10) {
|
||||
if (lastLong == 0) {
|
||||
lastLong = System.currentTimeMillis();
|
||||
} else {
|
||||
longs[count] = System.currentTimeMillis();
|
||||
lastLong = System.currentTimeMillis();
|
||||
}
|
||||
} else {
|
||||
long val = longs[9] - longs[0];
|
||||
clear();
|
||||
player.sendMessage(ChatColor.AQUA + "Done. Value calculated at " + ChatColor.WHITE + val);
|
||||
sendStep();
|
||||
calibrate();
|
||||
return val;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Begin event listeners
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == 2) {
|
||||
long v = getAbsoluteLong();
|
||||
if (v != -1) {
|
||||
dropItemTime = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
if (event.getEntity() instanceof Player && ((Player) event.getEntity()) == player) {
|
||||
if (step == 1) {
|
||||
long v = getAbsoluteLong();
|
||||
if (v != -1) {
|
||||
projectileTime = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == -1) {
|
||||
long v = getAvgLong();
|
||||
if (v != -1) {
|
||||
punchAvg = v;
|
||||
}
|
||||
} else if (step == 1) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == -1) {
|
||||
double lengthX = Math.abs(event.getBlock().getX() - event.getPlayer().getLocation().getX());
|
||||
double lengthZ = Math.abs(event.getBlock().getZ() - event.getPlayer().getLocation().getZ());
|
||||
double v = getMaxDouble(lengthX >= lengthZ ? lengthX : lengthZ);
|
||||
if (v != -1) {
|
||||
blockBreakMax = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == -1) {
|
||||
double lengthX = Math.abs(event.getBlock().getX() - event.getPlayer().getLocation().getX());
|
||||
double lengthZ = Math.abs(event.getBlock().getZ() - event.getPlayer().getLocation().getZ());
|
||||
double v = getMaxDouble(lengthX >= lengthZ ? lengthX : lengthZ);
|
||||
if (v != -1) {
|
||||
blockPlaceMax = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Not production code yet. Still experimental and needs a lot of work.
|
||||
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Calibrator implements Listener {
|
||||
private final Player player;
|
||||
private int step = 0;
|
||||
private static final int TOTAL = 30;
|
||||
private long lastLong;
|
||||
private int lastInt;
|
||||
private int lastDouble;
|
||||
private long[] longs = new long[10];
|
||||
private double[] doubles = new double[10];
|
||||
private int[] ints = new int[10];
|
||||
private int times = 0;
|
||||
|
||||
// Value-specific calculations
|
||||
private long projectileTime;
|
||||
private long dropItemTime;
|
||||
private long punchAvg;
|
||||
private double blockBreakMax;
|
||||
private double blockPlaceMax;
|
||||
|
||||
public Calibrator(Player player) {
|
||||
this.player = player;
|
||||
player.sendMessage(ChatColor.GREEN + "----You have entered calibration mode.----");
|
||||
// Wait for listener to be registered and calibrate method called.
|
||||
}
|
||||
|
||||
public void calibrate() {
|
||||
switch (step) {
|
||||
case 0:
|
||||
sendStep();
|
||||
player.getInventory().setItemInHand(new ItemStack(Material.BOW));
|
||||
player.getInventory().addItem(new ItemStack(Material.ARROW, 64));
|
||||
player.sendMessage("Fire arrows as fast as possible (don't pull all the way back)");
|
||||
break;
|
||||
case 2:
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setItemInHand(new ItemStack(Material.DIRT, 64));
|
||||
player.sendMessage("Drop items as fast as possible.");
|
||||
/*
|
||||
* case 0: sendStep(); player.sendMessage("Spam the left mouse button as fast as possible."); break; case 2: player.setGameMode(GameMode.CREATIVE); player.sendMessage("Break blocks from as far away as you can possibly get from them."); break; case 3:
|
||||
* player.sendMessage("Place blocks from as far away as you can possibly get from them."); break;
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getLongCount() {
|
||||
int fill = 0;
|
||||
for (long l : longs) {
|
||||
if (l != 0) {
|
||||
fill++;
|
||||
}
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
private int getDoubleCount() {
|
||||
int fill = 0;
|
||||
for (double d : doubles) {
|
||||
if (d != 0) {
|
||||
fill++;
|
||||
}
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
for (int i = 0; i < longs.length; i++) {
|
||||
longs[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
ints[i] = 0;
|
||||
}
|
||||
for (int i = 0; i < doubles.length; i++) {
|
||||
doubles[i] = 0;
|
||||
}
|
||||
lastInt = 0;
|
||||
lastDouble = 0;
|
||||
lastLong = 0;
|
||||
times = 0;
|
||||
|
||||
}
|
||||
|
||||
private void sendStep() {
|
||||
step++;
|
||||
player.sendMessage(ChatColor.GREEN + "Step " + step + "/" + TOTAL);
|
||||
}
|
||||
|
||||
// Find the average time it takes to do a task
|
||||
private long getAvgLong() {
|
||||
int count = getLongCount();
|
||||
if (count < 10) {
|
||||
if (lastLong == 0) {
|
||||
lastLong = System.currentTimeMillis();
|
||||
} else {
|
||||
longs[count] = System.currentTimeMillis() - lastLong;
|
||||
lastLong = System.currentTimeMillis();
|
||||
}
|
||||
} else {
|
||||
long avg = 0;
|
||||
for (long l : longs) {
|
||||
avg += l;
|
||||
}
|
||||
clear();
|
||||
avg /= 10;
|
||||
player.sendMessage(ChatColor.AQUA + "Done. Average calculated at " + ChatColor.WHITE + avg);
|
||||
sendStep();
|
||||
calibrate();
|
||||
return avg;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Find the maximum time it takes to do a task
|
||||
private double getMaxDouble(double length) {
|
||||
int count = getDoubleCount();
|
||||
if (count < 10) {
|
||||
doubles[count] = length;
|
||||
} else {
|
||||
double max = 0;
|
||||
for (double d : doubles) {
|
||||
if (max == 0 || d > max) {
|
||||
max = d;
|
||||
}
|
||||
}
|
||||
clear();
|
||||
player.sendMessage(ChatColor.AQUA + "Done. Maximum calculated at " + ChatColor.WHITE + max);
|
||||
sendStep();
|
||||
calibrate();
|
||||
return max;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the absolute time it takes to do something X times
|
||||
private long getAbsoluteLong() {
|
||||
int count = getLongCount();
|
||||
if (count < 10) {
|
||||
if (lastLong == 0) {
|
||||
lastLong = System.currentTimeMillis();
|
||||
} else {
|
||||
longs[count] = System.currentTimeMillis();
|
||||
lastLong = System.currentTimeMillis();
|
||||
}
|
||||
} else {
|
||||
long val = longs[9] - longs[0];
|
||||
clear();
|
||||
player.sendMessage(ChatColor.AQUA + "Done. Value calculated at " + ChatColor.WHITE + val);
|
||||
sendStep();
|
||||
calibrate();
|
||||
return val;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Begin event listeners
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == 2) {
|
||||
long v = getAbsoluteLong();
|
||||
if (v != -1) {
|
||||
dropItemTime = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
if (event.getEntity() instanceof Player && ((Player) event.getEntity()) == player) {
|
||||
if (step == 1) {
|
||||
long v = getAbsoluteLong();
|
||||
if (v != -1) {
|
||||
projectileTime = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == -1) {
|
||||
long v = getAvgLong();
|
||||
if (v != -1) {
|
||||
punchAvg = v;
|
||||
}
|
||||
} else if (step == 1) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == -1) {
|
||||
double lengthX = Math.abs(event.getBlock().getX() - event.getPlayer().getLocation().getX());
|
||||
double lengthZ = Math.abs(event.getBlock().getZ() - event.getPlayer().getLocation().getZ());
|
||||
double v = getMaxDouble(lengthX >= lengthZ ? lengthX : lengthZ);
|
||||
if (v != -1) {
|
||||
blockBreakMax = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
if (step == -1) {
|
||||
double lengthX = Math.abs(event.getBlock().getX() - event.getPlayer().getLocation().getX());
|
||||
double lengthZ = Math.abs(event.getBlock().getZ() - event.getPlayer().getLocation().getZ());
|
||||
double v = getMaxDouble(lengthX >= lengthZ ? lengthX : lengthZ);
|
||||
if (v != -1) {
|
||||
blockPlaceMax = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
public class CheckResult {
|
||||
|
||||
+59
-59
@@ -1,59 +1,59 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Distance {
|
||||
private final double l1Y;
|
||||
private final double l2Y;
|
||||
|
||||
private final double XDiff;
|
||||
private final double YDiff;
|
||||
private final double ZDiff;
|
||||
|
||||
public Distance(Location from, Location to) {
|
||||
l1Y = to.getY();
|
||||
l2Y = from.getY();
|
||||
|
||||
XDiff = Math.abs(to.getX() - from.getX());
|
||||
ZDiff = Math.abs(to.getZ() - from.getZ());
|
||||
YDiff = Math.abs(l1Y - l2Y);
|
||||
}
|
||||
|
||||
public double fromY() {
|
||||
return l2Y;
|
||||
}
|
||||
|
||||
public double toY() {
|
||||
return l1Y;
|
||||
}
|
||||
|
||||
public double getXDifference() {
|
||||
return XDiff;
|
||||
}
|
||||
|
||||
public double getZDifference() {
|
||||
return ZDiff;
|
||||
}
|
||||
|
||||
public double getYDifference() {
|
||||
return YDiff;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Distance {
|
||||
private final double l1Y;
|
||||
private final double l2Y;
|
||||
|
||||
private final double XDiff;
|
||||
private final double YDiff;
|
||||
private final double ZDiff;
|
||||
|
||||
public Distance(Location from, Location to) {
|
||||
l1Y = to.getY();
|
||||
l2Y = from.getY();
|
||||
|
||||
XDiff = Math.abs(to.getX() - from.getX());
|
||||
ZDiff = Math.abs(to.getZ() - from.getZ());
|
||||
YDiff = Math.abs(l1Y - l2Y);
|
||||
}
|
||||
|
||||
public double fromY() {
|
||||
return l2Y;
|
||||
}
|
||||
|
||||
public double toY() {
|
||||
return l1Y;
|
||||
}
|
||||
|
||||
public double getXDifference() {
|
||||
return XDiff;
|
||||
}
|
||||
|
||||
public double getZDifference() {
|
||||
return ZDiff;
|
||||
}
|
||||
|
||||
public double getYDifference() {
|
||||
return YDiff;
|
||||
}
|
||||
}
|
||||
+36
-36
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class FileFormatter extends Formatter {
|
||||
private static final DateFormat FORMAT = new SimpleDateFormat("h:mm:ss");
|
||||
private static final String LINE_SEP = System.getProperty("line.separator");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
StringBuilder output = new StringBuilder().append("[").append(record.getLevel()).append('|').append(FORMAT.format(new Date(record.getMillis()))).append("]: ").append(record.getMessage()).append(' ').append(LINE_SEP);
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
public class FileFormatter extends Formatter {
|
||||
private static final DateFormat FORMAT = new SimpleDateFormat("h:mm:ss");
|
||||
private static final String LINE_SEP = System.getProperty("line.separator");
|
||||
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
StringBuilder output = new StringBuilder().append("[").append(record.getLevel()).append('|').append(FORMAT.format(new Date(record.getMillis()))).append("]: ").append(record.getMessage()).append(' ').append(LINE_SEP);
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -16,9 +16,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
+3
-3
@@ -16,10 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.files.Magic;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.files.Magic;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
+563
-563
File diff suppressed because it is too large.
Load diff
+5
-5
@@ -16,12 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util.enterprise;
|
||||
package net.gravitydevelopment.anticheat.util.enterprise;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
+4
-4
@@ -16,10 +16,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util.rule;
|
||||
package net.gravitydevelopment.anticheat.util.rule;
|
||||
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
@@ -42,7 +42,7 @@ import java.util.SortedMap;
|
||||
* Check_SPIDER > 0 ? Player.KICK : null<br />
|
||||
* <i>The above statement would read 'If the spider check has been failed over zero times, kick the player. Otherwise, do nothing.'</i>
|
||||
* <p/>
|
||||
* To see syntax for variables and functions that you may use, see {@link net.h31ix.anticheat.util.rule.Rule}
|
||||
* To see syntax for variables and functions that you may use, see {@link net.gravitydevelopment.anticheat.util.rule.Rule}
|
||||
*/
|
||||
public class ConditionalRule extends Rule {
|
||||
|
||||
+9
-9
@@ -16,12 +16,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util.rule;
|
||||
package net.gravitydevelopment.anticheat.util.rule;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import net.gravitydevelopment.anticheat.util.Utilities;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
@@ -39,7 +39,7 @@ import java.util.TreeMap;
|
||||
* <br /><br />
|
||||
* <p/>
|
||||
* <b>Types of variables:</b><br />
|
||||
* - Check: Contains all valid checks as listed in {@link net.h31ix.anticheat.manage.CheckType}, and will return the number of times this user has failed the given check<br />
|
||||
* - Check: Contains all valid checks as listed in {@link net.gravitydevelopment.anticheat.manage.CheckType}, and will return the number of times this user has failed the given check<br />
|
||||
* - Player: Contains LEVEL, the player's current level and CHECK, the check that was just failed
|
||||
* <br /><br />
|
||||
* <p/>
|
||||
@@ -56,7 +56,7 @@ import java.util.TreeMap;
|
||||
* <p/>
|
||||
* The Rule class itself is not an functional rule setup,
|
||||
* it is inherited and made functional by different implementations of the rule parser.<br />
|
||||
* The only current Rule implementation is the {@link net.h31ix.anticheat.util.rule.ConditionalRule}
|
||||
* The only current Rule implementation is the {@link net.gravitydevelopment.anticheat.util.rule.ConditionalRule}
|
||||
*/
|
||||
public class Rule {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Rule {
|
||||
private Type type;
|
||||
|
||||
public enum Type {
|
||||
CONDITIONAL(".*[?]*.*:.*", "net.h31ix.anticheat.util.rule.ConditionalRule");
|
||||
CONDITIONAL(".*[?]*.*:.*", "net.gravitydevelopment.anticheat.util.rule.ConditionalRule");
|
||||
|
||||
private String regex;
|
||||
private String c;
|
||||
@@ -125,7 +125,7 @@ public class Rule {
|
||||
/**
|
||||
* Get the type of rule this is
|
||||
*
|
||||
* @return a {@link net.h31ix.anticheat.util.rule.Rule.Type}
|
||||
* @return a {@link net.gravitydevelopment.anticheat.util.rule.Rule.Type}
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
+66
-66
@@ -1,66 +1,66 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.xray;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.manage.CheckManager;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
public class XRayListener implements Listener {
|
||||
private XRayTracker tracker = AntiCheat.getManager().getXRayTracker();
|
||||
private Configuration config = AntiCheat.getManager().getConfiguration();
|
||||
private CheckManager checkManager = AntiCheat.getManager().getCheckManager();
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (config.getConfig().logXRayStats.getValue()) {
|
||||
Player p = event.getPlayer();
|
||||
if (p.getGameMode() == GameMode.CREATIVE && !config.getConfig().trackCreativeXRay.getValue()) {
|
||||
return;
|
||||
}
|
||||
String player = p.getName();
|
||||
if (checkManager.willCheck(p, CheckType.XRAY)) {
|
||||
Material m = event.getBlock().getType();
|
||||
if (m == Material.DIAMOND_ORE) {
|
||||
tracker.addDiamond(player);
|
||||
} else if (m == Material.IRON_ORE) {
|
||||
tracker.addIron(player);
|
||||
} else if (m == Material.GOLD_ORE) {
|
||||
tracker.addGold(player);
|
||||
} else if (m == Material.LAPIS_ORE) {
|
||||
tracker.addLapis(player);
|
||||
} else if (m == Material.REDSTONE_ORE || m == Material.GLOWING_REDSTONE_ORE) {
|
||||
tracker.addRedstone(player);
|
||||
} else if (m == Material.GOLD_ORE) {
|
||||
tracker.addGold(player);
|
||||
} else {
|
||||
tracker.addBlock(player);
|
||||
}
|
||||
tracker.addTotal(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.xray;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckManager;
|
||||
import net.gravitydevelopment.anticheat.manage.CheckType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
public class XRayListener implements Listener {
|
||||
private XRayTracker tracker = AntiCheat.getManager().getXRayTracker();
|
||||
private Configuration config = AntiCheat.getManager().getConfiguration();
|
||||
private CheckManager checkManager = AntiCheat.getManager().getCheckManager();
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (config.getConfig().logXRayStats.getValue()) {
|
||||
Player p = event.getPlayer();
|
||||
if (p.getGameMode() == GameMode.CREATIVE && !config.getConfig().trackCreativeXRay.getValue()) {
|
||||
return;
|
||||
}
|
||||
String player = p.getName();
|
||||
if (checkManager.willCheck(p, CheckType.XRAY)) {
|
||||
Material m = event.getBlock().getType();
|
||||
if (m == Material.DIAMOND_ORE) {
|
||||
tracker.addDiamond(player);
|
||||
} else if (m == Material.IRON_ORE) {
|
||||
tracker.addIron(player);
|
||||
} else if (m == Material.GOLD_ORE) {
|
||||
tracker.addGold(player);
|
||||
} else if (m == Material.LAPIS_ORE) {
|
||||
tracker.addLapis(player);
|
||||
} else if (m == Material.REDSTONE_ORE || m == Material.GLOWING_REDSTONE_ORE) {
|
||||
tracker.addRedstone(player);
|
||||
} else if (m == Material.GOLD_ORE) {
|
||||
tracker.addGold(player);
|
||||
} else {
|
||||
tracker.addBlock(player);
|
||||
}
|
||||
tracker.addTotal(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+84
-84
@@ -1,84 +1,84 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.xray;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class XRayStats {
|
||||
private static final int DIVISOR = 100;
|
||||
private double t = 1;
|
||||
private double d = 0;
|
||||
private double g = 0;
|
||||
private double i = 0;
|
||||
private double l = 0;
|
||||
private double r = 0;
|
||||
private double o = 0;
|
||||
|
||||
public XRayStats(String player, Map<String, Integer> diamond, Map<String, Integer> gold, Map<String, Integer> iron, Map<String, Integer> lapis, Map<String, Integer> redstone, Map<String, Integer> other, Map<String, Integer> total) {
|
||||
if (total.get(player) != null) {
|
||||
t = total.get(player);
|
||||
}
|
||||
if (diamond.get(player) != null) {
|
||||
d = (diamond.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (gold.get(player) != null) {
|
||||
g = (gold.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (iron.get(player) != null) {
|
||||
i = (iron.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (lapis.get(player) != null) {
|
||||
l = (lapis.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (redstone.get(player) != null) {
|
||||
r = (redstone.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (other.get(player) != null) {
|
||||
o = (other.get(player) / t) * DIVISOR;
|
||||
}
|
||||
}
|
||||
|
||||
public double getTotal() {
|
||||
return t;
|
||||
}
|
||||
|
||||
public double getDiamond() {
|
||||
return d;
|
||||
}
|
||||
|
||||
public double getGold() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public double getIron() {
|
||||
return i;
|
||||
}
|
||||
|
||||
public double getLapis() {
|
||||
return l;
|
||||
}
|
||||
|
||||
public double getRedstone() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public double getOther() {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.xray;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class XRayStats {
|
||||
private static final int DIVISOR = 100;
|
||||
private double t = 1;
|
||||
private double d = 0;
|
||||
private double g = 0;
|
||||
private double i = 0;
|
||||
private double l = 0;
|
||||
private double r = 0;
|
||||
private double o = 0;
|
||||
|
||||
public XRayStats(String player, Map<String, Integer> diamond, Map<String, Integer> gold, Map<String, Integer> iron, Map<String, Integer> lapis, Map<String, Integer> redstone, Map<String, Integer> other, Map<String, Integer> total) {
|
||||
if (total.get(player) != null) {
|
||||
t = total.get(player);
|
||||
}
|
||||
if (diamond.get(player) != null) {
|
||||
d = (diamond.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (gold.get(player) != null) {
|
||||
g = (gold.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (iron.get(player) != null) {
|
||||
i = (iron.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (lapis.get(player) != null) {
|
||||
l = (lapis.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (redstone.get(player) != null) {
|
||||
r = (redstone.get(player) / t) * DIVISOR;
|
||||
}
|
||||
if (other.get(player) != null) {
|
||||
o = (other.get(player) / t) * DIVISOR;
|
||||
}
|
||||
}
|
||||
|
||||
public double getTotal() {
|
||||
return t;
|
||||
}
|
||||
|
||||
public double getDiamond() {
|
||||
return d;
|
||||
}
|
||||
|
||||
public double getGold() {
|
||||
return g;
|
||||
}
|
||||
|
||||
public double getIron() {
|
||||
return i;
|
||||
}
|
||||
|
||||
public double getLapis() {
|
||||
return l;
|
||||
}
|
||||
|
||||
public double getRedstone() {
|
||||
return r;
|
||||
}
|
||||
|
||||
public double getOther() {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
+152
-152
@@ -1,152 +1,152 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.xray;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class XRayTracker {
|
||||
private Map<String, Integer> diamond = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> gold = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> iron = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> lapis = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> redstone = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> block = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> totalblock = new HashMap<String, Integer>();
|
||||
private List<String> alerted = new ArrayList<String>();
|
||||
private static final ChatColor GREEN = ChatColor.GREEN;
|
||||
private static final ChatColor WHITE = ChatColor.WHITE;
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private static final int RATIO_DIVISOR = 3;
|
||||
private static final int POWER = 10;
|
||||
private static final int MIN_BLOCK_COUNT = 100;
|
||||
|
||||
public XRayTracker() {
|
||||
}
|
||||
|
||||
public boolean sufficientData(String player) {
|
||||
return totalblock.get(player) != null && totalblock.get(player) >= MIN_BLOCK_COUNT;
|
||||
}
|
||||
|
||||
public void calculate(CommandSender cs, String player, double x, double b, String type) {
|
||||
ChatColor color = WHITE;
|
||||
if (x >= b / RATIO_DIVISOR) {
|
||||
color = RED;
|
||||
}
|
||||
cs.sendMessage(GRAY + "Percent " + type + " ore: " + color + round(x) + "%");
|
||||
}
|
||||
|
||||
public boolean calculate(String player, double x, double b) {
|
||||
return x >= b / RATIO_DIVISOR;
|
||||
}
|
||||
|
||||
public boolean hasAbnormal(String player) {
|
||||
XRayStats stats = new XRayStats(player, diamond, gold, iron, lapis, redstone, block, totalblock);
|
||||
double total = stats.getOther();
|
||||
return calculate(player, stats.getDiamond(), total) || calculate(player, stats.getGold(), total) || calculate(player, stats.getIron(), total) || calculate(player, stats.getLapis(), total) || calculate(player, stats.getRedstone(), total);
|
||||
}
|
||||
|
||||
public boolean hasAlerted(String player) {
|
||||
return alerted.contains(player);
|
||||
}
|
||||
|
||||
public void logAlert(String player) {
|
||||
alerted.add(player);
|
||||
}
|
||||
|
||||
public void sendStats(CommandSender cs, String player) {
|
||||
getStats(cs, player);
|
||||
}
|
||||
|
||||
public void getStats(CommandSender cs, String player) {
|
||||
XRayStats stats = new XRayStats(player, diamond, gold, iron, lapis, redstone, block, totalblock);
|
||||
double total = stats.getOther();
|
||||
cs.sendMessage("--------------------[" + GREEN + "X-Ray Stats" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Player: " + WHITE + player);
|
||||
cs.sendMessage(GRAY + "Total blocks broken: " + WHITE + stats.getTotal());
|
||||
calculate(cs, player, stats.getDiamond(), total, "diamond");
|
||||
calculate(cs, player, stats.getGold(), total, "gold");
|
||||
calculate(cs, player, stats.getIron(), total, "iron");
|
||||
calculate(cs, player, stats.getLapis(), total, "lapis");
|
||||
calculate(cs, player, stats.getRedstone(), total, "redstone");
|
||||
cs.sendMessage(GRAY + "Percent all other blocks: " + WHITE + round(stats.getOther()) + "%");
|
||||
cs.sendMessage("-----------------------------------------------------");
|
||||
}
|
||||
|
||||
public void addDiamond(String player) {
|
||||
addOre(player, diamond);
|
||||
}
|
||||
|
||||
public void addGold(String player) {
|
||||
addOre(player, gold);
|
||||
}
|
||||
|
||||
public void addIron(String player) {
|
||||
addOre(player, iron);
|
||||
}
|
||||
|
||||
public void addLapis(String player) {
|
||||
addOre(player, lapis);
|
||||
}
|
||||
|
||||
public void addRedstone(String player) {
|
||||
addOre(player, redstone);
|
||||
}
|
||||
|
||||
public void addBlock(String player) {
|
||||
addOre(player, block);
|
||||
}
|
||||
|
||||
public void addTotal(String player) {
|
||||
addOre(player, totalblock);
|
||||
}
|
||||
|
||||
private void addOre(String player, Map<String, Integer> map) {
|
||||
if (map.get(player) == null || map.get(player) == 0) {
|
||||
map.put(player, 1);
|
||||
} else {
|
||||
int playerLevel = map.get(player);
|
||||
map.put(player, playerLevel + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private float round(double num) {
|
||||
double number = num;
|
||||
float p = (float) Math.pow(POWER, 1);
|
||||
number *= p;
|
||||
float tmp = Math.round(number);
|
||||
return tmp / p;
|
||||
}
|
||||
|
||||
public void reset(String player) {
|
||||
totalblock.put(player, 1);
|
||||
diamond.put(player, 0);
|
||||
iron.put(player, 0);
|
||||
gold.put(player, 0);
|
||||
redstone.put(player, 0);
|
||||
lapis.put(player, 0);
|
||||
totalblock.put(player, 0);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.xray;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class XRayTracker {
|
||||
private Map<String, Integer> diamond = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> gold = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> iron = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> lapis = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> redstone = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> block = new HashMap<String, Integer>();
|
||||
private Map<String, Integer> totalblock = new HashMap<String, Integer>();
|
||||
private List<String> alerted = new ArrayList<String>();
|
||||
private static final ChatColor GREEN = ChatColor.GREEN;
|
||||
private static final ChatColor WHITE = ChatColor.WHITE;
|
||||
private static final ChatColor RED = ChatColor.RED;
|
||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||
private static final int RATIO_DIVISOR = 3;
|
||||
private static final int POWER = 10;
|
||||
private static final int MIN_BLOCK_COUNT = 100;
|
||||
|
||||
public XRayTracker() {
|
||||
}
|
||||
|
||||
public boolean sufficientData(String player) {
|
||||
return totalblock.get(player) != null && totalblock.get(player) >= MIN_BLOCK_COUNT;
|
||||
}
|
||||
|
||||
public void calculate(CommandSender cs, String player, double x, double b, String type) {
|
||||
ChatColor color = WHITE;
|
||||
if (x >= b / RATIO_DIVISOR) {
|
||||
color = RED;
|
||||
}
|
||||
cs.sendMessage(GRAY + "Percent " + type + " ore: " + color + round(x) + "%");
|
||||
}
|
||||
|
||||
public boolean calculate(String player, double x, double b) {
|
||||
return x >= b / RATIO_DIVISOR;
|
||||
}
|
||||
|
||||
public boolean hasAbnormal(String player) {
|
||||
XRayStats stats = new XRayStats(player, diamond, gold, iron, lapis, redstone, block, totalblock);
|
||||
double total = stats.getOther();
|
||||
return calculate(player, stats.getDiamond(), total) || calculate(player, stats.getGold(), total) || calculate(player, stats.getIron(), total) || calculate(player, stats.getLapis(), total) || calculate(player, stats.getRedstone(), total);
|
||||
}
|
||||
|
||||
public boolean hasAlerted(String player) {
|
||||
return alerted.contains(player);
|
||||
}
|
||||
|
||||
public void logAlert(String player) {
|
||||
alerted.add(player);
|
||||
}
|
||||
|
||||
public void sendStats(CommandSender cs, String player) {
|
||||
getStats(cs, player);
|
||||
}
|
||||
|
||||
public void getStats(CommandSender cs, String player) {
|
||||
XRayStats stats = new XRayStats(player, diamond, gold, iron, lapis, redstone, block, totalblock);
|
||||
double total = stats.getOther();
|
||||
cs.sendMessage("--------------------[" + GREEN + "X-Ray Stats" + WHITE + "]---------------------");
|
||||
cs.sendMessage(GRAY + "Player: " + WHITE + player);
|
||||
cs.sendMessage(GRAY + "Total blocks broken: " + WHITE + stats.getTotal());
|
||||
calculate(cs, player, stats.getDiamond(), total, "diamond");
|
||||
calculate(cs, player, stats.getGold(), total, "gold");
|
||||
calculate(cs, player, stats.getIron(), total, "iron");
|
||||
calculate(cs, player, stats.getLapis(), total, "lapis");
|
||||
calculate(cs, player, stats.getRedstone(), total, "redstone");
|
||||
cs.sendMessage(GRAY + "Percent all other blocks: " + WHITE + round(stats.getOther()) + "%");
|
||||
cs.sendMessage("-----------------------------------------------------");
|
||||
}
|
||||
|
||||
public void addDiamond(String player) {
|
||||
addOre(player, diamond);
|
||||
}
|
||||
|
||||
public void addGold(String player) {
|
||||
addOre(player, gold);
|
||||
}
|
||||
|
||||
public void addIron(String player) {
|
||||
addOre(player, iron);
|
||||
}
|
||||
|
||||
public void addLapis(String player) {
|
||||
addOre(player, lapis);
|
||||
}
|
||||
|
||||
public void addRedstone(String player) {
|
||||
addOre(player, redstone);
|
||||
}
|
||||
|
||||
public void addBlock(String player) {
|
||||
addOre(player, block);
|
||||
}
|
||||
|
||||
public void addTotal(String player) {
|
||||
addOre(player, totalblock);
|
||||
}
|
||||
|
||||
private void addOre(String player, Map<String, Integer> map) {
|
||||
if (map.get(player) == null || map.get(player) == 0) {
|
||||
map.put(player, 1);
|
||||
} else {
|
||||
int playerLevel = map.get(player);
|
||||
map.put(player, playerLevel + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private float round(double num) {
|
||||
double number = num;
|
||||
float p = (float) Math.pow(POWER, 1);
|
||||
number *= p;
|
||||
float tmp = Math.round(number);
|
||||
return tmp / p;
|
||||
}
|
||||
|
||||
public void reset(String player) {
|
||||
totalblock.put(player, 1);
|
||||
diamond.put(player, 0);
|
||||
iron.put(player, 0);
|
||||
gold.put(player, 0);
|
||||
redstone.put(player, 0);
|
||||
lapis.put(player, 0);
|
||||
totalblock.put(player, 0);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
author: Gravity
|
||||
database: false
|
||||
description: Prevention of hacks and other malicious tinkering on a Minecraft server.
|
||||
main: net.h31ix.anticheat.AntiCheat
|
||||
main: net.gravitydevelopment.anticheat.AntiCheat
|
||||
name: AntiCheat
|
||||
softdepend: [ProtocolLib]
|
||||
startup: postworld
|
||||
url: http://gravitydevelopment.net
|
||||
version: ${project.version}-b${BUILD_NUMBER}
|
||||
version: ${project.build.version}
|
||||
commands:
|
||||
anticheat:
|
||||
description: Control and view info about AntiCheat
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
package net.gravitydevelopment.anticheat.util;
|
||||
|
||||
|
||||
import org.bukkit.Material;
|
||||
Reference in new issue
Block a user