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
31 files changed
+233
-307
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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,7 +56,13 @@ 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.
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
*
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -81,7 +81,9 @@ 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);
|
||||
@@ -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.
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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
|
||||
*/
|
||||
@@ -229,6 +231,7 @@ public class User {
|
||||
|
||||
/**
|
||||
* Restore the player's inventory with the current inventory snapshot
|
||||
*
|
||||
* @param inventory Player's inventory
|
||||
*/
|
||||
public void restoreInventory(Inventory inventory) {
|
||||
@@ -244,6 +247,7 @@ public class User {
|
||||
|
||||
/**
|
||||
* Set the player's to location
|
||||
*
|
||||
* @param x X value
|
||||
* @param y Y value
|
||||
* @param z Z value
|
||||
@@ -256,6 +260,7 @@ public class User {
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -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) {
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
@@ -216,53 +197,39 @@ public class Updater
|
||||
int count;
|
||||
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)
|
||||
{
|
||||
} 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);
|
||||
ZipFile zipFile = new ZipFile(fSourceZip);
|
||||
Enumeration<? extends ZipEntry> e = zipFile.entries();
|
||||
while(e.hasMoreElements())
|
||||
{
|
||||
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,12 +273,9 @@ 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
|
||||
@@ -327,19 +283,15 @@ public class Updater
|
||||
boolean found = false;
|
||||
for (File xFile : contents) // Loop through contents to see if it exists
|
||||
{
|
||||
if(xFile.getName().equals(cFile.getName()))
|
||||
{
|
||||
if (xFile.getName().equals(cFile.getName())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
if (!found) {
|
||||
// Move the new file into the current dir
|
||||
cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// This file already exists, so we don't need it anymore.
|
||||
cFile.delete();
|
||||
}
|
||||
@@ -350,9 +302,7 @@ public class Updater
|
||||
}
|
||||
new File(zipPath).delete();
|
||||
fSourceZip.delete();
|
||||
}
|
||||
catch(IOException ex)
|
||||
{
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful.");
|
||||
result = Updater.UpdateResult.FAIL_DOWNLOAD;
|
||||
@@ -363,12 +313,9 @@ public class Updater
|
||||
/**
|
||||
* Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
|
||||
*/
|
||||
public boolean pluginFile(String name)
|
||||
{
|
||||
for(File file : new File("plugins").listFiles())
|
||||
{
|
||||
if(file.getName().equals(name))
|
||||
{
|
||||
public boolean pluginFile(String name) {
|
||||
for (File file : new File("plugins").listFiles()) {
|
||||
if (file.getName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -378,11 +325,9 @@ public class Updater
|
||||
/**
|
||||
* Obtain the direct download file url from the file's page.
|
||||
*/
|
||||
private String getFile(String link)
|
||||
{
|
||||
private String getFile(String link) {
|
||||
String download = null;
|
||||
try
|
||||
{
|
||||
try {
|
||||
// Open a connection to the page
|
||||
URL url = new URL(link);
|
||||
URLConnection urlConn = url.openConnection();
|
||||
@@ -391,22 +336,17 @@ 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>"))
|
||||
{
|
||||
else if (line.contains("<dt>Size</dt>")) {
|
||||
sizeLine = counter + 1;
|
||||
}
|
||||
else if(counter == sizeLine)
|
||||
{
|
||||
} else if (counter == sizeLine) {
|
||||
String size = line.replaceAll("<dd>", "").replaceAll("</dd>", "");
|
||||
multiplier = size.contains("MiB") ? 1048576 : 1024;
|
||||
size = size.replace(" KiB", "").replace(" MiB", "");
|
||||
@@ -417,9 +357,7 @@ public class Updater
|
||||
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
|
||||
{
|
||||
try {
|
||||
remVer = calVer(remoteVersion);
|
||||
curVer = calVer(version);
|
||||
}
|
||||
catch(NumberFormatException nfe)
|
||||
{
|
||||
} 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"))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = "";
|
||||
@@ -49,7 +49,8 @@ public class PastebinReport {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum Permission {
|
||||
/* Check Nodes */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user