mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Sanity commit. Had a nice break.
This commit is contained in:
1 parent
77645da2b2
commit
e7e5c996f3
10 files changed
+178
-178
No files matched your search
@@ -55,210 +55,211 @@ public class Anticheat extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
manager = new AnticheatManager(this, getLogger());
|
||||
eventList.add(new PlayerListener());
|
||||
eventList.add(new BlockListener());
|
||||
eventList.add(new EntityListener());
|
||||
eventList.add(new VehicleListener());
|
||||
eventList.add(new InventoryListener());
|
||||
// Order is important in some cases, don't screw with these unless needed, especially config
|
||||
setupConfig();
|
||||
// Xray must come before events
|
||||
setupXray();
|
||||
setupEvents();
|
||||
setupCommands();
|
||||
setupUpdater();
|
||||
setupMetrics();
|
||||
restoreLevels();
|
||||
// Test for compatibility for 1.4.5-R1.0
|
||||
try {
|
||||
Material.AIR.isSolid();
|
||||
} catch (NoSuchMethodError error) {
|
||||
getLogger().severe("You are using an outdated version of CraftBukkit that does not contain the API required for AntiCheat to run properly.");
|
||||
getLogger().severe("Please update to CraftBukkit 1.4.5-R1.0 or higher by visiting dl.bukkit.org and hitting the green download button.");
|
||||
getLogger().severe("AntiCheat will now be disabled, and will not protect your server until it is updated.");
|
||||
getPluginLoader().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
// End test
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Finished loading.");
|
||||
}
|
||||
manager = new AnticheatManager(this, getLogger());
|
||||
eventList.add(new PlayerListener());
|
||||
eventList.add(new BlockListener());
|
||||
eventList.add(new EntityListener());
|
||||
eventList.add(new VehicleListener());
|
||||
eventList.add(new InventoryListener());
|
||||
// Order is important in some cases, don't screw with these unless needed, especially config
|
||||
setupConfig();
|
||||
// Xray must come before events
|
||||
setupXray();
|
||||
setupEvents();
|
||||
setupCommands();
|
||||
setupUpdater();
|
||||
setupMetrics();
|
||||
restoreLevels();
|
||||
// Test for compatibility for 1.4.5-R1.0
|
||||
try {
|
||||
Material.AIR.isSolid();
|
||||
} catch (NoSuchMethodError error) {
|
||||
getLogger().severe("You are using an outdated version of CraftBukkit that does not contain the API required for AntiCheat to run properly.");
|
||||
getLogger().severe("Please update to CraftBukkit 1.4.5-R1.0 or higher by visiting dl.bukkit.org and hitting the green download button.");
|
||||
getLogger().severe("AntiCheat will now be disabled, and will not protect your server until it is updated.");
|
||||
getPluginLoader().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
// End test
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Finished loading.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
AnticheatManager.close();
|
||||
for (User user : manager.getUserManager().getUsers()) {
|
||||
config.saveLevel(user.getName(), user.getLevel());
|
||||
}
|
||||
config.saveLevels();
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
cleanup();
|
||||
AnticheatManager.close();
|
||||
for (User user : manager.getUserManager().getUsers()) {
|
||||
config.saveLevel(user.getName(), user.getLevel());
|
||||
}
|
||||
config.saveLevels();
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
private boolean save(InputStream in, File file) {
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Unable to save files. Is the directory writeable?");
|
||||
}
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, file.getName() + " created.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
getLogger().severe("Unable to save files. Is the directory writeable?");
|
||||
}
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, file.getName() + " created.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setupXray() {
|
||||
final XRayTracker xtracker = manager.getXRayTracker();
|
||||
if (config.logXRay()) {
|
||||
eventList.add(new XRayListener());
|
||||
if (config.alertXRay()) {
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
String name = player.getName();
|
||||
if (!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name)) {
|
||||
List<String> alert = new ArrayList<String>();
|
||||
alert.add(ChatColor.YELLOW + "[ALERT] " + ChatColor.WHITE + name + ChatColor.YELLOW + " might be using xray.");
|
||||
alert.add(ChatColor.YELLOW + "[ALERT] Please check their xray stats using " + ChatColor.WHITE + "/anticheat xray " + name + ChatColor.YELLOW + ".");
|
||||
Utilities.alert(alert);
|
||||
xtracker.logAlert(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, XRAY_TIME, XRAY_TIME);
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Scheduled the XRay checker.");
|
||||
}
|
||||
}
|
||||
}
|
||||
final XRayTracker xtracker = manager.getXRayTracker();
|
||||
if (config.logXRay()) {
|
||||
eventList.add(new XRayListener());
|
||||
if (config.alertXRay()) {
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
String name = player.getName();
|
||||
if (!xtracker.hasAlerted(name) && xtracker.sufficientData(name) && xtracker.hasAbnormal(name)) {
|
||||
List<String> alert = new ArrayList<String>();
|
||||
alert.add(ChatColor.YELLOW + "[ALERT] " + ChatColor.WHITE + name + ChatColor.YELLOW + " might be using xray.");
|
||||
alert.add(ChatColor.YELLOW + "[ALERT] Please check their xray stats using " + ChatColor.WHITE + "/anticheat xray " + name + ChatColor.YELLOW + ".");
|
||||
Utilities.alert(alert);
|
||||
xtracker.logAlert(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, XRAY_TIME, XRAY_TIME);
|
||||
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Scheduled the XRay checker.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupEvents() {
|
||||
for (Listener listener : eventList) {
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Registered events for ".concat(listener.toString().split("@")[0].split(".anticheat.")[1]));
|
||||
}
|
||||
}
|
||||
for (Listener listener : eventList) {
|
||||
getServer().getPluginManager().registerEvents(listener, this);
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Registered events for ".concat(listener.toString().split("@")[0].split(".anticheat.")[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupCommands() {
|
||||
getCommand("anticheat").setExecutor(new CommandHandler());
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Registered commands.");
|
||||
}
|
||||
getCommand("anticheat").setExecutor(new CommandHandler());
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Registered commands.");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupUpdater() {
|
||||
if (config.autoUpdate()) {
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Checking for a new update...");
|
||||
}
|
||||
Updater updater = new Updater(this, "anticheat", this.getFile(), Updater.UpdateType.DEFAULT, false);
|
||||
update = updater.getResult() != Updater.UpdateResult.NO_UPDATE;
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Update available: " + update);
|
||||
}
|
||||
}
|
||||
if (config.autoUpdate()) {
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Checking for a new update...");
|
||||
}
|
||||
Updater updater = new Updater(this, "anticheat", this.getFile(), Updater.UpdateType.DEFAULT, false);
|
||||
update = updater.getResult() != Updater.UpdateResult.NO_UPDATE;
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Update available: " + update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMetrics() {
|
||||
try {
|
||||
metrics = new Metrics(this);
|
||||
final EventListener listener = new EventListener();
|
||||
Graph hacksGraph = metrics.createGraph("Hacks blocked");
|
||||
for (final CheckType type : CheckType.values()) {
|
||||
hacksGraph.addPlotter(new Metrics.Plotter(CheckType.getName(type)) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return EventListener.getCheats(type);
|
||||
}
|
||||
});
|
||||
listener.resetCheck(type);
|
||||
}
|
||||
Graph apiGraph = metrics.createGraph("API Usage");
|
||||
apiGraph.addPlotter(new Metrics.Plotter("Checks disabled") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return manager.getCheckManager().getDisabled();
|
||||
}
|
||||
});
|
||||
apiGraph.addPlotter(new Metrics.Plotter("Players exempted") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return manager.getCheckManager().getExempt();
|
||||
}
|
||||
});
|
||||
metrics.start();
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Metrics started.");
|
||||
}
|
||||
} catch (IOException ex) {}
|
||||
try {
|
||||
metrics = new Metrics(this);
|
||||
final EventListener listener = new EventListener();
|
||||
Graph hacksGraph = metrics.createGraph("Hacks blocked");
|
||||
for (final CheckType type : CheckType.values()) {
|
||||
hacksGraph.addPlotter(new Metrics.Plotter(CheckType.getName(type)) {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return EventListener.getCheats(type);
|
||||
}
|
||||
});
|
||||
listener.resetCheck(type);
|
||||
}
|
||||
Graph apiGraph = metrics.createGraph("API Usage");
|
||||
apiGraph.addPlotter(new Metrics.Plotter("Checks disabled") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return manager.getCheckManager().getDisabled();
|
||||
}
|
||||
});
|
||||
apiGraph.addPlotter(new Metrics.Plotter("Players exempted") {
|
||||
@Override
|
||||
public int getValue() {
|
||||
return manager.getCheckManager().getExempt();
|
||||
}
|
||||
});
|
||||
metrics.start();
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Metrics started.");
|
||||
}
|
||||
} catch (IOException ex) {}
|
||||
}
|
||||
|
||||
private void setupConfig() {
|
||||
config = manager.getConfiguration();
|
||||
config.load();
|
||||
checkConfigs();
|
||||
verbose = config.verboseStartup();
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Setup the config.");
|
||||
}
|
||||
config = manager.getConfiguration();
|
||||
config.load();
|
||||
checkConfigs();
|
||||
verbose = config.verboseStartup();
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Setup the config.");
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreLevels() {
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
String name = player.getName();
|
||||
manager.getUserManager().addUser(new User(player.getName(), config.getLevel(name)));
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Data for " + player.getName() + " re-applied from flatfile");
|
||||
}
|
||||
}
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
String name = player.getName();
|
||||
manager.getUserManager().addUser(new User(player.getName(), config.getLevel(name)));
|
||||
if (verbose) {
|
||||
getLogger().log(Level.INFO, "Data for " + player.getName() + " re-applied from flatfile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkConfigs() {
|
||||
save(getResource("config.yml"), new File(getDataFolder() + "/config.yml"));
|
||||
save(getResource("lang.yml"), new File(getDataFolder() + "/lang.yml"));
|
||||
save(getResource("magic.yml"), new File(getDataFolder() + "/magic.yml"));
|
||||
if(!save(getResource("events.yml"), new File(getDataFolder() + "/events.yml"))) {
|
||||
config.updateEvents();
|
||||
}
|
||||
save(getResource("config.yml"), new File(getDataFolder() + "/config.yml"));
|
||||
save(getResource("lang.yml"), new File(getDataFolder() + "/lang.yml"));
|
||||
save(getResource("magic.yml"), new File(getDataFolder() + "/magic.yml"));
|
||||
if(!save(getResource("events.yml"), new File(getDataFolder() + "/events.yml"))) {
|
||||
config.updateEvents();
|
||||
}
|
||||
}
|
||||
|
||||
public static Anticheat getPlugin() {
|
||||
return manager.getPlugin();
|
||||
return manager.getPlugin();
|
||||
}
|
||||
|
||||
public static AnticheatManager getManager() {
|
||||
return manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
public static boolean isUpdated() {
|
||||
return !update;
|
||||
return !update;
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
return manager.getPlugin().getDescription().getVersion();
|
||||
return manager.getPlugin().getDescription().getVersion();
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
eventList = null;
|
||||
manager = null;
|
||||
config = null;
|
||||
metrics = null;
|
||||
eventList = null;
|
||||
manager = null;
|
||||
config = null;
|
||||
metrics = null;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ package net.h31ix.anticheat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.h31ix.anticheat.util.Calibrator;
|
||||
import net.h31ix.anticheat.manage.CheckType;
|
||||
import net.h31ix.anticheat.manage.User;
|
||||
import net.h31ix.anticheat.manage.UserManager;
|
||||
|
||||
@@ -29,7 +29,6 @@ import net.h31ix.anticheat.util.Distance;
|
||||
import net.h31ix.anticheat.util.Language;
|
||||
import net.h31ix.anticheat.util.Magic;
|
||||
import net.h31ix.anticheat.util.Utilities;
|
||||
import net.h31ix.anticheat.util.yaml.CommentedConfiguration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
@@ -12,7 +12,6 @@ public class BlockHardnessTest {
|
||||
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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
package net.h31ix.anticheat.update;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.IllegalThreadStateException;
|
||||
import java.lang.Runnable;
|
||||
import java.lang.Thread;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
@@ -186,7 +186,9 @@ public enum BlockHardness {
|
||||
|
||||
public static BlockHardness getHardness(Material m) {
|
||||
for (BlockHardness e : BlockHardness.values()) {
|
||||
if (e.mat.equals(m)) return e;
|
||||
if (e.mat.equals(m)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.h31ix.anticheat.Anticheat;
|
||||
import net.h31ix.anticheat.manage.AnticheatManager;
|
||||
import net.h31ix.anticheat.util.yaml.CommentedConfiguration;
|
||||
|
||||
@@ -21,7 +21,6 @@ package net.h31ix.anticheat.util;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -18,11 +18,10 @@
|
||||
|
||||
package net.h31ix.anticheat.util;
|
||||
|
||||
import net.h31ix.anticheat.Anticheat;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.h31ix.anticheat.Anticheat;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Level {
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
public final class Utilities {
|
||||
@@ -108,9 +107,11 @@ public final class Utilities {
|
||||
public static boolean isHoveringOverWater(Location player, int blocks) {
|
||||
for (int i = player.getBlockY(); i > player.getBlockY() - blocks; i--) {
|
||||
Block newloc = (new Location(player.getWorld(), player.getBlockX(), i, player.getBlockZ())).getBlock();
|
||||
if (newloc.getTypeId() != 0 && newloc.isLiquid())
|
||||
if (newloc.getTypeId() != 0 && newloc.isLiquid()) {
|
||||
return true;
|
||||
else if (newloc.getTypeId() != 0) return false;
|
||||
} else if (newloc.getTypeId() != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -193,12 +194,15 @@ public final class Utilities {
|
||||
|
||||
result += 150;
|
||||
|
||||
if (enchantlvl > 0)
|
||||
if (enchantlvl > 0) {
|
||||
result /= enchantlvl * enchantlvl + 1L;
|
||||
}
|
||||
|
||||
if (result > 25000)
|
||||
if (result > 25000) {
|
||||
result = 25000;
|
||||
else if (result < 0) result = 0;
|
||||
} else if (result < 0) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -206,7 +210,9 @@ public final class Utilities {
|
||||
public static boolean blockIsnt(Block block, Material[] materials) {
|
||||
Material type = block.getType();
|
||||
for(Material m : materials) {
|
||||
if(m == type) return false;
|
||||
if(m == type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user