mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-04 14:38:47 +00:00
Sanity clean up
This commit is contained in:
1 parent
ca4406809b
commit
9486e18c4f
40 files changed
+461
-535
No files matched your search
@@ -1,4 +1,5 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.h31ix.anticheat</groupId>
|
||||
<artifactId>AntiCheat</artifactId>
|
||||
|
||||
@@ -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();
|
||||
@@ -128,7 +128,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
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();
|
||||
@@ -197,7 +197,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
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,7 +211,7 @@ public class CommandHandler implements CommandExecutor {
|
||||
};
|
||||
|
||||
cs.sendMessage("----------------------[" + GREEN + "AntiCheat" + WHITE + "]----------------------");
|
||||
for(String s : lines) {
|
||||
for (String s : lines) {
|
||||
cs.sendMessage(base + GREEN + s);
|
||||
}
|
||||
}
|
||||
@@ -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() + ")";
|
||||
@@ -403,8 +403,8 @@ public class CommandHandler implements CommandExecutor {
|
||||
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;
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
@@ -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.
|
||||
@@ -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,7 +41,7 @@ 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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -134,7 +134,7 @@ 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;
|
||||
@@ -142,7 +142,7 @@ public class EntityListener extends EventListener {
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class InventoryListener extends EventListener {
|
||||
|
||||
@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()));
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
@@ -101,7 +101,9 @@ public class AnticheatManager {
|
||||
|
||||
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));
|
||||
}
|
||||
@@ -124,7 +126,7 @@ public class AnticheatManager {
|
||||
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';
|
||||
}
|
||||
|
||||
@@ -135,7 +137,7 @@ public class AnticheatManager {
|
||||
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";
|
||||
@@ -176,7 +178,7 @@ public class AnticheatManager {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -131,6 +132,7 @@ public class UserManager {
|
||||
|
||||
/**
|
||||
* Reset a user
|
||||
*
|
||||
* @param name Name of the user
|
||||
*/
|
||||
public void safeReset(String name) {
|
||||
@@ -151,7 +153,7 @@ public class UserManager {
|
||||
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,6 +166,7 @@ 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
|
||||
@@ -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
|
||||
{
|
||||
if(xFile.getName().equals(cFile.getName()))
|
||||
for (File xFile : contents) // Loop through contents to see if it exists
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.h31ix.anticheat.util;
|
||||
public class CheckResult {
|
||||
|
||||
public enum Result {
|
||||
PASSED,FAILED
|
||||
PASSED, FAILED
|
||||
}
|
||||
|
||||
private Result result;
|
||||
|
||||
@@ -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,13 +34,6 @@ 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 = "";
|
||||
@@ -43,13 +43,14 @@ public class PastebinReport {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -57,7 +58,8 @@ public class PastebinReport {
|
||||
createReport(tp);
|
||||
try {
|
||||
writeReport();
|
||||
} catch (IOException e) {}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
postReport();
|
||||
}
|
||||
|
||||
@@ -73,8 +75,8 @@ 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');
|
||||
}
|
||||
@@ -100,11 +102,11 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -131,25 +133,25 @@ 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.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum Permission {
|
||||
/* Check Nodes */
|
||||
@@ -74,8 +73,8 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ public enum ToolHardness {
|
||||
|
||||
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()) {
|
||||
@@ -138,6 +137,7 @@ public final class Utilities {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -336,7 +336,8 @@ public final class Utilities {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
x = true;
|
||||
} catch (Exception ex) {}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -348,7 +349,7 @@ public final class Utilities {
|
||||
* @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);
|
||||
@@ -369,8 +370,8 @@ public final class Utilities {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
if(isQuickCombo(tool, block)) {
|
||||
result = result/2;
|
||||
if (isQuickCombo(tool, block)) {
|
||||
result = result / 2;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -384,8 +385,8 @@ public final class Utilities {
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -401,8 +402,8 @@ public final class Utilities {
|
||||
*/
|
||||
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(";");
|
||||
}
|
||||
|
||||
@@ -437,8 +438,8 @@ public final class Utilities {
|
||||
* @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,9 +466,9 @@ 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(",");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -137,8 +139,8 @@ public class Rule {
|
||||
SortedMap<String, Object> map = new TreeMap<String, Object>();
|
||||
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 + "}";
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,9 @@ public class XRayListener implements Listener {
|
||||
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();
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -26,8 +27,8 @@ public class BlockHardnessTest {
|
||||
|
||||
@Test
|
||||
public void verifyExistence() {
|
||||
for(Material m : Material.values()) {
|
||||
if(!BlockHardness.hasBlockHardness(m) && m.isBlock() && m != Material.AIR && m != Material.BEDROCK) {
|
||||
for (Material m : Material.values()) {
|
||||
if (!BlockHardness.hasBlockHardness(m) && m.isBlock() && m != Material.AIR && m != Material.BEDROCK) {
|
||||
Assert.fail("Material " + m + " is not accounted for by BlockHardness");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user