mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Sanity clean up
This commit is contained in:
1 parent
ca4406809b
commit
9486e18c4f
47 files changed
+710
-784
No files matched your search
@@ -18,10 +18,6 @@
|
||||
|
||||
package net.h31ix.anticheat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.event.*;
|
||||
@@ -38,6 +34,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AntiCheat extends JavaPlugin {
|
||||
|
||||
private static AnticheatManager manager;
|
||||
@@ -157,8 +156,8 @@ public class AntiCheat extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void setupEnterprise() {
|
||||
if(config.getConfig().enterprise.getValue()) {
|
||||
if(config.getEnterprise().loggingEnabled.getValue()) {
|
||||
if (config.getConfig().enterprise.getValue()) {
|
||||
if (config.getEnterprise().loggingEnabled.getValue()) {
|
||||
config.getEnterprise().database.cleanEvents();
|
||||
}
|
||||
}
|
||||
@@ -214,7 +213,7 @@ public class AntiCheat extends JavaPlugin {
|
||||
public static void debugLog(final String string) {
|
||||
Bukkit.getScheduler().runTask(getPlugin(), new Runnable() {
|
||||
public void run() {
|
||||
if(developer) {
|
||||
if (developer) {
|
||||
manager.log("[DEBUG] " + string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
|
||||
package net.h31ix.anticheat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
@@ -36,6 +33,9 @@ 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();
|
||||
@@ -53,7 +53,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
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")) {
|
||||
@@ -77,7 +77,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handleDebug(CommandSender cs) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_DEBUG)) {
|
||||
cs.sendMessage(GRAY + "Please wait while I collect some data...");
|
||||
@@ -86,7 +86,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
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...");
|
||||
@@ -95,7 +95,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
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()) {
|
||||
@@ -121,14 +121,14 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
if (user != null) {
|
||||
user.resetLevel();
|
||||
XRAY_TRACKER.reset(player.getName());
|
||||
user.clearMessages();
|
||||
@@ -144,7 +144,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handleSpy(CommandSender cs, String[] args) {
|
||||
if (cs instanceof Player) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_SPY)) {
|
||||
@@ -193,11 +193,11 @@ public class CommandHandler implements CommandExecutor {
|
||||
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 = {
|
||||
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",
|
||||
@@ -211,12 +211,12 @@ public class CommandHandler implements CommandExecutor {
|
||||
};
|
||||
|
||||
cs.sendMessage("----------------------[" + GREEN + "AntiCheat" + WHITE + "]----------------------");
|
||||
for(String s : lines) {
|
||||
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());
|
||||
@@ -234,7 +234,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handleCalibrate(CommandSender cs) {
|
||||
if (cs instanceof Player) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_CALIBRATE)) {
|
||||
@@ -244,7 +244,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handleReport(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
getPlayers();
|
||||
@@ -276,7 +276,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getReportPageNum(String[] args) {
|
||||
if (args.length == 2) {
|
||||
return 1;
|
||||
@@ -286,7 +286,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
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) {
|
||||
@@ -311,7 +311,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void handlePlayerReport(CommandSender cs, String[] args) {
|
||||
if (hasPermission(cs, Permission.SYSTEM_REPORT)) {
|
||||
User user = AntiCheat.getManager().getUserManager().getUser(args[1]);
|
||||
@@ -348,7 +348,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
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);
|
||||
@@ -356,7 +356,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
Level level = user.getNamedLevel();
|
||||
String levelString = ChatColor.GREEN + "Low";
|
||||
|
||||
if(level != null) {
|
||||
if (level != null) {
|
||||
levelString = level.getColor() + level.getName();
|
||||
}
|
||||
levelString += " (" + user.getLevel() + ")";
|
||||
@@ -391,20 +391,20 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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())) {
|
||||
for (Level level : CONFIG.getEvents().getLevels()) {
|
||||
if (args[1].equalsIgnoreCase(level.getName())) {
|
||||
handleReport(cs, args);
|
||||
return true;
|
||||
}
|
||||
@@ -461,7 +461,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void getPlayers() {
|
||||
high.clear();
|
||||
med.clear();
|
||||
@@ -479,7 +479,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender cs, Permission perm) {
|
||||
if(perm.get(cs)) {
|
||||
if (perm.get(cs)) {
|
||||
return true;
|
||||
} else {
|
||||
cs.sendMessage(PERMISSIONS_ERROR + " (" + WHITE + perm.toString() + RED + ")");
|
||||
|
||||
@@ -19,12 +19,14 @@
|
||||
package net.h31ix.anticheat.api;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.manage.*;
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Developer's interface for all things AntiCheat.
|
||||
*/
|
||||
|
||||
@@ -32,107 +34,107 @@ 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
|
||||
* @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
|
||||
* @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
|
||||
* @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
|
||||
* @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
|
||||
* @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.
|
||||
*/
|
||||
@@ -140,12 +142,12 @@ public class AnticheatAPI {
|
||||
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() {
|
||||
|
||||
@@ -50,6 +50,7 @@ public class CheckFailEvent extends Event {
|
||||
|
||||
/**
|
||||
* Get the {@link net.h31ix.anticheat.manage.CheckType} failed
|
||||
*
|
||||
* @return a {@link net.h31ix.anticheat.manage.CheckType}
|
||||
*/
|
||||
public CheckType getCheck() {
|
||||
|
||||
@@ -19,13 +19,15 @@
|
||||
package net.h31ix.anticheat.config;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.files.*;
|
||||
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.YamlLevelsHolder;
|
||||
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;
|
||||
@@ -54,53 +56,59 @@ public class Configuration {
|
||||
lang = new Lang(plugin, this);
|
||||
magic = new Magic(plugin, this);
|
||||
|
||||
flatfiles = new ArrayList<ConfigurationFile>(){{ add(config); add(enterprise); add(lang); add(magic); }};
|
||||
flatfiles = new ArrayList<ConfigurationFile>() {{
|
||||
add(config);
|
||||
add(enterprise);
|
||||
add(lang);
|
||||
add(magic);
|
||||
}};
|
||||
|
||||
dbfiles = new ArrayList<ConfigurationTable>();
|
||||
|
||||
// The following values can be configuration from a database, or from flatfile.
|
||||
if(config.enterprise.getValue() && enterprise.configEvents.getValue()) {
|
||||
if (config.enterprise.getValue() && enterprise.configEvents.getValue()) {
|
||||
events = new MySQLEventsHolder(this);
|
||||
dbfiles.add((MySQLEventsHolder)events);
|
||||
dbfiles.add((MySQLEventsHolder) events);
|
||||
} else {
|
||||
events = new YamlEventsHolder(plugin, this);
|
||||
flatfiles.add((YamlEventsHolder)events);
|
||||
flatfiles.add((YamlEventsHolder) events);
|
||||
}
|
||||
|
||||
if(config.enterprise.getValue() && enterprise.configRules.getValue()) {
|
||||
if (config.enterprise.getValue() && enterprise.configRules.getValue()) {
|
||||
rules = new MySQLRulesHolder(this);
|
||||
dbfiles.add((MySQLRulesHolder)rules);
|
||||
dbfiles.add((MySQLRulesHolder) rules);
|
||||
} else {
|
||||
rules = new YamlRulesHolder(plugin, this);
|
||||
flatfiles.add((YamlRulesHolder)rules);
|
||||
flatfiles.add((YamlRulesHolder) rules);
|
||||
}
|
||||
|
||||
if(config.enterprise.getValue() && enterprise.configEvents.getValue()) {
|
||||
if (config.enterprise.getValue() && enterprise.configEvents.getValue()) {
|
||||
levels = new MySQLLevelsHolder(this);
|
||||
dbfiles.add((MySQLLevelsHolder)levels);
|
||||
dbfiles.add((MySQLLevelsHolder) levels);
|
||||
} else {
|
||||
levels = new YamlLevelsHolder(plugin, this);
|
||||
flatfiles.add((YamlLevelsHolder)levels);
|
||||
flatfiles.add((YamlLevelsHolder) levels);
|
||||
}
|
||||
// End
|
||||
|
||||
for(ConfigurationFile file : flatfiles) {
|
||||
for (ConfigurationFile file : flatfiles) {
|
||||
file.save();
|
||||
checkReload(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
for(ConfigurationFile file : flatfiles) {
|
||||
for (ConfigurationFile file : flatfiles) {
|
||||
file.load();
|
||||
checkReload(file);
|
||||
}
|
||||
for(ConfigurationTable table : dbfiles) {
|
||||
for (ConfigurationTable table : dbfiles) {
|
||||
table.load();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkReload(ConfigurationFile file) {
|
||||
if(file.needsReload()) {
|
||||
if (file.needsReload()) {
|
||||
file.reload();
|
||||
file.setNeedsReload(false);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ConfigurationFile {
|
||||
this.rawFile = rawFile;
|
||||
this.saveDefault = saveDefault;
|
||||
|
||||
if(saveDefault) {
|
||||
if (saveDefault) {
|
||||
defaultConfigFile = YamlConfiguration.loadConfiguration(plugin.getResource(fileName));
|
||||
}
|
||||
load();
|
||||
@@ -65,11 +65,11 @@ public class ConfigurationFile {
|
||||
|
||||
public void load() {
|
||||
// Can change with user editing
|
||||
if(!rawFile.exists()) {
|
||||
if(saveDefault) {
|
||||
if (!rawFile.exists()) {
|
||||
if (saveDefault) {
|
||||
plugin.saveResource(fileName, true);
|
||||
} else {
|
||||
if(!rawFile.getParentFile().exists()) {
|
||||
if (!rawFile.getParentFile().exists()) {
|
||||
rawFile.getParentFile().mkdir();
|
||||
}
|
||||
try {
|
||||
@@ -144,9 +144,9 @@ public class ConfigurationFile {
|
||||
public ConfigValue(String path, boolean loadDefault) {
|
||||
this.path = path;
|
||||
|
||||
if(getConfigFile().contains(path)) {
|
||||
if (getConfigFile().contains(path)) {
|
||||
value = getConfigFile().get(path);
|
||||
} else if(loadDefault) {
|
||||
} else if (loadDefault) {
|
||||
getConfigFile().set(path, getDefaultConfigFile().get(path));
|
||||
value = getDefaultConfigFile().get(path);
|
||||
getConfigFile().set(path, value);
|
||||
|
||||
@@ -21,6 +21,7 @@ package net.h31ix.anticheat.config.files;
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Config extends ConfigurationFile {
|
||||
|
||||
@@ -67,16 +67,16 @@ public class Enterprise extends ConfigurationFile {
|
||||
|
||||
// Convert database values to Database
|
||||
database = new Database(
|
||||
Database.DatabaseType.valueOf(databaseType.getValue()),
|
||||
databaseHostname.getValue(),
|
||||
databasePort.getValue(),
|
||||
databaseUsername.getValue(),
|
||||
databasePassword.getValue(),
|
||||
databasePrefix.getValue(),
|
||||
databaseSchema.getValue(),
|
||||
serverName.getValue(),
|
||||
loggingInterval.getValue(),
|
||||
loggingLife.getValue()
|
||||
Database.DatabaseType.valueOf(databaseType.getValue()),
|
||||
databaseHostname.getValue(),
|
||||
databasePort.getValue(),
|
||||
databaseUsername.getValue(),
|
||||
databasePassword.getValue(),
|
||||
databasePrefix.getValue(),
|
||||
databaseSchema.getValue(),
|
||||
serverName.getValue(),
|
||||
loggingInterval.getValue(),
|
||||
loggingLife.getValue()
|
||||
);
|
||||
|
||||
database.connect();
|
||||
|
||||
@@ -24,16 +24,16 @@ import net.h31ix.anticheat.config.ConfigurationFile;
|
||||
|
||||
/**
|
||||
* Magic number class. Modifications to values in magic.yml will be accepted here.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Note that although each value is documented, changing it may have unintended side-effects. For instance, setting something to 0 that the plugin then uses as a dividend will result in an error. <br>
|
||||
* Also realize that the smaller a value is, the less you should change it; it's probably small for a reason. The larger a value is, the safer it is to probably change it.
|
||||
* <p>
|
||||
* <p/>
|
||||
* <b>How to read the value documentation:</b> <br>
|
||||
* First, you will see a description of the value. Then, you will see a type: <br>
|
||||
* <b>Type SYSTEM:</b> This is a 'long' value, measured in milliseconds, used to compare past and future events with the current system time. Remember, 1000 ms = 1 second. <br>
|
||||
* <b>Type INTEGER:</b> This is a regular number. It's typically used as something trivial, such as how many times X event can occur. <br>
|
||||
* <b>Type DOUBLE:</b> This is a number that has a decimal in it. It's typically used to evaluate speed or distance.
|
||||
* <p>
|
||||
* <p/>
|
||||
* After the type, you may see a recommendation labeled as '+Leniency'. This means 'In order to add leniency to this value, do X' <br>
|
||||
* The suggestion for adding leniency will either be to INCREASE or DECREASE the variable. Doing what it suggests will cause the system to not judge the people being checked so vigorously.
|
||||
*/
|
||||
@@ -349,7 +349,7 @@ public class Magic extends ConfigurationFile {
|
||||
public long TELEPORT_MIN;
|
||||
|
||||
private double version;
|
||||
|
||||
|
||||
public Magic(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, "magic.yml");
|
||||
}
|
||||
@@ -358,7 +358,7 @@ public class Magic extends ConfigurationFile {
|
||||
public void open() {
|
||||
version = new ConfigValue<Double>("VERSION").getValue();
|
||||
|
||||
if(version == 0.2D) {
|
||||
if (version == 0.2D) {
|
||||
// 0.2 -> 0.3 diffs
|
||||
// Fix improperly stored double Y_MAXDIFF
|
||||
new ConfigValue<Double>("Y_MAXDIFF").setValue(new ConfigValue<Double>("Y_MAXDIFF").getDefaultValue());
|
||||
|
||||
@@ -45,7 +45,7 @@ public class MySQLEventsHolder extends ConfigurationTable implements Events {
|
||||
highestLevel = 0;
|
||||
levels = new ArrayList<Level>();
|
||||
|
||||
String sqlCreate= "CREATE TABLE IF NOT EXISTS " + getFullTable() + "(" +
|
||||
String sqlCreate = "CREATE TABLE IF NOT EXISTS " + getFullTable() + "(" +
|
||||
" `id` INT NOT NULL," +
|
||||
" `name` VARCHAR(45) NOT NULL," +
|
||||
" `level` INT NOT NULL," +
|
||||
@@ -59,14 +59,14 @@ public class MySQLEventsHolder extends ConfigurationTable implements Events {
|
||||
getConnection().commit();
|
||||
|
||||
ResultSet set = getConnection().prepareStatement(sqlLoad).executeQuery();
|
||||
while(set.next()) {
|
||||
while (set.next()) {
|
||||
String name = set.getString("name");
|
||||
int level = set.getInt("level");
|
||||
String color = set.getString("color");
|
||||
List<String> actions = Arrays.asList(set.getString("actions").split(","));
|
||||
|
||||
levels.add(new Level(name, level, color, actions));
|
||||
if(level > highestLevel) {
|
||||
if (level > highestLevel) {
|
||||
highestLevel = level;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,11 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
|
||||
|
||||
@Override
|
||||
public void saveLevelFromUser(final User user) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable(){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!user.isWaitingOnLevelSync()) {
|
||||
AntiCheat.debugLog("Syncing to "+user.getName()+" value "+user.getLevel());
|
||||
AntiCheat.debugLog("Syncing to " + user.getName() + " value " + user.getLevel());
|
||||
try {
|
||||
PreparedStatement statement = getConnection().prepareStatement(sqlSave);
|
||||
statement.setString(1, user.getName());
|
||||
@@ -98,7 +98,7 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
|
||||
|
||||
@Override
|
||||
public void loadLevelToUser(final User user) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable(){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -108,13 +108,13 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
boolean has = false;
|
||||
while(set.next()) {
|
||||
while (set.next()) {
|
||||
has = true;
|
||||
AntiCheat.debugLog("Syncing from "+user.getName()+" value "+set.getInt("level"));
|
||||
AntiCheat.debugLog("Syncing from " + user.getName() + " value " + set.getInt("level"));
|
||||
user.setLevel(set.getInt("level"));
|
||||
user.setLevelSyncTimestamp(set.getTimestamp("last_update"));
|
||||
}
|
||||
if(!has) user.setLevel(0);
|
||||
if (!has) user.setLevel(0);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
|
||||
public void saveLevelsFromUsers(List<User> users) {
|
||||
try {
|
||||
PreparedStatement statement = getConnection().prepareStatement(sqlSave);
|
||||
for(User user : users) {
|
||||
for (User user : users) {
|
||||
if (!user.isWaitingOnLevelSync()) {
|
||||
try {
|
||||
statement.setString(1, user.getName());
|
||||
|
||||
@@ -54,13 +54,13 @@ public class MySQLRulesHolder extends ConfigurationTable implements Rules {
|
||||
|
||||
this.rules = new ArrayList<Rule>();
|
||||
ResultSet set = getConnection().prepareStatement(sqlLoad).executeQuery();
|
||||
while(set.next()) {
|
||||
while (set.next()) {
|
||||
String string = set.getString("rule");
|
||||
Rule rule = Rule.load(string);
|
||||
if(rule != null) {
|
||||
if (rule != null) {
|
||||
this.rules.add(rule);
|
||||
} else {
|
||||
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '"+string+"' from the database. Improper format used.");
|
||||
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from the database. Improper format used.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -22,9 +22,7 @@ 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.config.providers.Rules;
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
import net.h31ix.anticheat.util.rule.Rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -59,9 +57,9 @@ public class YamlEventsHolder extends ConfigurationFile implements Events {
|
||||
|
||||
// Convert levels list to Levels
|
||||
this.levels = new ArrayList<Level>();
|
||||
for(String string : levels.getValue()) {
|
||||
for (String string : levels.getValue()) {
|
||||
Level level = Level.load(string);
|
||||
if(level == null || level.getValue() < 0) {
|
||||
if (level == null || level.getValue() < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@ public class YamlLevelsHolder extends ConfigurationFile implements Levels {
|
||||
|
||||
@Override
|
||||
public void saveLevelsFromUsers(List<User> users) {
|
||||
for(User user : users) {
|
||||
for (User user : users) {
|
||||
saveLevelFromUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
private int getLevel(String name) {
|
||||
ConfigValue<Integer> level = new ConfigValue<Integer>(name, false);
|
||||
if(level.hasValue()) {
|
||||
if (level.hasValue()) {
|
||||
return level.getValue();
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
@@ -21,14 +21,10 @@ package net.h31ix.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.config.providers.Rules;
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
import net.h31ix.anticheat.util.rule.Rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class YamlRulesHolder extends ConfigurationFile implements Rules {
|
||||
@@ -53,19 +49,19 @@ public class YamlRulesHolder extends ConfigurationFile implements Rules {
|
||||
// Convert rules list to Rules
|
||||
this.rules = new ArrayList<Rule>();
|
||||
List<String> tempRules = rules.getValue();
|
||||
for(int i=0;i<tempRules.size();i++) {
|
||||
for (int i = 0; i < tempRules.size(); i++) {
|
||||
String string = tempRules.get(i);
|
||||
|
||||
if(string.equals("Check_SPIDER < 0 ? Player.KICK : null")) {
|
||||
if (string.equals("Check_SPIDER < 0 ? Player.KICK : null")) {
|
||||
// Default rule, won't ever run so we shouldn't load it; only used as example
|
||||
continue;
|
||||
}
|
||||
|
||||
Rule rule = Rule.load(string);
|
||||
if(rule != null) {
|
||||
if (rule != null) {
|
||||
this.rules.add(rule);
|
||||
} else {
|
||||
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '"+string+"' from config. Improper format used.");
|
||||
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from config. Improper format used.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,6 @@
|
||||
|
||||
package net.h31ix.anticheat.config.yaml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@@ -39,6 +29,15 @@ import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* An extension of {@link org.bukkit.configuration.file.YamlConfiguration} which preserves comments.
|
||||
* Note that this implementation is not synchronized.
|
||||
@@ -47,7 +46,7 @@ import org.yaml.snakeyaml.representer.Representer;
|
||||
*/
|
||||
public class CommentedConfiguration extends YamlConfiguration {
|
||||
private Map<Integer, String> comments = new HashMap<Integer, String>();
|
||||
|
||||
|
||||
private final DumperOptions yamlOptions = new DumperOptions();
|
||||
private final Representer yamlRepresenter = new YamlRepresenter();
|
||||
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
||||
@@ -66,11 +65,11 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
}
|
||||
|
||||
/** - CommentedConfiguration
|
||||
String header = parseHeader(contents);
|
||||
if (header.length() > 0) {
|
||||
options().header(header);
|
||||
}
|
||||
**/
|
||||
String header = parseHeader(contents);
|
||||
if (header.length() > 0) {
|
||||
options().header(header);
|
||||
}
|
||||
**/
|
||||
|
||||
if (input != null) {
|
||||
convertMapsToSections(input, this);
|
||||
@@ -80,14 +79,14 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
int i = 0;
|
||||
int blank = 0;
|
||||
String[] lines = contents.split("\n");
|
||||
while(i < lines.length) {
|
||||
if(lines[i].trim().equalsIgnoreCase("")) {
|
||||
while (i < lines.length) {
|
||||
if (lines[i].trim().equalsIgnoreCase("")) {
|
||||
i++;
|
||||
blank++;
|
||||
continue;
|
||||
}
|
||||
if(lines[i].contains(COMMENT_PREFIX)) {
|
||||
comments.put(i-blank, lines[i]);
|
||||
if (lines[i].contains(COMMENT_PREFIX)) {
|
||||
comments.put(i - blank, lines[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -112,7 +111,7 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
|
||||
String[] lines = dump.split("\n");
|
||||
ArrayDeque<String> queue = new ArrayDeque<String>();
|
||||
for(String string : lines) {
|
||||
for (String string : lines) {
|
||||
queue.add(string);
|
||||
}
|
||||
|
||||
@@ -148,7 +147,7 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommentedConfiguration}, loading from the given file.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Any errors loading the Configuration will be logged and then ignored.
|
||||
* If the specified input is not a valid config, a blank config will be returned.
|
||||
*
|
||||
@@ -167,7 +166,7 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file , ex);
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||
}
|
||||
|
||||
return config;
|
||||
@@ -175,7 +174,7 @@ public class CommentedConfiguration extends YamlConfiguration {
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommentedConfiguration}, loading from the given stream.
|
||||
* <p>
|
||||
* <p/>
|
||||
* Any errors loading the Configuration will be logged and then ignored.
|
||||
* If the specified input is not a valid config, a blank config will be returned.
|
||||
*
|
||||
|
||||
@@ -41,12 +41,12 @@ public class BlockListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.AUTOTOOL)) {
|
||||
CheckResult result = getBackend().checkAutoTool(player);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.AUTOTOOL);
|
||||
log(result.getMessage(), player, CheckType.AUTOTOOL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class BlockListener extends EventListener {
|
||||
getBackend().logBlockPlace(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class BlockListener extends EventListener {
|
||||
CheckResult result;
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_BREAK)) {
|
||||
result = getBackend().checkFastBreak(player, block);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_BREAK);
|
||||
noHack = false;
|
||||
@@ -84,7 +84,7 @@ public class BlockListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.NO_SWING)) {
|
||||
result = getBackend().checkSwing(player, block);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.NO_SWING);
|
||||
noHack = false;
|
||||
|
||||
@@ -33,7 +33,7 @@ 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) {
|
||||
@@ -48,10 +48,10 @@ public class EntityListener extends EventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) {
|
||||
@@ -67,10 +67,10 @@ public class EntityListener extends EventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||
if (event.getEntity() instanceof Player) {
|
||||
@@ -86,10 +86,10 @@ public class EntityListener extends EventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
boolean noHack = true;
|
||||
@@ -134,15 +134,15 @@ public class EntityListener extends EventListener {
|
||||
getBackend().logDamage(player, 1);
|
||||
if (getCheckManager().willCheck(player, CheckType.AUTOTOOL)) {
|
||||
CheckResult result = getBackend().checkAutoTool(player);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.AUTOTOOL);
|
||||
noHack = false;
|
||||
noHack = false;
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.FORCEFIELD)) {
|
||||
CheckResult result = getBackend().checkSprintDamage(player);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FORCEFIELD);
|
||||
noHack = false;
|
||||
@@ -150,7 +150,7 @@ public class EntityListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.NO_SWING)) {
|
||||
CheckResult result = getBackend().checkAnimation(player, event.getEntity());
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.NO_SWING);
|
||||
noHack = false;
|
||||
@@ -158,7 +158,7 @@ public class EntityListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.FORCEFIELD)) {
|
||||
CheckResult result = getBackend().checkSight(player, e.getEntity());
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FORCEFIELD);
|
||||
noHack = false;
|
||||
@@ -169,7 +169,7 @@ public class EntityListener extends EventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,16 @@
|
||||
|
||||
package net.h31ix.anticheat.event;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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>();
|
||||
@@ -39,7 +39,7 @@ public class EventListener implements Listener {
|
||||
|
||||
public static void log(String message, Player player, CheckType type) {
|
||||
User user = getUserManager().getUser(player.getName());
|
||||
if(user != null) { // npc
|
||||
if (user != null) { // npc
|
||||
logCheat(type, user);
|
||||
if (user.increaseLevel(type) && message != null) {
|
||||
AntiCheat.getManager().log(message);
|
||||
@@ -75,17 +75,17 @@ public class EventListener implements Listener {
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
DECREASE_LIST.put(user.getName(), x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
||||
public class InventoryListener extends EventListener {
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!event.isRightClick() && !event.isShiftClick() && event.getWhoClicked() instanceof Player) {
|
||||
@@ -49,13 +49,13 @@ public class InventoryListener extends EventListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if(event.getInventory().getType() != InventoryType.BEACON) {
|
||||
if (event.getInventory().getType() != InventoryType.BEACON) {
|
||||
getUserManager().getUser(event.getPlayer().getName()).setInventorySnapshot(event.getInventory().getContents());
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class InventoryListener extends EventListener {
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
User user = getUserManager().getUser(event.getPlayer().getName());
|
||||
if(user != null) {
|
||||
if (user != null) {
|
||||
user.removeInventorySnapshot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,11 +81,13 @@ public class PlayerListener extends EventListener {
|
||||
if (event.getEntity().getShooter() instanceof Player) {
|
||||
Player player = (Player) event.getEntity().getShooter();
|
||||
|
||||
if (event.getEntity() instanceof Arrow) { return; }
|
||||
if (event.getEntity() instanceof Arrow) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (getCheckManager().willCheck(player, CheckType.FAST_PROJECTILE)) {
|
||||
CheckResult result = getBackend().checkProjectile(player);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.FAST_PROJECTILE);
|
||||
}
|
||||
@@ -123,8 +125,7 @@ public class PlayerListener extends EventListener {
|
||||
@EventHandler
|
||||
public void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.FLY))
|
||||
{
|
||||
if (getCheckManager().willCheck(player, CheckType.FLY)) {
|
||||
if (getBackend().justVelocity(player) && getBackend().extendVelocityTime(player)) {
|
||||
event.setCancelled(!silentMode());
|
||||
return; // don't log it lol.
|
||||
@@ -143,7 +144,7 @@ public class PlayerListener extends EventListener {
|
||||
CheckResult result = getBackend().checkSpam(player, event.getMessage());
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
if(!result.getMessage().equals("")) {
|
||||
if (!result.getMessage().equals("")) {
|
||||
player.sendMessage(ChatColor.RED + result.getMessage());
|
||||
}
|
||||
getBackend().processChatSpammer(player);
|
||||
@@ -176,7 +177,7 @@ public class PlayerListener extends EventListener {
|
||||
@EventHandler
|
||||
public void onPlayerToggleSprint(PlayerToggleSprintEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if(!event.isSprinting()) {
|
||||
if (!event.isSprinting()) {
|
||||
getBackend().logEnterExit(player);
|
||||
}
|
||||
if (getCheckManager().willCheck(player, CheckType.SPRINT)) {
|
||||
@@ -219,7 +220,7 @@ public class PlayerListener extends EventListener {
|
||||
Player player = event.getPlayer();
|
||||
if (getCheckManager().willCheck(player, CheckType.ITEM_SPAM)) {
|
||||
CheckResult result = getBackend().checkFastDrop(player);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
event.setCancelled(!silentMode());
|
||||
log(result.getMessage(), player, CheckType.ITEM_SPAM);
|
||||
}
|
||||
@@ -285,7 +286,7 @@ public class PlayerListener extends EventListener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if(getCheckManager().checkInWorld(player) && !getCheckManager().isOpExempt(player)) {
|
||||
if (getCheckManager().checkInWorld(player) && !getCheckManager().isOpExempt(player)) {
|
||||
final Location from = event.getFrom();
|
||||
final Location to = event.getTo();
|
||||
|
||||
@@ -298,9 +299,9 @@ public class PlayerListener extends EventListener {
|
||||
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPEED)) {
|
||||
CheckResult result = getBackend().checkFreeze(player, from.getY(), to.getY());
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
if(!silentMode()) {
|
||||
if (!silentMode()) {
|
||||
player.kickPlayer("Freezing client");
|
||||
}
|
||||
}
|
||||
@@ -314,7 +315,7 @@ public class PlayerListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !player.isFlying()) {
|
||||
CheckResult result = getBackend().checkFlight(player, distance);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
@@ -339,7 +340,7 @@ public class PlayerListener extends EventListener {
|
||||
}
|
||||
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 (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.
|
||||
@@ -355,7 +356,7 @@ public class PlayerListener extends EventListener {
|
||||
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 (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
@@ -385,7 +386,7 @@ public class PlayerListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.WATER_WALK)) {
|
||||
CheckResult result = getBackend().checkWaterWalk(player, x, y, z);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
player.teleport(user.getGoodLocation(player.getLocation().add(0, -1, 0)));
|
||||
}
|
||||
@@ -395,7 +396,7 @@ public class PlayerListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SNEAK)) {
|
||||
CheckResult result = getBackend().checkSneak(player, x, z);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
player.setSneaking(false);
|
||||
@@ -406,7 +407,7 @@ public class PlayerListener extends EventListener {
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.SPIDER)) {
|
||||
CheckResult result = getBackend().checkSpider(player, y);
|
||||
if(result.failed()) {
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
@@ -430,7 +431,7 @@ public class PlayerListener extends EventListener {
|
||||
final Location from = event.getFrom();
|
||||
final Location to = event.getTo();
|
||||
|
||||
if(!user.checkTo(to.getX(), to.getY(), to.getZ())) {
|
||||
if (!user.checkTo(to.getX(), to.getY(), to.getZ())) {
|
||||
// The to value has been modified by another plugin
|
||||
return;
|
||||
}
|
||||
@@ -439,7 +440,7 @@ public class PlayerListener extends EventListener {
|
||||
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 (!log.equals("")) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
|
||||
@@ -26,32 +26,32 @@ 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) {
|
||||
if (event.getVehicle().getPassenger() != null && event.getVehicle().getPassenger() instanceof Player) {
|
||||
getBackend().logEnterExit((Player) event.getVehicle().getPassenger());
|
||||
}
|
||||
|
||||
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,14 @@
|
||||
|
||||
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;
|
||||
@@ -29,14 +37,6 @@ import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* The internal hub for all managers.
|
||||
*/
|
||||
@@ -54,7 +54,7 @@ public class AnticheatManager {
|
||||
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!!!!!
|
||||
@@ -77,11 +77,11 @@ public class AnticheatManager {
|
||||
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(ChatColor.RED + message);
|
||||
@@ -94,21 +94,23 @@ public class AnticheatManager {
|
||||
}
|
||||
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; }
|
||||
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;
|
||||
@@ -117,66 +119,66 @@ public class AnticheatManager {
|
||||
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) {
|
||||
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) {
|
||||
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()) {
|
||||
if (configuration.getConfig().enterprise.getValue()) {
|
||||
configuration.getEnterprise().database.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,12 @@
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.files.Lang;
|
||||
import net.h31ix.anticheat.config.files.Magic;
|
||||
import net.h31ix.anticheat.util.CheckResult;
|
||||
import net.h31ix.anticheat.util.CheckResult.Result;
|
||||
import net.h31ix.anticheat.util.Distance;
|
||||
import net.h31ix.anticheat.config.files.Magic;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -39,11 +33,12 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Backend {
|
||||
private List<String> isInWater = new ArrayList<String>();
|
||||
private List<String> isInWaterCache = new ArrayList<String>();
|
||||
@@ -183,8 +178,8 @@ public class Backend {
|
||||
float f = (float) ticks / 20.0F;
|
||||
f = (f * f + f * 2.0F) / 3.0F;
|
||||
f = f > 1.0F ? 1.0F : f;
|
||||
if(Math.abs(force - f) > magic.BOW_ERROR) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" fired their bow too fast (actual force="+force+", calculated force="+f+")");
|
||||
if (Math.abs(force - f) > magic.BOW_ERROR) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " fired their bow too fast (actual force=" + force + ", calculated force=" + f + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -199,8 +194,8 @@ public class Backend {
|
||||
long time = System.currentTimeMillis() - projectileTime.get(player.getName());
|
||||
projectileTime.remove(player.getName());
|
||||
projectilesShot.remove(player.getName());
|
||||
if(time < magic.PROJECTILE_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" wound up a bow too fast (actual time="+time+", min time="+magic.PROJECTILE_TIME_MIN+")");
|
||||
if (time < magic.PROJECTILE_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " wound up a bow too fast (actual time=" + time + ", min time=" + magic.PROJECTILE_TIME_MIN + ")");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -215,8 +210,8 @@ public class Backend {
|
||||
long time = System.currentTimeMillis() - blockTime.get(player.getName());
|
||||
blockTime.remove(player.getName());
|
||||
blocksDropped.remove(player.getName());
|
||||
if(time < magic.DROP_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" dropped an item too fast (actual time="+time+", min time="+magic.DROP_TIME_MIN+")");
|
||||
if (time < magic.DROP_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " dropped an item too fast (actual time=" + time + ", min time=" + magic.DROP_TIME_MIN + ")");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -226,14 +221,14 @@ public class Backend {
|
||||
if (isInstantBreakExempt(player)) {
|
||||
return new CheckResult(Result.PASSED);
|
||||
} else {
|
||||
String string = player.getName()+" reached too far for a block";
|
||||
String string = player.getName() + " reached too far for a block";
|
||||
double distance =
|
||||
player.getGameMode() == GameMode.CREATIVE ? magic.BLOCK_MAX_DISTANCE_CREATIVE
|
||||
: player.getLocation().getDirection().getY() > 0.9 ? magic.BLOCK_MAX_DISTANCE_CREATIVE
|
||||
: magic.BLOCK_MAX_DISTANCE;
|
||||
: player.getLocation().getDirection().getY() > 0.9 ? magic.BLOCK_MAX_DISTANCE_CREATIVE
|
||||
: magic.BLOCK_MAX_DISTANCE;
|
||||
double i = x >= distance ? x : y > distance ? y : z > distance ? z : -1;
|
||||
if(i != -1) {
|
||||
return new CheckResult(Result.FAILED, string+" (distance="+i+", max="+magic.BLOCK_MAX_DISTANCE+")");
|
||||
if (i != -1) {
|
||||
return new CheckResult(Result.FAILED, string + " (distance=" + i + ", max=" + magic.BLOCK_MAX_DISTANCE + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -241,26 +236,26 @@ public class Backend {
|
||||
}
|
||||
|
||||
public CheckResult checkLongReachDamage(Player player, double x, double y, double z) {
|
||||
String string = player.getName()+" reached too far for an entity";
|
||||
String string = player.getName() + " reached too far for an entity";
|
||||
double i = x >= magic.ENTITY_MAX_DISTANCE ? x : y > magic.ENTITY_MAX_DISTANCE ? y : z > magic.ENTITY_MAX_DISTANCE ? z : -1;
|
||||
if(i != -1) {
|
||||
return new CheckResult(Result.FAILED, string+" (distance="+i+", max="+magic.ENTITY_MAX_DISTANCE+")");
|
||||
if (i != -1) {
|
||||
return new CheckResult(Result.FAILED, string + " (distance=" + i + ", max=" + magic.ENTITY_MAX_DISTANCE + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public CheckResult checkSpider(Player player, double y) {
|
||||
if(y <= magic.LADDER_Y_MAX && y >= magic.LADDER_Y_MIN && !Utilities.isClimbableBlock(player.getLocation().getBlock())) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to climb a non-ladder ("+player.getLocation().getBlock().getType()+")");
|
||||
if (y <= magic.LADDER_Y_MAX && y >= magic.LADDER_Y_MIN && !Utilities.isClimbableBlock(player.getLocation().getBlock())) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to climb a non-ladder (" + player.getLocation().getBlock().getType() + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public CheckResult checkYSpeed(Player player, double y) {
|
||||
if(!isMovingExempt(player) && !player.isInsideVehicle() && !player.isSleeping() && y > magic.Y_SPEED_MAX && !isDoing(player, velocitized, magic.VELOCITY_TIME) && !player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+"'s y speed was too high (speed="+y+", max="+magic.Y_SPEED_MAX+")");
|
||||
if (!isMovingExempt(player) && !player.isInsideVehicle() && !player.isSleeping() && y > magic.Y_SPEED_MAX && !isDoing(player, velocitized, magic.VELOCITY_TIME) && !player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + "'s y speed was too high (speed=" + y + ", max=" + magic.Y_SPEED_MAX + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -279,7 +274,7 @@ public class Backend {
|
||||
int i = nofallViolation.get(name);
|
||||
if (i >= magic.NOFALL_LIMIT) {
|
||||
nofallViolation.put(player.getName(), 1);
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to avoid fall damage (fall distance = 0 "+i+" times in a row, max="+magic.NOFALL_LIMIT+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to avoid fall damage (fall distance = 0 " + i + " times in a row, max=" + magic.NOFALL_LIMIT + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -300,8 +295,8 @@ public class Backend {
|
||||
reason = "on soulsand while sprinting ";
|
||||
max = magic.XZ_SPEED_MAX_SOULSAND_SPRINT;
|
||||
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
|
||||
reason = "on soulsand with speed potion ";
|
||||
max = magic.XZ_SPEED_MAX_SOULSAND_POTION;
|
||||
reason = "on soulsand with speed potion ";
|
||||
max = magic.XZ_SPEED_MAX_SOULSAND_POTION;
|
||||
} else {
|
||||
reason = "on soulsand ";
|
||||
max = magic.XZ_SPEED_MAX_SOULSAND;
|
||||
@@ -322,8 +317,8 @@ public class Backend {
|
||||
|
||||
if (x > max || z > max) {
|
||||
int num = this.increment(player, speedViolation, magic.SPEED_MAX);
|
||||
if(num >= magic.SPEED_MAX) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+"'s speed was too high "+reason+num+" times in a row (max="+magic.SPEED_MAX+", speed="+(x > z ? x : z)+", max speed="+max+")");
|
||||
if (num >= magic.SPEED_MAX) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + "'s speed was too high " + reason + num + " times in a row (max=" + magic.SPEED_MAX + ", speed=" + (x > z ? x : z) + ", max speed=" + max + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -339,8 +334,8 @@ public class Backend {
|
||||
public CheckResult checkSneak(Player player, double x, double z) {
|
||||
if (player.isSneaking() && !player.isFlying() && !isMovingExempt(player) && !player.isInsideVehicle()) {
|
||||
double i = x > magic.XZ_SPEED_MAX_SNEAK ? x : z > magic.XZ_SPEED_MAX_SNEAK ? z : -1;
|
||||
if(i != -1) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" was sneaking too fast (speed="+i+", max="+magic.XZ_SPEED_MAX_SNEAK+")");
|
||||
if (i != -1) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " was sneaking too fast (speed=" + i + ", max=" + magic.XZ_SPEED_MAX_SNEAK + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -352,7 +347,7 @@ public class Backend {
|
||||
public CheckResult checkSprintHungry(PlayerToggleSprintEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.isSprinting() && player.getGameMode() != GameMode.CREATIVE && player.getFoodLevel() <= magic.SPRINT_FOOD_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" sprinted while hungry (food="+player.getFoodLevel()+", min="+magic.SPRINT_FOOD_MIN+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " sprinted while hungry (food=" + player.getFoodLevel() + ", min=" + magic.SPRINT_FOOD_MIN + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -378,7 +373,8 @@ public class Backend {
|
||||
b = x > magic.XZ_SPEED_MAX_WATER || z > magic.XZ_SPEED_MAX_WATER;
|
||||
} else {
|
||||
b = x > magic.XZ_SPEED_MAX_WATER_SPRINT || z > magic.XZ_SPEED_MAX_WATER_SPRINT;
|
||||
} if (!b && !Utilities.isFullyInWater(player.getLocation()) && Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D && !block.getType().equals(Material.WATER_LILY)) {
|
||||
}
|
||||
if (!b && !Utilities.isFullyInWater(player.getLocation()) && Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D && !block.getType().equals(Material.WATER_LILY)) {
|
||||
b = true;
|
||||
}
|
||||
if (b) {
|
||||
@@ -386,7 +382,7 @@ public class Backend {
|
||||
int v = waterSpeedViolation.get(player.getName());
|
||||
if (v >= magic.WATER_SPEED_VIOLATION_MAX) {
|
||||
waterSpeedViolation.put(player.getName(), 0);
|
||||
return new CheckResult(Result.FAILED, player.getName()+" stood on water "+v+" times (can't stand on "+block.getType()+" or "+block.getRelative(BlockFace.DOWN).getType()+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
|
||||
} else {
|
||||
waterSpeedViolation.put(player.getName(), v + 1);
|
||||
}
|
||||
@@ -411,7 +407,7 @@ public class Backend {
|
||||
} else {
|
||||
waterAscensionViolation.put(player.getName(), v + 1);
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName()+" stood on water "+v+" times (can't stand on "+block.getType()+" or "+block.getRelative(BlockFace.DOWN).getType()+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
|
||||
} else {
|
||||
waterAscensionViolation.put(player.getName(), 1);
|
||||
}
|
||||
@@ -434,7 +430,7 @@ public class Backend {
|
||||
for (int i = 0; i < (Math.round(distance.getYDifference())) + 1; i++) {
|
||||
Block block = new Location(player.getWorld(), player.getLocation().getX(), to + i, player.getLocation().getZ()).getBlock();
|
||||
if (block.getTypeId() != 0 && block.getType().isSolid()) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to move through a solid block", (int)from + 3);
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to move through a solid block", (int) from + 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +462,7 @@ public class Backend {
|
||||
player.teleport(g);
|
||||
}
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to fly on y-axis "+yAxisViolations.get(name)+" times (max ="+magic.Y_MAXVIOLATIONS+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to fly on y-axis " + yAxisViolations.get(name) + " times (max =" + magic.Y_MAXVIOLATIONS + ")");
|
||||
} else {
|
||||
if (yAxisViolations.get(name) > magic.Y_MAXVIOLATIONS && (System.currentTimeMillis() - yAxisLastViolation.get(name)) > magic.Y_MAXVIOTIME) {
|
||||
yAxisViolations.put(name, 0);
|
||||
@@ -485,7 +481,7 @@ public class Backend {
|
||||
player.teleport(g);
|
||||
}
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to fly on y-axis in "+i+" ms (min ="+magic.Y_TIME+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + magic.Y_TIME + ")");
|
||||
} else {
|
||||
if ((y1 - lastYcoord.get(name)) > magic.Y_MAXDIFF + 1 || (System.currentTimeMillis() - lastYtime.get(name)) > magic.Y_TIME) {
|
||||
lastYtime.put(name, System.currentTimeMillis());
|
||||
@@ -511,8 +507,8 @@ public class Backend {
|
||||
if (step == magic.TIMER_STEP_CHECK) {
|
||||
long time = System.currentTimeMillis() - stepTime.get(name);
|
||||
steps.put(name, 0);
|
||||
if(time < magic.TIMER_TIMEMIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to alter their timer, took "+step+" steps in "+time+" ms (min = "+magic.TIMER_TIMEMIN+" ms)");
|
||||
if (time < magic.TIMER_TIMEMIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to alter their timer, took " + step + " steps in " + time + " ms (min = " + magic.TIMER_TIMEMIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -562,7 +558,7 @@ public class Backend {
|
||||
final String name = player.getName();
|
||||
final double y1 = distance.fromY();
|
||||
final double y2 = distance.toY();
|
||||
if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities.cantStandAtExp(player.getLocation()) && Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), new Material [] {Material.FENCE, Material.FENCE_GATE, Material.COBBLE_WALL})) {
|
||||
if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities.cantStandAtExp(player.getLocation()) && Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), new Material[]{Material.FENCE, Material.FENCE_GATE, Material.COBBLE_WALL})) {
|
||||
|
||||
if (!blocksOverFlight.containsKey(name)) {
|
||||
blocksOverFlight.put(name, 0D);
|
||||
@@ -575,7 +571,7 @@ public class Backend {
|
||||
}
|
||||
|
||||
if (blocksOverFlight.get(name) > magic.FLIGHT_BLOCK_LIMIT && (y1 <= y2)) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" flew over "+blocksOverFlight.get(name)+" blocks (max="+magic.FLIGHT_BLOCK_LIMIT+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " flew over " + blocksOverFlight.get(name) + " blocks (max=" + magic.FLIGHT_BLOCK_LIMIT + ")");
|
||||
}
|
||||
} else {
|
||||
blocksOverFlight.put(name, 0D);
|
||||
@@ -607,7 +603,7 @@ public class Backend {
|
||||
if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid() && !block.getRelative(BlockFace.EAST).isLiquid() && !block.getRelative(BlockFace.WEST).isLiquid()) {
|
||||
increment(player, ascensionCount, max);
|
||||
if (ascensionCount.get(name) >= max) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" ascended "+ascensionCount.get(name)+" times in a row (max = "+max+string+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " ascended " + ascensionCount.get(name) + " times in a row (max = " + max + string + ")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -624,7 +620,7 @@ public class Backend {
|
||||
if (blockPunches.get(name) != null && player.getGameMode() != GameMode.CREATIVE) {
|
||||
int i = blockPunches.get(name);
|
||||
if (i < magic.BLOCK_PUNCH_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to break a block of "+block.getType()+" after only "+i+" punches (min="+magic.BLOCK_PUNCH_MIN+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to break a block of " + block.getType() + " after only " + i + " punches (min=" + magic.BLOCK_PUNCH_MIN + ")");
|
||||
} else {
|
||||
blockPunches.put(name, 0); // it should reset after EACH block break.
|
||||
}
|
||||
@@ -652,7 +648,7 @@ public class Backend {
|
||||
if (!silentMode()) {
|
||||
player.sendMessage(ChatColor.RED + "[AntiCheat] Fastbreaking detected. Please wait 10 seconds before breaking blocks.");
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName()+" broke blocks too fast "+i+" times in a row (max="+violations+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " broke blocks too fast " + i + " times in a row (max=" + violations + ")");
|
||||
} else if (fastBreakViolation.get(name) > 0 && math > magic.FASTBREAK_MAXVIOLATIONTIME) {
|
||||
fastBreakViolation.put(name, 0);
|
||||
}
|
||||
@@ -666,7 +662,7 @@ public class Backend {
|
||||
}
|
||||
} else {
|
||||
Long math = System.currentTimeMillis() - lastBlockBroken.get(name);
|
||||
if((math != 0L && timemax != 0L)) {
|
||||
if ((math != 0L && timemax != 0L)) {
|
||||
if (math < timemax) {
|
||||
if (fastBreakViolation.containsKey(name) && fastBreakViolation.get(name) > 0) {
|
||||
fastBreakViolation.put(name, fastBreakViolation.get(name) + 1);
|
||||
@@ -679,7 +675,7 @@ public class Backend {
|
||||
int i = fastBreaks.get(name);
|
||||
fastBreaks.put(name, 0);
|
||||
fastBreakViolation.put(name, fastBreakViolation.get(name) + 1);
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to break "+i+" blocks in "+math+" ms (max="+magic.FASTBREAK_LIMIT+" in "+timemax+" ms)");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to break " + i + " blocks in " + math + " ms (max=" + magic.FASTBREAK_LIMIT + " in " + timemax + " ms)");
|
||||
} else if (fastBreaks.get(name) >= magic.FASTBREAK_LIMIT || fastBreakViolation.get(name) > 0) {
|
||||
if (!blockBreakHolder.containsKey(name) || !blockBreakHolder.get(name)) {
|
||||
blockBreakHolder.put(name, true);
|
||||
@@ -716,7 +712,7 @@ public class Backend {
|
||||
if (!silentMode()) {
|
||||
player.sendMessage(ChatColor.RED + "[AntiCheat] Fastplacing detected. Please wait 10 seconds before placing blocks.");
|
||||
}
|
||||
return new CheckResult(Result.FAILED, player.getName()+" placed blocks too fast "+fastBreakViolation.get(name)+" times in a row (max="+violations+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " placed blocks too fast " + fastBreakViolation.get(name) + " times in a row (max=" + violations + ")");
|
||||
} else if (lastBlockPlaced.get(name) > 0 && math > magic.FASTPLACE_MAXVIOLATIONTIME) {
|
||||
AntiCheat.debugLog("Reset facePlaceViolation for " + name);
|
||||
fastPlaceViolation.put(name, 0);
|
||||
@@ -730,7 +726,7 @@ public class Backend {
|
||||
lastBlockPlaceTime.put(name, (time - last));
|
||||
lastBlockPlaced.put(name, time);
|
||||
fastPlaceViolation.put(name, fastPlaceViolation.get(name) + 1);
|
||||
return new CheckResult(Result.FAILED, player.getName()+" tried to place a block "+thisTime+" ms after the last one (min="+magic.FASTPLACE_TIMEMIN+" ms)");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " tried to place a block " + thisTime + " ms after the last one (min=" + magic.FASTPLACE_TIMEMIN + " ms)");
|
||||
}
|
||||
lastBlockPlaceTime.put(name, (time - last));
|
||||
}
|
||||
@@ -753,18 +749,18 @@ public class Backend {
|
||||
public CheckResult checkSpam(Player player, String msg) {
|
||||
String name = player.getName();
|
||||
User user = manager.getUserManager().getUser(name);
|
||||
if(user.getLastMessageTime() != -1) {
|
||||
for(int i=0;i<2;i++) {
|
||||
if (user.getLastMessageTime() != -1) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
String m = user.getMessage(i);
|
||||
if(m == null) {
|
||||
if (m == null) {
|
||||
break;
|
||||
}
|
||||
Long l = user.getMessageTime(i);
|
||||
|
||||
if(System.currentTimeMillis() - l > magic.CHAT_REPEAT_MIN * 100) {
|
||||
if (System.currentTimeMillis() - l > magic.CHAT_REPEAT_MIN * 100) {
|
||||
user.clearMessages();
|
||||
break;
|
||||
} else if((m.equalsIgnoreCase(msg) && i == 1) || System.currentTimeMillis() - user.getLastMessageTime() < magic.CHAT_MIN * 2) {
|
||||
} else if ((m.equalsIgnoreCase(msg) && i == 1) || System.currentTimeMillis() - user.getLastMessageTime() < magic.CHAT_MIN * 2) {
|
||||
return new CheckResult(Result.FAILED, lang.spamWarning.getValue());
|
||||
}
|
||||
}
|
||||
@@ -788,8 +784,8 @@ public class Backend {
|
||||
} else if (clicks == magic.INVENTORY_CHECK) {
|
||||
long time = System.currentTimeMillis() - inventoryTime.get(name);
|
||||
inventoryClicks.put(name, 0);
|
||||
if(time < magic.INVENTORY_TIMEMIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" clicked inventory slots "+clicks+" times in "+time+" ms (max="+magic.INVENTORY_CHECK+" in "+magic.INVENTORY_TIMEMIN+" ms)");
|
||||
if (time < magic.INVENTORY_TIMEMIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " clicked inventory slots " + clicks + " times in " + time + " ms (max=" + magic.INVENTORY_CHECK + " in " + magic.INVENTORY_TIMEMIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -797,23 +793,23 @@ public class Backend {
|
||||
|
||||
public CheckResult checkAutoTool(Player player) {
|
||||
if (itemInHand.containsKey(player.getName()) && itemInHand.get(player.getName()) != player.getItemInHand().getType()) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" switched tools too fast (had "+itemInHand.get(player.getName())+", has "+player.getItemInHand().getType()+")");
|
||||
return new CheckResult(Result.FAILED, player.getName() + " switched tools too fast (had " + itemInHand.get(player.getName()) + ", has " + player.getItemInHand().getType() + ")");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public CheckResult checkSprintDamage(Player player) {
|
||||
if(isDoing(player, sprinted, magic.SPRINT_MIN)) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" sprinted and damaged an entity too fast (min sprint="+magic.SPRINT_MIN+" ms)");
|
||||
if (isDoing(player, sprinted, magic.SPRINT_MIN)) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " sprinted and damaged an entity too fast (min sprint=" + magic.SPRINT_MIN + " ms)");
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
}
|
||||
|
||||
public CheckResult checkAnimation(Player player, Entity e) {
|
||||
if(!justAnimated(player)) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" didn't animate before damaging a "+e.getType());
|
||||
if (!justAnimated(player)) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " didn't animate before damaging a " + e.getType());
|
||||
} else {
|
||||
return PASS;
|
||||
}
|
||||
@@ -824,8 +820,8 @@ public class Backend {
|
||||
{
|
||||
long l = lastHeal.get(player.getName());
|
||||
lastHeal.remove(player.getName());
|
||||
if((System.currentTimeMillis() - l) < magic.HEAL_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" healed too quickly (time="+(System.currentTimeMillis() - l)+" ms, min="+magic.HEAL_TIME_MIN+" ms)");
|
||||
if ((System.currentTimeMillis() - l) < magic.HEAL_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " healed too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + magic.HEAL_TIME_MIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -836,8 +832,8 @@ public class Backend {
|
||||
{
|
||||
long l = startEat.get(player.getName());
|
||||
startEat.remove(player.getName());
|
||||
if((System.currentTimeMillis() - l) < magic.EAT_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName()+" ate too quickly (time="+(System.currentTimeMillis() - l)+" ms, min="+magic.EAT_TIME_MIN+" ms)");
|
||||
if ((System.currentTimeMillis() - l) < magic.EAT_TIME_MIN) {
|
||||
return new CheckResult(Result.FAILED, player.getName() + " ate too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + magic.EAT_TIME_MIN + " ms)");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
@@ -861,7 +857,9 @@ public class Backend {
|
||||
|
||||
public boolean isHoveringOverWaterAfterViolation(Player player) {
|
||||
if (waterSpeedViolation.containsKey(player.getName())) {
|
||||
if (waterSpeedViolation.get(player.getName()) >= magic.WATER_SPEED_VIOLATION_MAX && Utilities.isHoveringOverWater(player.getLocation())) { return true; }
|
||||
if (waterSpeedViolation.get(player.getName()) >= magic.WATER_SPEED_VIOLATION_MAX && Utilities.isHoveringOverWater(player.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1026,7 +1024,7 @@ public class Backend {
|
||||
}
|
||||
|
||||
public void processChatSpammer(Player player) {
|
||||
if(chatLevel.get(player.getName()) != null && chatLevel.get(player.getName()) >= magic.CHAT_KICK_LEVEL) {
|
||||
if (chatLevel.get(player.getName()) != null && chatLevel.get(player.getName()) >= magic.CHAT_KICK_LEVEL) {
|
||||
if (player != null && player.isOnline()) {
|
||||
String name = player.getName();
|
||||
int kick;
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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>
|
||||
* <p/>
|
||||
* The manager that AntiCheat will check with to see if it should watch certain checks and certain players.
|
||||
*/
|
||||
|
||||
@@ -85,7 +85,7 @@ public class CheckManager {
|
||||
* Exempt a player from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
* @param type The check
|
||||
*/
|
||||
public void exemptPlayer(Player player, CheckType type) {
|
||||
if (!isExempt(player, type)) {
|
||||
@@ -102,7 +102,7 @@ public class CheckManager {
|
||||
* Unexempt a player from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
* @param type The check
|
||||
*/
|
||||
public void unexemptPlayer(Player player, CheckType type) {
|
||||
if (isExempt(player, type)) {
|
||||
@@ -115,7 +115,7 @@ public class CheckManager {
|
||||
* Determine whether a player is exempt from a check
|
||||
*
|
||||
* @param player The player
|
||||
* @param type The check
|
||||
* @param type The check
|
||||
*/
|
||||
public boolean isExempt(Player player, CheckType type) {
|
||||
return exemptList.containsKey(player.getName()) ? exemptList.get(player.getName()).contains(type) : false;
|
||||
@@ -144,29 +144,29 @@ public class CheckManager {
|
||||
* 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
|
||||
* @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);
|
||||
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
|
||||
* @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);
|
||||
&& checkInWorld(player)
|
||||
&& !isExempt(player, type)
|
||||
&& !type.checkPermission(player)
|
||||
&& !isOpExempt(player);
|
||||
AntiCheat.debugLog("Check " + type + (check ? " run " : " not run ") + "on " + player.getName());
|
||||
return check;
|
||||
}
|
||||
|
||||
@@ -18,16 +18,16 @@
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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>
|
||||
* <p/>
|
||||
* All the types of checks and their corresponding permission nodes.
|
||||
*/
|
||||
|
||||
@@ -57,7 +57,7 @@ public enum CheckType {
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
|
||||
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY),
|
||||
AUTOTOOL(Permission.CHECK_AUTOTOOL);
|
||||
|
||||
|
||||
private final Permission permission;
|
||||
private final Map<String, Integer> level = new HashMap<String, Integer>();
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class User {
|
||||
private final String name;
|
||||
@@ -40,8 +41,8 @@ public class User {
|
||||
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 String[] messages = new String[2];
|
||||
private Long[] messageTimes = new Long[2];
|
||||
|
||||
private boolean isWaitingOnLevelSync;
|
||||
private Timestamp levelSyncTimestamp;
|
||||
@@ -94,10 +95,10 @@ public class User {
|
||||
|
||||
public Level getNamedLevel() {
|
||||
List<Level> levels = config.getEvents().getLevels();
|
||||
for (int i=0;i<levels.size();i++) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
@@ -118,17 +119,17 @@ public class User {
|
||||
level++;
|
||||
|
||||
// Check levels
|
||||
for(Level l : getLevels()) {
|
||||
if(l.getValue() == level) {
|
||||
for (Level l : getLevels()) {
|
||||
if (l.getValue() == level) {
|
||||
AntiCheat.getManager().getUserManager().alert(this, l, type);
|
||||
if(l.getValue() == config.getEvents().getHighestLevel()) {
|
||||
if (l.getValue() == config.getEvents().getHighestLevel()) {
|
||||
level = l.getValue() - 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute rules
|
||||
for(Rule rule : config.getRules().getRules()) {
|
||||
for (Rule rule : config.getRules().getRules()) {
|
||||
rule.check(this, type);
|
||||
}
|
||||
return true;
|
||||
@@ -149,6 +150,7 @@ public class User {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -213,8 +215,8 @@ public class User {
|
||||
*/
|
||||
public void setInventorySnapshot(ItemStack[] is) {
|
||||
inventorySnapshot = new ArrayList<ItemStack>();
|
||||
for(int i=0;i<is.length;i++) {
|
||||
if(is[i] != null) {
|
||||
for (int i = 0; i < is.length; i++) {
|
||||
if (is[i] != null) {
|
||||
inventorySnapshot.add(is[i].clone());
|
||||
}
|
||||
}
|
||||
@@ -229,13 +231,14 @@ public class User {
|
||||
|
||||
/**
|
||||
* Restore the player's inventory with the current inventory snapshot
|
||||
*
|
||||
* @param inventory Player's inventory
|
||||
*/
|
||||
public void restoreInventory(Inventory inventory) {
|
||||
if(inventorySnapshot != null) {
|
||||
if (inventorySnapshot != null) {
|
||||
inventory.clear();
|
||||
for(ItemStack is : inventorySnapshot) {
|
||||
if(is != null) {
|
||||
for (ItemStack is : inventorySnapshot) {
|
||||
if (is != null) {
|
||||
inventory.addItem(is);
|
||||
}
|
||||
}
|
||||
@@ -244,25 +247,27 @@ public class User {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
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;
|
||||
return (int) x == toX && (int) y == toY && (int) z == toZ;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.Configuration;
|
||||
import net.h31ix.anticheat.util.Level;
|
||||
@@ -28,6 +25,9 @@ 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;
|
||||
@@ -49,6 +49,7 @@ public class UserManager {
|
||||
|
||||
/**
|
||||
* Get a user with the given name
|
||||
*
|
||||
* @param name Name
|
||||
* @return User with name
|
||||
*/
|
||||
@@ -119,7 +120,7 @@ public class UserManager {
|
||||
/**
|
||||
* Set a user's level
|
||||
*
|
||||
* @param name Name of the player
|
||||
* @param name Name of the player
|
||||
* @param level Level to set
|
||||
*/
|
||||
public void safeSetLevel(String name, int level) {
|
||||
@@ -131,6 +132,7 @@ public class UserManager {
|
||||
|
||||
/**
|
||||
* Reset a user
|
||||
*
|
||||
* @param name Name of the user
|
||||
*/
|
||||
public void safeReset(String name) {
|
||||
@@ -143,15 +145,15 @@ public class UserManager {
|
||||
/**
|
||||
* Fire an alert
|
||||
*
|
||||
* @param user The user to alert
|
||||
* @param user The user to alert
|
||||
* @param level The user's level
|
||||
* @param type The CheckType that triggered the alert
|
||||
* @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("")) {
|
||||
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);
|
||||
@@ -164,9 +166,10 @@ public class UserManager {
|
||||
|
||||
/**
|
||||
* Execute configuration actions for an alert
|
||||
* @param user The user
|
||||
*
|
||||
* @param user The user
|
||||
* @param actions The list of actions to execute
|
||||
* @param type The CheckType that triggered the alert
|
||||
* @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());
|
||||
@@ -175,12 +178,12 @@ public class UserManager {
|
||||
/**
|
||||
* 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 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
|
||||
* @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
|
||||
@@ -188,11 +191,11 @@ public class UserManager {
|
||||
@Override
|
||||
public void run() {
|
||||
final String name = user.getName();
|
||||
for(String event : actions) {
|
||||
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)) {
|
||||
for (String cmd : Utilities.getCommands(event)) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||
}
|
||||
} else if (event.equalsIgnoreCase("KICK")) {
|
||||
@@ -204,7 +207,7 @@ public class UserManager {
|
||||
} else if (event.equalsIgnoreCase("WARN")) {
|
||||
List<String> message = warning;
|
||||
for (String string : message) {
|
||||
if(!string.equals("")) {
|
||||
if (!string.equals("")) {
|
||||
user.getPlayer().sendMessage(RED + string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,31 +6,30 @@
|
||||
|
||||
package net.h31ix.anticheat.update;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import java.io.*;
|
||||
import java.lang.Runnable;
|
||||
import java.lang.Thread;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.XMLEvent;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
|
||||
* <p>
|
||||
* <p/>
|
||||
* <b>VERY, VERY IMPORTANT</b>: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed auto-updating.
|
||||
* <br>
|
||||
* It is a <b>BUKKIT POLICY</b> that you include a boolean value in your config that prevents the auto-updater from running <b>AT ALL</b>.
|
||||
* <br>
|
||||
* If you fail to include this option in your config, your plugin will be <b>REJECTED</b> when you attempt to submit it to dev.bukkit.org.
|
||||
* <p>
|
||||
* <p/>
|
||||
* An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater.
|
||||
* <br>
|
||||
* If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l
|
||||
@@ -38,8 +37,7 @@ import org.bukkit.plugin.Plugin;
|
||||
* @author H31IX
|
||||
*/
|
||||
|
||||
public class Updater
|
||||
{
|
||||
public class Updater {
|
||||
private Plugin plugin;
|
||||
private UpdateType type;
|
||||
private String versionTitle;
|
||||
@@ -53,7 +51,7 @@ public class Updater
|
||||
private File file; // The plugin's file
|
||||
private Thread thread; // Updater thread
|
||||
private static final String DBOUrl = "http://dev.bukkit.org/server-mods/"; // Slugs will be appended to this to get to the project's RSS feed
|
||||
private String [] noUpdateTag = {"-DEV","-PRE","-SNAPSHOT"}; // If the version number contains one of these, don't update.
|
||||
private String[] noUpdateTag = {"-DEV", "-PRE", "-SNAPSHOT"}; // If the version number contains one of these, don't update.
|
||||
private static final int BYTE_SIZE = 1024; // Used for downloading files
|
||||
private String updateFolder = YamlConfiguration.loadConfiguration(new File("bukkit.yml")).getString("settings.update-folder"); // The folder that downloads will be placed in
|
||||
private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process
|
||||
@@ -65,8 +63,7 @@ public class Updater
|
||||
/**
|
||||
* Gives the dev the result of the update process. Can be obtained by called getResult().
|
||||
*/
|
||||
public enum UpdateResult
|
||||
{
|
||||
public enum UpdateResult {
|
||||
/**
|
||||
* The updater found an update, and has readied it to be loaded the next time the server restarts/reloads.
|
||||
*/
|
||||
@@ -100,8 +97,7 @@ public class Updater
|
||||
/**
|
||||
* Allows the dev to specify the type of update that will be run.
|
||||
*/
|
||||
public enum UpdateType
|
||||
{
|
||||
public enum UpdateType {
|
||||
/**
|
||||
* Run a version check, and then if the file is out of date, download the newest version.
|
||||
*/
|
||||
@@ -119,30 +115,21 @@ public class Updater
|
||||
/**
|
||||
* Initialize the updater
|
||||
*
|
||||
* @param plugin
|
||||
* The plugin that is checking for an update.
|
||||
* @param slug
|
||||
* The dev.bukkit.org slug of the project (http://dev.bukkit.org/server-mods/SLUG_IS_HERE)
|
||||
* @param file
|
||||
* The file that the plugin is running from, get this by doing this.getFile() from within your main class.
|
||||
* @param type
|
||||
* Specify the type of update this will be. See {@link UpdateType}
|
||||
* @param announce
|
||||
* True if the program should announce the progress of new updates in console
|
||||
* @param plugin The plugin that is checking for an update.
|
||||
* @param slug The dev.bukkit.org slug of the project (http://dev.bukkit.org/server-mods/SLUG_IS_HERE)
|
||||
* @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class.
|
||||
* @param type Specify the type of update this will be. See {@link UpdateType}
|
||||
* @param announce True if the program should announce the progress of new updates in console
|
||||
*/
|
||||
public Updater(Plugin plugin, String slug, File file, UpdateType type, boolean announce)
|
||||
{
|
||||
public Updater(Plugin plugin, String slug, File file, UpdateType type, boolean announce) {
|
||||
this.plugin = plugin;
|
||||
this.type = type;
|
||||
this.announce = announce;
|
||||
this.file = file;
|
||||
try
|
||||
{
|
||||
try {
|
||||
// Obtain the results of the project's file feed
|
||||
url = new URL(DBOUrl + slug + "/files.rss");
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
} catch (MalformedURLException ex) {
|
||||
// Invalid slug
|
||||
plugin.getLogger().warning("The author of this plugin (" + plugin.getDescription().getAuthors().get(0) + ") has misconfigured their Auto Update system");
|
||||
plugin.getLogger().warning("The project slug given ('" + slug + "') is invalid. Please nag the author about this.");
|
||||
@@ -155,8 +142,7 @@ public class Updater
|
||||
/**
|
||||
* Get the result of the update process.
|
||||
*/
|
||||
public Updater.UpdateResult getResult()
|
||||
{
|
||||
public Updater.UpdateResult getResult() {
|
||||
waitForThread();
|
||||
return result;
|
||||
}
|
||||
@@ -164,8 +150,7 @@ public class Updater
|
||||
/**
|
||||
* Get the total bytes of the file (can only be used after running a version check or a normal run).
|
||||
*/
|
||||
public long getFileSize()
|
||||
{
|
||||
public long getFileSize() {
|
||||
waitForThread();
|
||||
return totalSize;
|
||||
}
|
||||
@@ -173,8 +158,7 @@ public class Updater
|
||||
/**
|
||||
* Get the version string latest file avaliable online.
|
||||
*/
|
||||
public String getLatestVersionString()
|
||||
{
|
||||
public String getLatestVersionString() {
|
||||
waitForThread();
|
||||
return versionTitle;
|
||||
}
|
||||
@@ -184,7 +168,7 @@ public class Updater
|
||||
* before alloowing anyone to check the result.
|
||||
*/
|
||||
public void waitForThread() {
|
||||
if(thread.isAlive()) {
|
||||
if (thread.isAlive()) {
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
@@ -196,16 +180,13 @@ public class Updater
|
||||
/**
|
||||
* Save an update from dev.bukkit.org into the server's update folder.
|
||||
*/
|
||||
private void saveFile(File folder, String file, String u)
|
||||
{
|
||||
if(!folder.exists())
|
||||
{
|
||||
private void saveFile(File folder, String file, String u) {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
BufferedInputStream in = null;
|
||||
FileOutputStream fout = null;
|
||||
try
|
||||
{
|
||||
try {
|
||||
// Download the file
|
||||
URL url = new URL(u);
|
||||
int fileLength = url.openConnection().getContentLength();
|
||||
@@ -214,55 +195,41 @@ public class Updater
|
||||
|
||||
byte[] data = new byte[BYTE_SIZE];
|
||||
int count;
|
||||
if(announce) plugin.getLogger().info("About to download a new update: " + versionTitle);
|
||||
if (announce) plugin.getLogger().info("About to download a new update: " + versionTitle);
|
||||
long downloaded = 0;
|
||||
while ((count = in.read(data, 0, BYTE_SIZE)) != -1)
|
||||
{
|
||||
while ((count = in.read(data, 0, BYTE_SIZE)) != -1) {
|
||||
downloaded += count;
|
||||
fout.write(data, 0, count);
|
||||
int percent = (int) (downloaded * 100 / fileLength);
|
||||
if(announce & (percent % 10 == 0))
|
||||
{
|
||||
if (announce & (percent % 10 == 0)) {
|
||||
plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
|
||||
}
|
||||
}
|
||||
//Just a quick check to make sure we didn't leave any files from last time...
|
||||
for(File xFile : new File("plugins/" + updateFolder).listFiles())
|
||||
{
|
||||
if(xFile.getName().endsWith(".zip"))
|
||||
{
|
||||
for (File xFile : new File("plugins/" + updateFolder).listFiles()) {
|
||||
if (xFile.getName().endsWith(".zip")) {
|
||||
xFile.delete();
|
||||
}
|
||||
}
|
||||
// Check to see if it's a zip file, if it is, unzip it.
|
||||
File dFile = new File(folder.getAbsolutePath() + "/" + file);
|
||||
if(dFile.getName().endsWith(".zip"))
|
||||
{
|
||||
if (dFile.getName().endsWith(".zip")) {
|
||||
// Unzip
|
||||
unzip(dFile.getCanonicalPath());
|
||||
}
|
||||
if(announce) plugin.getLogger().info("Finished updating.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (announce) plugin.getLogger().info("Finished updating.");
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful.");
|
||||
result = Updater.UpdateResult.FAIL_DOWNLOAD;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (in != null)
|
||||
{
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (fout != null)
|
||||
{
|
||||
if (fout != null) {
|
||||
fout.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,40 +237,32 @@ public class Updater
|
||||
/**
|
||||
* Part of Zip-File-Extractor, modified by H31IX for use with Bukkit
|
||||
*/
|
||||
private void unzip(String file)
|
||||
{
|
||||
try
|
||||
{
|
||||
private void unzip(String file) {
|
||||
try {
|
||||
File fSourceZip = new File(file);
|
||||
String zipPath = file.substring(0, file.length()-4);
|
||||
String zipPath = file.substring(0, file.length() - 4);
|
||||
ZipFile zipFile = new ZipFile(fSourceZip);
|
||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||
while(e.hasMoreElements())
|
||||
{
|
||||
ZipEntry entry = (ZipEntry)e.nextElement();
|
||||
File destinationFilePath = new File(zipPath,entry.getName());
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry entry = (ZipEntry) e.nextElement();
|
||||
File destinationFilePath = new File(zipPath, entry.getName());
|
||||
destinationFilePath.getParentFile().mkdirs();
|
||||
if(entry.isDirectory())
|
||||
{
|
||||
if (entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
|
||||
int b;
|
||||
byte buffer[] = new byte[BYTE_SIZE];
|
||||
FileOutputStream fos = new FileOutputStream(destinationFilePath);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos, BYTE_SIZE);
|
||||
while((b = bis.read(buffer, 0, BYTE_SIZE)) != -1)
|
||||
{
|
||||
while ((b = bis.read(buffer, 0, BYTE_SIZE)) != -1) {
|
||||
bos.write(buffer, 0, b);
|
||||
}
|
||||
bos.flush();
|
||||
bos.close();
|
||||
bis.close();
|
||||
String name = destinationFilePath.getName();
|
||||
if(name.endsWith(".jar") && pluginFile(name))
|
||||
{
|
||||
if (name.endsWith(".jar") && pluginFile(name)) {
|
||||
destinationFilePath.renameTo(new File("plugins/" + updateFolder + "/" + name));
|
||||
}
|
||||
}
|
||||
@@ -314,32 +273,25 @@ public class Updater
|
||||
zipFile.close();
|
||||
zipFile = null;
|
||||
// Move any plugin data folders that were included to the right place, Bukkit won't do this for us.
|
||||
for(File dFile : new File(zipPath).listFiles())
|
||||
{
|
||||
if(dFile.isDirectory())
|
||||
{
|
||||
if(pluginFile(dFile.getName()))
|
||||
{
|
||||
for (File dFile : new File(zipPath).listFiles()) {
|
||||
if (dFile.isDirectory()) {
|
||||
if (pluginFile(dFile.getName())) {
|
||||
File oFile = new File("plugins/" + dFile.getName()); // Get current dir
|
||||
File [] contents = oFile.listFiles(); // List of existing files in the current dir
|
||||
for(File cFile : dFile.listFiles()) // Loop through all the files in the new dir
|
||||
File[] contents = oFile.listFiles(); // List of existing files in the current dir
|
||||
for (File cFile : dFile.listFiles()) // Loop through all the files in the new dir
|
||||
{
|
||||
boolean found = false;
|
||||
for(File xFile : contents) // Loop through contents to see if it exists
|
||||
for (File xFile : contents) // Loop through contents to see if it exists
|
||||
{
|
||||
if(xFile.getName().equals(cFile.getName()))
|
||||
{
|
||||
if (xFile.getName().equals(cFile.getName())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
if (!found) {
|
||||
// Move the new file into the current dir
|
||||
cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// This file already exists, so we don't need it anymore.
|
||||
cFile.delete();
|
||||
}
|
||||
@@ -350,9 +302,7 @@ public class Updater
|
||||
}
|
||||
new File(zipPath).delete();
|
||||
fSourceZip.delete();
|
||||
}
|
||||
catch(IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful.");
|
||||
result = Updater.UpdateResult.FAIL_DOWNLOAD;
|
||||
@@ -363,12 +313,9 @@ public class Updater
|
||||
/**
|
||||
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
|
||||
*/
|
||||
public boolean pluginFile(String name)
|
||||
{
|
||||
for(File file : new File("plugins").listFiles())
|
||||
{
|
||||
if(file.getName().equals(name))
|
||||
{
|
||||
public boolean pluginFile(String name) {
|
||||
for (File file : new File("plugins").listFiles()) {
|
||||
if (file.getName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -378,11 +325,9 @@ public class Updater
|
||||
/**
|
||||
* Obtain the direct download file url from the file's page.
|
||||
*/
|
||||
private String getFile(String link)
|
||||
{
|
||||
private String getFile(String link) {
|
||||
String download = null;
|
||||
try
|
||||
{
|
||||
try {
|
||||
// Open a connection to the page
|
||||
URL url = new URL(link);
|
||||
URLConnection urlConn = url.openConnection();
|
||||
@@ -391,35 +336,28 @@ public class Updater
|
||||
|
||||
int counter = 0;
|
||||
String line;
|
||||
while((line = buff.readLine()) != null)
|
||||
{
|
||||
while ((line = buff.readLine()) != null) {
|
||||
counter++;
|
||||
// Search for the download link
|
||||
if(line.contains("<li class=\"user-action user-action-download\">"))
|
||||
{
|
||||
if (line.contains("<li class=\"user-action user-action-download\">")) {
|
||||
// Get the raw link
|
||||
download = line.split("<a href=\"")[1].split("\">Download</a>")[0];
|
||||
}
|
||||
// Search for size
|
||||
else if (line.contains("<dt>Size</dt>"))
|
||||
{
|
||||
sizeLine = counter+1;
|
||||
}
|
||||
else if(counter == sizeLine)
|
||||
{
|
||||
else if (line.contains("<dt>Size</dt>")) {
|
||||
sizeLine = counter + 1;
|
||||
} else if (counter == sizeLine) {
|
||||
String size = line.replaceAll("<dd>", "").replaceAll("</dd>", "");
|
||||
multiplier = size.contains("MiB") ? 1048576 : 1024;
|
||||
size = size.replace(" KiB", "").replace(" MiB", "");
|
||||
totalSize = (long)(Double.parseDouble(size)*multiplier);
|
||||
totalSize = (long) (Double.parseDouble(size) * multiplier);
|
||||
}
|
||||
}
|
||||
urlConn = null;
|
||||
inStream = null;
|
||||
buff.close();
|
||||
buff = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.getLogger().warning("The auto-updater tried to contact dev.bukkit.org, but was unsuccessful.");
|
||||
result = Updater.UpdateResult.FAIL_DBO;
|
||||
@@ -431,33 +369,24 @@ public class Updater
|
||||
/**
|
||||
* Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be updated
|
||||
*/
|
||||
private boolean versionCheck(String title)
|
||||
{
|
||||
if(type != UpdateType.NO_VERSION_CHECK)
|
||||
{
|
||||
private boolean versionCheck(String title) {
|
||||
if (type != UpdateType.NO_VERSION_CHECK) {
|
||||
String version = plugin.getDescription().getVersion();
|
||||
if(title.split(" v").length == 2)
|
||||
{
|
||||
if (title.split(" v").length == 2) {
|
||||
String remoteVersion = title.split(" v")[1].split(" ")[0]; // Get the newest file's version number
|
||||
int remVer = -1,curVer=0;
|
||||
try
|
||||
{
|
||||
int remVer = -1, curVer = 0;
|
||||
try {
|
||||
remVer = calVer(remoteVersion);
|
||||
curVer = calVer(version);
|
||||
} catch (NumberFormatException nfe) {
|
||||
remVer = -1;
|
||||
}
|
||||
catch(NumberFormatException nfe)
|
||||
{
|
||||
remVer=-1;
|
||||
}
|
||||
if(hasTag(version)||version.equalsIgnoreCase(remoteVersion)||curVer>=remVer)
|
||||
{
|
||||
if (hasTag(version) || version.equalsIgnoreCase(remoteVersion) || curVer >= remVer) {
|
||||
// We already have the latest version, or this build is tagged for no-update
|
||||
result = Updater.UpdateResult.NO_UPDATE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// The file's name did not contain the string 'vVersion'
|
||||
plugin.getLogger().warning("The author of this plugin (" + plugin.getDescription().getAuthors().get(0) + ") has misconfigured their Auto Update system");
|
||||
plugin.getLogger().warning("Files uploaded to BukkitDev should contain the version number, seperated from the name by a 'v', such as PluginName v1.0");
|
||||
@@ -468,19 +397,16 @@ public class Updater
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to calculate the version string as an Integer
|
||||
*/
|
||||
private Integer calVer(String s) throws NumberFormatException
|
||||
{
|
||||
if(s.contains("."))
|
||||
{
|
||||
private Integer calVer(String s) throws NumberFormatException {
|
||||
if (s.contains(".")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i <s.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
Character c = s.charAt(i);
|
||||
if (Character.isLetterOrDigit(c))
|
||||
{
|
||||
if (Character.isLetterOrDigit(c)) {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
@@ -488,15 +414,13 @@ public class Updater
|
||||
}
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate whether the version number is marked showing that it should not be updated by this program
|
||||
*/
|
||||
private boolean hasTag(String version)
|
||||
{
|
||||
for(String string : noUpdateTag)
|
||||
{
|
||||
if(version.contains(string))
|
||||
{
|
||||
private boolean hasTag(String version) {
|
||||
for (String string : noUpdateTag) {
|
||||
if (version.contains(string)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -506,10 +430,8 @@ public class Updater
|
||||
/**
|
||||
* Part of RSS Reader by Vogella, modified by H31IX for use with Bukkit
|
||||
*/
|
||||
private boolean readFeed()
|
||||
{
|
||||
try
|
||||
{
|
||||
private boolean readFeed() {
|
||||
try {
|
||||
// Set header values intial to the empty string
|
||||
String title = "";
|
||||
String link = "";
|
||||
@@ -517,32 +439,24 @@ public class Updater
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
// Setup a new eventReader
|
||||
InputStream in = read();
|
||||
if(in != null)
|
||||
{
|
||||
if (in != null) {
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
|
||||
// Read the XML document
|
||||
while (eventReader.hasNext())
|
||||
{
|
||||
while (eventReader.hasNext()) {
|
||||
XMLEvent event = eventReader.nextEvent();
|
||||
if (event.isStartElement())
|
||||
{
|
||||
if (event.asStartElement().getName().getLocalPart().equals(TITLE))
|
||||
{
|
||||
if (event.isStartElement()) {
|
||||
if (event.asStartElement().getName().getLocalPart().equals(TITLE)) {
|
||||
event = eventReader.nextEvent();
|
||||
title = event.asCharacters().getData();
|
||||
continue;
|
||||
}
|
||||
if (event.asStartElement().getName().getLocalPart().equals(LINK))
|
||||
{
|
||||
if (event.asStartElement().getName().getLocalPart().equals(LINK)) {
|
||||
event = eventReader.nextEvent();
|
||||
link = event.asCharacters().getData();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (event.isEndElement())
|
||||
{
|
||||
if (event.asEndElement().getName().getLocalPart().equals(ITEM))
|
||||
{
|
||||
} else if (event.isEndElement()) {
|
||||
if (event.asEndElement().getName().getLocalPart().equals(ITEM)) {
|
||||
// Store the title and link of the first entry we get - the first file on the list is all we need
|
||||
versionTitle = title;
|
||||
versionLink = link;
|
||||
@@ -552,14 +466,10 @@ public class Updater
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (XMLStreamException e)
|
||||
{
|
||||
} catch (XMLStreamException e) {
|
||||
plugin.getLogger().warning("Could not reach dev.bukkit.org for update checking. Is it offline?");
|
||||
return false;
|
||||
}
|
||||
@@ -568,14 +478,10 @@ public class Updater
|
||||
/**
|
||||
* Open the RSS feed
|
||||
*/
|
||||
private InputStream read()
|
||||
{
|
||||
try
|
||||
{
|
||||
private InputStream read() {
|
||||
try {
|
||||
return url.openStream();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("Could not reach BukkitDev file stream for update checking. Is dev.bukkit.org offline?");
|
||||
return null;
|
||||
}
|
||||
@@ -584,27 +490,20 @@ public class Updater
|
||||
private class UpdateRunnable implements Runnable {
|
||||
|
||||
public void run() {
|
||||
if(url != null)
|
||||
{
|
||||
if (url != null) {
|
||||
// Obtain the results of the project's file feed
|
||||
if(readFeed())
|
||||
{
|
||||
if(versionCheck(versionTitle))
|
||||
{
|
||||
if (readFeed()) {
|
||||
if (versionCheck(versionTitle)) {
|
||||
String fileLink = getFile(versionLink);
|
||||
if(fileLink != null && type != UpdateType.NO_DOWNLOAD)
|
||||
{
|
||||
if (fileLink != null && type != UpdateType.NO_DOWNLOAD) {
|
||||
String name = file.getName();
|
||||
// If it's a zip file, it shouldn't be downloaded as the plugin's name
|
||||
if(fileLink.endsWith(".zip"))
|
||||
{
|
||||
String [] split = fileLink.split("/");
|
||||
name = split[split.length-1];
|
||||
if (fileLink.endsWith(".zip")) {
|
||||
String[] split = fileLink.split("/");
|
||||
name = split[split.length - 1];
|
||||
}
|
||||
saveFile(new File("plugins/" + updateFolder), name, fileLink);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
result = UpdateResult.UPDATE_AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,15 +184,15 @@ public enum BlockHardness {
|
||||
PISTON_EXTENSION(0.70D),
|
||||
PISTON_MOVING_PIECE(0.70D),
|
||||
PISTON_STICKY_BASE(0.70D);
|
||||
|
||||
|
||||
Material mat;
|
||||
double hardness;
|
||||
|
||||
|
||||
BlockHardness(double hard) {
|
||||
mat = Material.getMaterial(name());
|
||||
hardness = hard;
|
||||
}
|
||||
|
||||
|
||||
public static double getBlockHardness(Material m) {
|
||||
BlockHardness h = getHardness(m);
|
||||
return h == null ? 0D : h.hardness;
|
||||
|
||||
@@ -25,20 +25,20 @@ public class Calibrator implements Listener {
|
||||
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:
|
||||
@@ -56,9 +56,9 @@ public class Calibrator implements Listener {
|
||||
* 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) {
|
||||
@@ -68,7 +68,7 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
|
||||
private int getDoubleCount() {
|
||||
int fill = 0;
|
||||
for (double d : doubles) {
|
||||
@@ -78,7 +78,7 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
|
||||
|
||||
private void clear() {
|
||||
for (int i = 0; i < longs.length; i++) {
|
||||
longs[i] = 0;
|
||||
@@ -93,14 +93,14 @@ public class Calibrator implements Listener {
|
||||
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();
|
||||
@@ -125,7 +125,7 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Find the maximum time it takes to do a task
|
||||
private double getMaxDouble(double length) {
|
||||
int count = getDoubleCount();
|
||||
@@ -146,7 +146,7 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Get the absolute time it takes to do something X times
|
||||
private long getAbsoluteLong() {
|
||||
int count = getLongCount();
|
||||
@@ -167,10 +167,10 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Begin event listeners
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
@@ -182,7 +182,7 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
if (event.getEntity() instanceof Player && ((Player) event.getEntity()) == player) {
|
||||
@@ -194,7 +194,7 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
@@ -204,11 +204,11 @@ public class Calibrator implements Listener {
|
||||
punchAvg = v;
|
||||
}
|
||||
} else if (step == 1) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
@@ -222,7 +222,7 @@ public class Calibrator implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.getPlayer() == player) {
|
||||
|
||||
@@ -19,43 +19,43 @@
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
public class CheckResult {
|
||||
|
||||
|
||||
public enum Result {
|
||||
PASSED,FAILED
|
||||
PASSED, FAILED
|
||||
}
|
||||
|
||||
|
||||
private Result result;
|
||||
private String message;
|
||||
private int data;
|
||||
|
||||
|
||||
public CheckResult(Result result, String message, int data) {
|
||||
this(result, message);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
public CheckResult(Result result, String message) {
|
||||
this(result);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public CheckResult(Result result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean failed() {
|
||||
return result == Result.FAILED;
|
||||
}
|
||||
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public int getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ 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);
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Level {
|
||||
|
||||
private String name;
|
||||
@@ -39,8 +39,8 @@ public class Level {
|
||||
this.actions = actions;
|
||||
|
||||
ChatColor c = ChatColor.valueOf(color);
|
||||
if(c == null) {
|
||||
AntiCheat.getPlugin().getLogger().warning("Event '"+name+"' was initialized with the color '"+color+"' which is invalid.");
|
||||
if (c == null) {
|
||||
AntiCheat.getPlugin().getLogger().warning("Event '" + name + "' was initialized with the color '" + color + "' which is invalid.");
|
||||
AntiCheat.getPlugin().getLogger().warning("This event will not run properly. See http://jd.bukkit.org/apidocs/org/bukkit/ChatColor.html#enum_constant_summary for a list of valid colors");
|
||||
} else {
|
||||
this.color = c;
|
||||
@@ -69,7 +69,7 @@ public class Level {
|
||||
|
||||
public static Level load(String string) {
|
||||
try {
|
||||
if(string.split(":").length == 4) {
|
||||
if (string.split(":").length == 4) {
|
||||
string = Utilities.removeWhitespace(string);
|
||||
String name = string.split(":")[0];
|
||||
int level = Integer.parseInt(string.split(":")[1]);
|
||||
@@ -80,15 +80,15 @@ public class Level {
|
||||
throw new Exception();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
AntiCheat.getPlugin().getLogger().warning("An event was initialized with an invalid string: '"+string+"'");
|
||||
AntiCheat.getPlugin().getLogger().warning("An event was initialized with an invalid string: '" + string + "'");
|
||||
AntiCheat.getPlugin().getLogger().warning("The proper format is: 'name : threshold : color : action' such as 'High : 50 : RED : KICK'");
|
||||
AntiCheat.getPlugin().getLogger().warning("This event will NOT run. ("+ex.getMessage()+")");
|
||||
AntiCheat.getPlugin().getLogger().warning("This event will NOT run. (" + ex.getMessage() + ")");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + " : " + value + " : "+ color.name() + " : " + Utilities.listToCommaString(actions);
|
||||
return name + " : " + value + " : " + color.name() + " : " + Utilities.listToCommaString(actions);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,13 @@
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.files.Magic;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -27,44 +34,39 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import net.h31ix.anticheat.config.files.Magic;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PastebinReport {
|
||||
private StringBuilder report = new StringBuilder();
|
||||
private String url = "";
|
||||
private Date date = new Date();
|
||||
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd kk:mm Z");
|
||||
|
||||
|
||||
|
||||
public PastebinReport(CommandSender cs) {
|
||||
Player player = null;
|
||||
if(cs instanceof Player) {
|
||||
if (cs instanceof Player) {
|
||||
player = (Player) cs;
|
||||
}
|
||||
createReport(player);
|
||||
try {
|
||||
writeReport();
|
||||
} catch (IOException e) {}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
postReport();
|
||||
}
|
||||
|
||||
|
||||
public PastebinReport(CommandSender cs, Player tp) {
|
||||
createReport(tp);
|
||||
try {
|
||||
writeReport();
|
||||
} catch (IOException e) {}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
postReport();
|
||||
}
|
||||
|
||||
|
||||
public String getURL() {
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
private void appendPermissionsTester(Player player) {
|
||||
if (player == null) {
|
||||
append("No player defined.");
|
||||
@@ -73,13 +75,13 @@ public class PastebinReport {
|
||||
|
||||
for (Permission node : Permission.values()) {
|
||||
report.append(player.getName() + ": " + node.toString() + " " + node.get(player));
|
||||
if(node.get(player) && !node.whichPermission(player).equals(node.toString())) {
|
||||
report.append(" (Applied by " + node.whichPermission(player) +")");
|
||||
if (node.get(player) && !node.whichPermission(player).equals(node.toString())) {
|
||||
report.append(" (Applied by " + node.whichPermission(player) + ")");
|
||||
}
|
||||
report.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void createReport(Player player) {
|
||||
if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) {
|
||||
append("------------ WARNING! ------------");
|
||||
@@ -100,15 +102,15 @@ public class PastebinReport {
|
||||
|
||||
private void appendLogs() {
|
||||
List<String> logs = AntiCheat.getManager().getLastLogs();
|
||||
if(logs.size() == 0) {
|
||||
if (logs.size() == 0) {
|
||||
append("No recent logs.");
|
||||
return;
|
||||
}
|
||||
for(String log : logs) {
|
||||
for (String log : logs) {
|
||||
append(log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void appendSystemInfo() {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
append("AntiCheat Version: " + AntiCheat.getVersion() + (AntiCheat.isUpdated() ? "" : " (OUTDATED)"));
|
||||
@@ -131,33 +133,33 @@ public class PastebinReport {
|
||||
FileConfiguration file = magic.getDefaultConfigFile();
|
||||
append("Version: " + magic.getVersion());
|
||||
boolean changed = false;
|
||||
for(Field field : Magic.class.getFields()) {
|
||||
for (Field field : Magic.class.getFields()) {
|
||||
Object defaultValue = file.get(field.getName());
|
||||
try {
|
||||
Field value = magic.getClass().getDeclaredField(field.getName());
|
||||
boolean x = false;
|
||||
String s1 = value.get(magic).toString();
|
||||
String s2 = defaultValue.toString();
|
||||
if(!s1.equals(s2) && !s1.equals(s2 + ".0")) {
|
||||
if (!s1.equals(s2) && !s1.equals(s2 + ".0")) {
|
||||
changed = true;
|
||||
append(field.getName() + ": " + s1 + " (Default: " + s2 + ")");
|
||||
} else {
|
||||
}
|
||||
} catch(NoSuchFieldException ex) {
|
||||
} catch (NoSuchFieldException ex) {
|
||||
|
||||
} catch(IllegalAccessException ex) {
|
||||
} catch (IllegalAccessException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
if(!changed) {
|
||||
if (!changed) {
|
||||
append("No changes from default.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void appendEventHandlers() {
|
||||
report.append(AntiCheat.getManager().getEventChainReport());
|
||||
}
|
||||
|
||||
|
||||
private void writeReport() throws IOException {
|
||||
File f = new File(AntiCheat.getPlugin().getDataFolder() + "/report.txt");
|
||||
FileWriter r = new FileWriter(f);
|
||||
@@ -165,7 +167,7 @@ public class PastebinReport {
|
||||
writer.write(report.toString());
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
private void postReport() {
|
||||
try {
|
||||
URL urls = new URL("http://pastebin.com/api/api_post.php");
|
||||
@@ -177,11 +179,11 @@ public class PastebinReport {
|
||||
conn.setInstanceFollowRedirects(false);
|
||||
conn.setDoOutput(true);
|
||||
OutputStream out = conn.getOutputStream();
|
||||
|
||||
|
||||
out.write(("api_option=paste" + "&api_dev_key=" + URLEncoder.encode("c0616def494dcb5b7632304f8c52c0f1", "utf-8") + "&api_paste_code=" + URLEncoder.encode(report.toString(), "utf-8") + "&api_paste_private=" + URLEncoder.encode("1", "utf-8") + "&api_paste_name=" + URLEncoder.encode("", "utf-8") + "&api_paste_expire_date=" + URLEncoder.encode("1M", "utf-8") + "&api_paste_format=" + URLEncoder.encode("text", "utf-8") + "&api_user_key=" + URLEncoder.encode("", "utf-8")).getBytes());
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
|
||||
if (conn.getResponseCode() == 200) {
|
||||
InputStream receive = conn.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(receive));
|
||||
@@ -192,9 +194,9 @@ public class PastebinReport {
|
||||
response.append("\r\n");
|
||||
}
|
||||
reader.close();
|
||||
|
||||
|
||||
String result = response.toString().trim();
|
||||
|
||||
|
||||
if (!result.contains("http://")) {
|
||||
url = "Failed to post. Check report.txt";
|
||||
} else {
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum Permission {
|
||||
/* Check Nodes */
|
||||
@@ -49,7 +48,7 @@ public enum Permission {
|
||||
CHECK_VISUAL,
|
||||
CHECK_FASTINVENTORY,
|
||||
CHECK_AUTOTOOL,
|
||||
|
||||
|
||||
/* System Nodes */
|
||||
SYSTEM_LOG,
|
||||
SYSTEM_XRAY,
|
||||
@@ -64,7 +63,7 @@ public enum Permission {
|
||||
SYSTEM_RELOAD;
|
||||
|
||||
private static final String PERMISSION_ALL = "anticheat.*";
|
||||
|
||||
|
||||
public boolean get(CommandSender cs) {
|
||||
return cs.hasPermission(toString()) || cs.hasPermission(getBase()) || cs.hasPermission(PERMISSION_ALL);
|
||||
}
|
||||
@@ -74,17 +73,17 @@ public enum Permission {
|
||||
}
|
||||
|
||||
public String whichPermission(CommandSender cs) {
|
||||
for(String s : new String[]{toString(), getBase(), PERMISSION_ALL}) {
|
||||
if(cs.hasPermission(s)) {
|
||||
for (String s : new String[]{toString(), getBase(), PERMISSION_ALL}) {
|
||||
if (cs.hasPermission(s)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "anticheat." + this.name().toLowerCase().replace("_", ".");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -24,21 +24,21 @@ public class SpyState {
|
||||
private boolean allowFlight;
|
||||
private boolean flying;
|
||||
private Location location;
|
||||
|
||||
|
||||
public SpyState(boolean allowFlight, boolean flying, Location location) {
|
||||
this.allowFlight = allowFlight;
|
||||
this.flying = flying;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
|
||||
public boolean getAllowFlight() {
|
||||
return this.allowFlight;
|
||||
}
|
||||
|
||||
|
||||
public boolean getFlying() {
|
||||
return this.flying;
|
||||
}
|
||||
|
||||
|
||||
public Location getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.h31ix.anticheat.util;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public enum ToolHardness {
|
||||
|
||||
|
||||
// NOTHING(null, 1.5)
|
||||
WOOD(0.75D),
|
||||
STONE(0.40D),
|
||||
@@ -29,18 +29,20 @@ public enum ToolHardness {
|
||||
DIAMOND(0.20D),
|
||||
SHEARS(0.55D),
|
||||
GOLD(0.15D);
|
||||
|
||||
|
||||
double hardness;
|
||||
|
||||
|
||||
ToolHardness(double hard) {
|
||||
hardness = hard;
|
||||
}
|
||||
|
||||
|
||||
public static double getToolHardness(Material tool) {
|
||||
for (ToolHardness e : ToolHardness.values()) {
|
||||
if (tool.name().contains(e.name())) { return e.hardness; }
|
||||
if (tool.name().contains(e.name())) {
|
||||
return e.hardness;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 1.50D;
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,6 @@
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.h31ix.anticheat.AntiCheat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -34,6 +29,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class Utilities {
|
||||
private static final List<Material> INSTANT_BREAK = new ArrayList<Material>();
|
||||
private static final List<Material> FOOD = new ArrayList<Material>();
|
||||
@@ -46,7 +46,6 @@ public final class Utilities {
|
||||
* Send a hack level alert to players and console
|
||||
*
|
||||
* @param message List of strings to send as the alert
|
||||
*
|
||||
*/
|
||||
public static void alert(List<String> message) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
@@ -126,18 +125,19 @@ public final class Utilities {
|
||||
*/
|
||||
public static boolean isFullyInWater(Location player) {
|
||||
double touchedX = fixXAxis(player.getX());
|
||||
|
||||
|
||||
// Yes, this doesn't make sense, but it's supposed to fix some false positives in water walk.
|
||||
// Think of it as 2 negatives = a positive :)
|
||||
if (!(new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && !(new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return (new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && (new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes a player's X position to determine the block they are on, even if they're on the edge
|
||||
*
|
||||
* @param x player's x position
|
||||
* @return fixed x position
|
||||
*/
|
||||
@@ -165,7 +165,7 @@ public final class Utilities {
|
||||
return newloc.isLiquid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -336,56 +336,57 @@ public final class Utilities {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
x = true;
|
||||
} catch (Exception ex) {}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the time in milliseconds that it should take to break the given block with the given tool
|
||||
*
|
||||
* @param tool tool to check
|
||||
* @param tool tool to check
|
||||
* @param block block to check
|
||||
* @return time in milliseconds to break
|
||||
*/
|
||||
public static long calcSurvivalFastBreak(ItemStack tool, Material block) {
|
||||
if(isInstantBreak(block) || (tool.getType() == Material.SHEARS && block == Material.LEAVES)) {
|
||||
if (isInstantBreak(block) || (tool.getType() == Material.SHEARS && block == Material.LEAVES)) {
|
||||
return 0;
|
||||
}
|
||||
double bhardness = BlockHardness.getBlockHardness(block);
|
||||
double thardness = ToolHardness.getToolHardness(tool.getType());
|
||||
long enchantlvl = (long) tool.getEnchantmentLevel(Enchantment.DIG_SPEED);
|
||||
|
||||
|
||||
long result = Math.round((bhardness * thardness) * 0.10 * 10000);
|
||||
|
||||
|
||||
result += 150;
|
||||
|
||||
|
||||
if (enchantlvl > 0) {
|
||||
result /= enchantlvl * enchantlvl + 1L;
|
||||
}
|
||||
|
||||
|
||||
if (result > 25000) {
|
||||
result = 25000;
|
||||
} else if (result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
if(isQuickCombo(tool, block)) {
|
||||
result = result/2;
|
||||
if (isQuickCombo(tool, block)) {
|
||||
result = result / 2;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the given tool is a combination that makes the breaking of this block faster
|
||||
*
|
||||
* @param tool tool to check
|
||||
* @param tool tool to check
|
||||
* @param block block to check
|
||||
* @return true if quick combo
|
||||
*/
|
||||
private static boolean isQuickCombo(ItemStack tool, Material block) {
|
||||
for(Material t : COMBO.keySet()) {
|
||||
if(tool.getType() == t && COMBO.get(t) == block) {
|
||||
for (Material t : COMBO.keySet()) {
|
||||
if (tool.getType() == t && COMBO.get(t) == block) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -395,14 +396,14 @@ public final class Utilities {
|
||||
/**
|
||||
* Determine if a block ISN'T one of the specified types
|
||||
*
|
||||
* @param block block to check
|
||||
* @param block block to check
|
||||
* @param materials array of possible materials
|
||||
* @return true if the block isn't any of the materials
|
||||
*/
|
||||
public static boolean blockIsnt(Block block, Material[] materials) {
|
||||
Material type = block.getType();
|
||||
for(Material m : materials) {
|
||||
if(m == type) {
|
||||
for (Material m : materials) {
|
||||
if (m == type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -415,7 +416,7 @@ public final class Utilities {
|
||||
* @param command input string
|
||||
* @return parsed commands
|
||||
*/
|
||||
public static String [] getCommands(String command) {
|
||||
public static String[] getCommands(String command) {
|
||||
return command.replaceAll("COMMAND\\[", "").replaceAll("]", "").split(";");
|
||||
}
|
||||
|
||||
@@ -433,12 +434,12 @@ public final class Utilities {
|
||||
* Determine if a player has the given enchantment on their armor
|
||||
*
|
||||
* @param player player to check
|
||||
* @param e enchantment to check
|
||||
* @param e enchantment to check
|
||||
* @return true if the armor has this enchantment
|
||||
*/
|
||||
public static boolean hasArmorEnchantment(Player player, Enchantment e) {
|
||||
for(ItemStack is : player.getInventory().getArmorContents()) {
|
||||
if(is != null && is.containsEnchantment(e)) {
|
||||
for (ItemStack is : player.getInventory().getArmorContents()) {
|
||||
if (is != null && is.containsEnchantment(e)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -465,16 +466,16 @@ public final class Utilities {
|
||||
*/
|
||||
public static String listToCommaString(List<String> list) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(int i=0;i<list.size();i++) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
b.append(list.get(i));
|
||||
if(i < list.size()-1) {
|
||||
if (i < list.size() - 1) {
|
||||
b.append(",");
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static {
|
||||
// START INSTANT BREAK MATERIALS
|
||||
INSTANT_BREAK.add(Material.RED_MUSHROOM);
|
||||
|
||||
@@ -24,7 +24,10 @@ import net.h31ix.anticheat.manage.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Database {
|
||||
|
||||
@@ -126,12 +129,12 @@ public class Database {
|
||||
|
||||
connection.setAutoCommit(false);
|
||||
|
||||
eventTask = Bukkit.getScheduler().runTaskTimerAsynchronously(AntiCheat.getPlugin(), new Runnable(){
|
||||
eventTask = Bukkit.getScheduler().runTaskTimerAsynchronously(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
flushEvents();
|
||||
}
|
||||
}, eventInterval* 60 * 20, eventInterval * 60 * 20);
|
||||
}, eventInterval * 60 * 20, eventInterval * 60 * 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -179,7 +182,7 @@ public class Database {
|
||||
}
|
||||
|
||||
public void cleanEvents() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable(){
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
@@ -32,16 +32,16 @@ import java.util.SortedMap;
|
||||
* Where CONDITION is a statement that will be evaluated as either <b>TRUE</b> or <b>FALSE</b>
|
||||
* and the results are actions to be taken for either outcome.
|
||||
* <br /><br />
|
||||
*
|
||||
* <p/>
|
||||
* Should you need additional actions, the system will recursively parse the following values and handle appropriately.
|
||||
* <br />
|
||||
* For instance, (CONDITION) ? (TRUE RESULT) : (CONDITION) ? (TRUE RESULT) : (FALSE RESULT) is a valid rule
|
||||
* <br /><br />
|
||||
*
|
||||
* <p/>
|
||||
* An example of a valid Conditional Rule:<br />
|
||||
* 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}
|
||||
*/
|
||||
public class ConditionalRule extends Rule {
|
||||
@@ -62,11 +62,11 @@ public class ConditionalRule extends Rule {
|
||||
try {
|
||||
// Load all variables
|
||||
SortedMap<String, Object> map = getVariables(user, type);
|
||||
for(String key : map.keySet()) {
|
||||
for (String key : map.keySet()) {
|
||||
engine.put(key, map.get(key));
|
||||
}
|
||||
|
||||
boolean value = (Boolean)engine.eval(getString().split(TRUE_DELIMITER)[0]);
|
||||
boolean value = (Boolean) engine.eval(getString().split(TRUE_DELIMITER)[0]);
|
||||
// Yo dawg I heard you like conditionals...
|
||||
String next = value ? getString().split(TRUE_DELIMITER)[1].split(FALSE_DELIMITER)[0] : getString().split(TRUE_DELIMITER)[1].split(FALSE_DELIMITER)[1];
|
||||
|
||||
@@ -80,14 +80,14 @@ public class ConditionalRule extends Rule {
|
||||
|
||||
private void execute(String string, User user, CheckType type) {
|
||||
// If we're told to do nothing
|
||||
if(string.equalsIgnoreCase("null") || string.equalsIgnoreCase("none")) return;
|
||||
if (string.equalsIgnoreCase("null") || string.equalsIgnoreCase("none")) return;
|
||||
|
||||
// If this string is a new conditional statement
|
||||
if(TYPE.matches(string)) {
|
||||
if (TYPE.matches(string)) {
|
||||
new ConditionalRule(string).check(user, type);
|
||||
} else if(isVariableSet(string)) {
|
||||
} else if (isVariableSet(string)) {
|
||||
setVariable(string.split("=")[0], string.split("=")[1], user);
|
||||
} else if(isFunction(string)) {
|
||||
} else if (isFunction(string)) {
|
||||
doFunction(string, type, user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,37 +24,39 @@ import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* A rule is a scriptable function used to customize the functions of AntiCheat<br />
|
||||
* Rules are executed whenever a user's level rises.<br /><br />
|
||||
*
|
||||
* <p/>
|
||||
* There are various variables you can use to interact with AntiCheat through your rules<br />
|
||||
* Variables are denoted with the type followed by a _ followed by the variable name.<br />
|
||||
* For instance, a variable coming from a user who has used FLY 5 times and is checked by a rule containing 'Check_FLY' will produce a value of 5.
|
||||
* <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 />
|
||||
* - Player: Contains LEVEL, the player's current level and CHECK, the check that was just failed
|
||||
* <br /><br />
|
||||
*
|
||||
* <p/>
|
||||
* There are also functions you can use to execute an action within AntiCheat<br />
|
||||
* Functions are denoted with the type followed by a period followed by the function name.<br />
|
||||
* For instance, a rule containing Player.KICK will result in the user being kicked.<br />
|
||||
* <br /><br />
|
||||
*
|
||||
* <p/>
|
||||
* <b>Types of functions:</b><br />
|
||||
* - Player: RESET, KICK, BAN, COMMAND[command] OR COMMAND[command1;command2]
|
||||
* <i>- when using commands <b>&player</b> will be replaced by the player name, <b>&world</b> will be replaced by the player's world,
|
||||
* and <b>&check</b> will be replaced by the check that caused this rule to be run</i><br />
|
||||
* <br /><br />
|
||||
*
|
||||
* <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}
|
||||
*
|
||||
*/
|
||||
public class Rule {
|
||||
|
||||
@@ -106,12 +108,12 @@ public class Rule {
|
||||
* @return an instance of Rule if an implementation exists to handle this rule, null if none are found
|
||||
*/
|
||||
public static Rule load(String string) {
|
||||
for(Type type : Type.values()) {
|
||||
if(type.matches(string)) {
|
||||
for (Type type : Type.values()) {
|
||||
if (type.matches(string)) {
|
||||
try {
|
||||
Class c = Class.forName(type.getInstance());
|
||||
Constructor con = c.getConstructor(String.class);
|
||||
return (Rule)con.newInstance(string);
|
||||
return (Rule) con.newInstance(string);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -135,10 +137,10 @@ public class Rule {
|
||||
|
||||
protected SortedMap<String, Object> getVariables(User user, CheckType type) {
|
||||
SortedMap<String, Object> map = new TreeMap<String, Object>();
|
||||
map.put("player_check", type.name().toLowerCase());
|
||||
map.put("player_check", type.name().toLowerCase());
|
||||
map.put("player_level", user.getLevel());
|
||||
for(CheckType t : CheckType.values()) {
|
||||
map.put("check_"+t.name().toLowerCase(), t.getUses(user.getName()));
|
||||
for (CheckType t : CheckType.values()) {
|
||||
map.put("check_" + t.name().toLowerCase(), t.getUses(user.getName()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -146,13 +148,13 @@ public class Rule {
|
||||
protected void setVariable(String variable, String value, User user) {
|
||||
// Only variable that can be set for now, may change in the future
|
||||
// others wouldn't make any sense to set
|
||||
if(variable.equals("player_level") && Utilities.isInt(value)) {
|
||||
if (variable.equals("player_level") && Utilities.isInt(value)) {
|
||||
user.setLevel(Integer.parseInt(value));
|
||||
}
|
||||
}
|
||||
|
||||
protected void doFunction(String text, CheckType type, User user) {
|
||||
if(text.toLowerCase().startsWith("player")) {
|
||||
if (text.toLowerCase().startsWith("player")) {
|
||||
text = text.split("\\.")[1];
|
||||
List<String> action = new ArrayList<String>();
|
||||
action.add(text);
|
||||
@@ -170,6 +172,6 @@ public class Rule {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type+"{"+string+"}";
|
||||
return type + "{" + string + "}";
|
||||
}
|
||||
}
|
||||
@@ -33,12 +33,14 @@ 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; }
|
||||
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();
|
||||
|
||||
@@ -29,7 +29,7 @@ public class XRayStats {
|
||||
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);
|
||||
@@ -53,31 +53,31 @@ public class XRayStats {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
|
||||
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;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class XRayTracker {
|
||||
private Map<String, Integer> diamond = new HashMap<String, Integer>();
|
||||
@@ -41,14 +42,14 @@ public class XRayTracker {
|
||||
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) {
|
||||
@@ -56,29 +57,29 @@ public class XRayTracker {
|
||||
}
|
||||
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();
|
||||
@@ -93,35 +94,35 @@ public class XRayTracker {
|
||||
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);
|
||||
@@ -130,7 +131,7 @@ public class XRayTracker {
|
||||
map.put(player, playerLevel + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private float round(double num) {
|
||||
double number = num;
|
||||
float p = (float) Math.pow(POWER, 1);
|
||||
@@ -138,7 +139,7 @@ public class XRayTracker {
|
||||
float tmp = Math.round(number);
|
||||
return tmp / p;
|
||||
}
|
||||
|
||||
|
||||
public void reset(String player) {
|
||||
totalblock.put(player, 1);
|
||||
diamond.put(player, 0);
|
||||
|
||||
Reference in new issue
Block a user