mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 22:15:28 +00:00
Implement new levels system.
This commit is contained in:
1 parent
14ca51bac9
commit
52a90b9bc8
11 files changed
+307
-131
No files matched your search
@@ -35,6 +35,7 @@
|
|||||||
<include>config.yml</include>
|
<include>config.yml</include>
|
||||||
<include>lang.yml</include>
|
<include>lang.yml</include>
|
||||||
<include>magic.yml</include>
|
<include>magic.yml</include>
|
||||||
|
<include>events.yml</include>
|
||||||
</includes>
|
</includes>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public class Anticheat extends JavaPlugin {
|
|||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save(InputStream in, File file) {
|
private boolean save(InputStream in, File file) {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
try {
|
try {
|
||||||
@@ -115,7 +115,9 @@ public class Anticheat extends JavaPlugin {
|
|||||||
if (verbose) {
|
if (verbose) {
|
||||||
getLogger().log(Level.INFO, file.getName() + " created.");
|
getLogger().log(Level.INFO, file.getName() + " created.");
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupXray() {
|
private void setupXray() {
|
||||||
@@ -210,6 +212,7 @@ public class Anticheat extends JavaPlugin {
|
|||||||
|
|
||||||
private void setupConfig() {
|
private void setupConfig() {
|
||||||
config = manager.getConfiguration();
|
config = manager.getConfiguration();
|
||||||
|
config.load();
|
||||||
checkConfigs();
|
checkConfigs();
|
||||||
verbose = config.verboseStartup();
|
verbose = config.verboseStartup();
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
@@ -231,6 +234,9 @@ public class Anticheat extends JavaPlugin {
|
|||||||
save(getResource("config.yml"), new File(getDataFolder() + "/config.yml"));
|
save(getResource("config.yml"), new File(getDataFolder() + "/config.yml"));
|
||||||
save(getResource("lang.yml"), new File(getDataFolder() + "/lang.yml"));
|
save(getResource("lang.yml"), new File(getDataFolder() + "/lang.yml"));
|
||||||
save(getResource("magic.yml"), new File(getDataFolder() + "/magic.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() {
|
public static Anticheat getPlugin() {
|
||||||
|
|||||||
@@ -359,12 +359,11 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
public void sendPlayerReport(CommandSender cs, List<CheckType> types, User user, int page) {
|
public void sendPlayerReport(CommandSender cs, List<CheckType> types, User user, int page) {
|
||||||
String name = user.getName();
|
String name = user.getName();
|
||||||
int pages = (int) Math.ceil(((float) types.size()) / 6);
|
int pages = (int) Math.ceil(((float) types.size()) / 6);
|
||||||
int level = user.getLevel();
|
String levelString = ChatColor.GREEN+"Low";
|
||||||
String levelString = GREEN + "Low";
|
for(Level level : CONFIG.getLevels()) {
|
||||||
if (level >= CONFIG.highThreshold()) {
|
if(level.getValue() == user.getLevel()) {
|
||||||
levelString = RED + "High";
|
levelString = level.getColor()+level.getName();
|
||||||
} else if (level >= CONFIG.medThreshold()) {
|
}
|
||||||
levelString = YELLOW + "Medium";
|
|
||||||
}
|
}
|
||||||
if (page <= pages && page > 0) {
|
if (page <= pages && page > 0) {
|
||||||
cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------");
|
cs.sendMessage("--------------------[" + GREEN + "REPORT[" + page + "/" + pages + "]" + WHITE + "]---------------------");
|
||||||
@@ -410,11 +409,13 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
|
public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
if (args[0].equalsIgnoreCase("report")) {
|
if (args[0].equalsIgnoreCase("report")) {
|
||||||
if (args[1].equalsIgnoreCase("low") || args[1].equalsIgnoreCase("medium") || args[1].equalsIgnoreCase("high")) {
|
for(Level level : CONFIG.getLevels()) {
|
||||||
handleReport(cs, args);
|
if(args[1].equalsIgnoreCase(level.getName())) {
|
||||||
} else {
|
handleReport(cs, args);
|
||||||
handlePlayerReport(cs, args);
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
handlePlayerReport(cs, args);
|
||||||
}
|
}
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
if (args[0].equalsIgnoreCase("log")) {
|
if (args[0].equalsIgnoreCase("log")) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package net.h31ix.anticheat.manage;
|
|||||||
|
|
||||||
import net.h31ix.anticheat.Anticheat;
|
import net.h31ix.anticheat.Anticheat;
|
||||||
import net.h31ix.anticheat.util.Configuration;
|
import net.h31ix.anticheat.util.Configuration;
|
||||||
|
import net.h31ix.anticheat.util.Level;
|
||||||
import net.h31ix.anticheat.util.Utilities;
|
import net.h31ix.anticheat.util.Utilities;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -33,11 +34,11 @@ import java.util.List;
|
|||||||
public class User {
|
public class User {
|
||||||
private final String name;
|
private final String name;
|
||||||
private int level = 0;
|
private int level = 0;
|
||||||
private int high;
|
|
||||||
private int med;
|
|
||||||
private Location goodLocation;
|
private Location goodLocation;
|
||||||
private boolean silentMode;
|
private boolean silentMode;
|
||||||
private List<ItemStack> inventorySnapshot = null;
|
private List<ItemStack> inventorySnapshot = null;
|
||||||
|
private Configuration config = Anticheat.getManager().getConfiguration();
|
||||||
|
private List<Level> levels = new ArrayList<Level>();
|
||||||
|
|
||||||
public User(String name) {
|
public User(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -51,10 +52,9 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getConfigInfo() {
|
private void getConfigInfo() {
|
||||||
Configuration config = Anticheat.getManager().getConfiguration();
|
config = Anticheat.getManager().getConfiguration();
|
||||||
silentMode = config.silentMode();
|
silentMode = config.silentMode();
|
||||||
med = config.medThreshold();
|
levels = config.getLevels();
|
||||||
high = config.highThreshold();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -76,12 +76,13 @@ public class User {
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
level++;
|
level++;
|
||||||
if (level == med) {
|
for(Level l : levels) {
|
||||||
Anticheat.getManager().getUserManager().alertMed(this, type);
|
if(l.getValue() == level) {
|
||||||
} else if (level == high) {
|
Anticheat.getManager().getUserManager().alert(this, l, type);
|
||||||
Anticheat.getManager().getUserManager().alertHigh(this, type);
|
if(l.getValue() == config.getHighestLevel()) {
|
||||||
// Prevent the player from going over the high limit
|
level = l.getValue() - 10;
|
||||||
level = high - 10;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -95,7 +96,7 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(int level) {
|
public void setLevel(int level) {
|
||||||
if (level > 0 && level <= high) {
|
if (level > 0 && level <= config.getHighestLevel()) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.h31ix.anticheat.util.Configuration;
|
import net.h31ix.anticheat.util.Configuration;
|
||||||
import net.h31ix.anticheat.util.Language;
|
import net.h31ix.anticheat.util.Language;
|
||||||
|
import net.h31ix.anticheat.util.Level;
|
||||||
import net.h31ix.anticheat.util.Utilities;
|
import net.h31ix.anticheat.util.Utilities;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@@ -103,57 +104,46 @@ public class UserManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alertMed(User user, CheckType type) {
|
public void alert(User user, Level level, CheckType type) {
|
||||||
List<String> messageArray = lang.getMediumAlert();
|
List<String> messageArray = lang.getAlert();
|
||||||
for (int i = 0; i < messageArray.size(); i++) {
|
for (int i = 0; i < messageArray.size(); i++) {
|
||||||
String message = messageArray.get(i);
|
String message = messageArray.get(i);
|
||||||
message = message.replaceAll("&player", GOLD + user.getName() + GRAY);
|
message = message.replaceAll("&player", GOLD + user.getName() + GRAY);
|
||||||
message = message.replaceAll("&check", GOLD + CheckType.getName(type) + GRAY);
|
message = message.replaceAll("&check", GOLD + CheckType.getName(type) + GRAY);
|
||||||
message = message.replaceAll("medium", YELLOW + "medium" + GRAY);
|
message = message.replaceAll("&level", level.getColor() + level.getName() + GRAY);
|
||||||
messageArray.set(i, message);
|
messageArray.set(i, message);
|
||||||
}
|
}
|
||||||
Utilities.alert(messageArray);
|
Utilities.alert(messageArray);
|
||||||
execute(user, config.mediumEvent());
|
execute(user, level.getActions(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void alertHigh(User user, CheckType type) {
|
public void execute(User user, List<String> actions, CheckType type) {
|
||||||
List<String> messageArray = lang.getHighAlert();
|
|
||||||
for (int i = 0; i < messageArray.size(); i++) {
|
|
||||||
String message = messageArray.get(i);
|
|
||||||
message = message.replaceAll("&player", GOLD + user.getName() + GRAY);
|
|
||||||
message = message.replaceAll("&check", GOLD + CheckType.getName(type) + GRAY);
|
|
||||||
message = message.replaceAll("high", RED + "high" + GRAY);
|
|
||||||
messageArray.set(i, message);
|
|
||||||
}
|
|
||||||
Utilities.alert(messageArray);
|
|
||||||
execute(user, config.highEvent());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute(User user, String event) {
|
|
||||||
final String name = user.getName();
|
final String name = user.getName();
|
||||||
event = event.replaceAll("&player", name).replaceAll("&world", user.getPlayer().getWorld().getName());
|
for(String event : actions) {
|
||||||
|
event = event.replaceAll("&player", name).replaceAll("&world", user.getPlayer().getWorld().getName()).replaceAll("&check", type.name());
|
||||||
|
|
||||||
if (event.startsWith("COMMAND[")) {
|
if (event.startsWith("COMMAND[")) {
|
||||||
for(String cmd : Utilities.getCommands(event)) {
|
for(String cmd : Utilities.getCommands(event)) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||||
}
|
}
|
||||||
} else if (event.equalsIgnoreCase("KICK")) {
|
} else if (event.equalsIgnoreCase("KICK")) {
|
||||||
user.getPlayer().kickPlayer(RED + lang.getKickReason());
|
user.getPlayer().kickPlayer(RED + lang.getKickReason());
|
||||||
String msg = RED + lang.getKickBroadcast().replaceAll("&player", name);
|
String msg = RED + lang.getKickBroadcast().replaceAll("&player", name);
|
||||||
if (!msg.equals("")) {
|
if (!msg.equals("")) {
|
||||||
Bukkit.broadcastMessage(msg);
|
Bukkit.broadcastMessage(msg);
|
||||||
}
|
}
|
||||||
} else if (event.equalsIgnoreCase("WARN")) {
|
} else if (event.equalsIgnoreCase("WARN")) {
|
||||||
List<String> message = lang.getWarning();
|
List<String> message = lang.getWarning();
|
||||||
for (String string : message) {
|
for (String string : message) {
|
||||||
user.getPlayer().sendMessage(RED + string);
|
user.getPlayer().sendMessage(RED + string);
|
||||||
}
|
}
|
||||||
} else if (event.equalsIgnoreCase("BAN")) {
|
} else if (event.equalsIgnoreCase("BAN")) {
|
||||||
user.getPlayer().setBanned(true);
|
user.getPlayer().setBanned(true);
|
||||||
user.getPlayer().kickPlayer(RED + lang.getBanReason());
|
user.getPlayer().kickPlayer(RED + lang.getBanReason());
|
||||||
String msg = RED + lang.getBanBroadcast().replaceAll("&player", name);
|
String msg = RED + lang.getBanBroadcast().replaceAll("&player", name);
|
||||||
if (!msg.equals("")) {
|
if (!msg.equals("")) {
|
||||||
Bukkit.broadcastMessage(msg);
|
Bukkit.broadcastMessage(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,13 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.h31ix.anticheat.Anticheat;
|
||||||
import net.h31ix.anticheat.manage.AnticheatManager;
|
import net.h31ix.anticheat.manage.AnticheatManager;
|
||||||
import net.h31ix.anticheat.util.yaml.CommentedConfiguration;
|
import net.h31ix.anticheat.util.yaml.CommentedConfiguration;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@@ -37,9 +39,11 @@ public class Configuration {
|
|||||||
private File levelFile = null;
|
private File levelFile = null;
|
||||||
private File langFile = null;
|
private File langFile = null;
|
||||||
private File magicFile = null;
|
private File magicFile = null;
|
||||||
|
private File eventsFile = null;
|
||||||
private CommentedConfiguration config;
|
private CommentedConfiguration config;
|
||||||
private FileConfiguration level;
|
private FileConfiguration level;
|
||||||
private FileConfiguration magic;
|
private FileConfiguration magic;
|
||||||
|
private FileConfiguration events;
|
||||||
private boolean logConsole;
|
private boolean logConsole;
|
||||||
private boolean logXRay;
|
private boolean logXRay;
|
||||||
private boolean alertXRay;
|
private boolean alertXRay;
|
||||||
@@ -52,16 +56,14 @@ public class Configuration {
|
|||||||
private boolean trackCreativeXRay;
|
private boolean trackCreativeXRay;
|
||||||
private boolean eventChains;
|
private boolean eventChains;
|
||||||
private int fileLogLevel = 0;
|
private int fileLogLevel = 0;
|
||||||
private int medThreshold = 0;
|
|
||||||
private int highThreshold = 0;
|
|
||||||
private String updateFolder;
|
private String updateFolder;
|
||||||
private String eventMed;
|
|
||||||
private String eventHigh;
|
|
||||||
private String chatActionKick;
|
private String chatActionKick;
|
||||||
private String chatActionBan;
|
private String chatActionBan;
|
||||||
private static Language language;
|
private static Language language;
|
||||||
private List<String> exemptWorlds = new ArrayList<String>();
|
private List<String> exemptWorlds = new ArrayList<String>();
|
||||||
|
private List<Level> levels = new ArrayList<Level>();
|
||||||
private Magic magicInstance;
|
private Magic magicInstance;
|
||||||
|
private int highestLevel;
|
||||||
|
|
||||||
public Configuration(AnticheatManager instance) {
|
public Configuration(AnticheatManager instance) {
|
||||||
micromanage = instance;
|
micromanage = instance;
|
||||||
@@ -69,14 +71,19 @@ public class Configuration {
|
|||||||
levelFile = new File(micromanage.getPlugin().getDataFolder() + "/data/level.yml");
|
levelFile = new File(micromanage.getPlugin().getDataFolder() + "/data/level.yml");
|
||||||
langFile = new File(micromanage.getPlugin().getDataFolder() + "/lang.yml");
|
langFile = new File(micromanage.getPlugin().getDataFolder() + "/lang.yml");
|
||||||
magicFile = new File(micromanage.getPlugin().getDataFolder() + "/magic.yml");
|
magicFile = new File(micromanage.getPlugin().getDataFolder() + "/magic.yml");
|
||||||
load();
|
eventsFile = new File(micromanage.getPlugin().getDataFolder() + "/events.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
|
events.save(eventsFile);
|
||||||
|
level.save(levelFile);
|
||||||
|
magic.save(magicFile);
|
||||||
|
System.out.println("Saved");
|
||||||
|
System.out.println(config.get("Events.Level Medium"));
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Configuration.class.getName()).severe(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,22 +135,6 @@ public class Configuration {
|
|||||||
return eventChains;
|
return eventChains;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int medThreshold() {
|
|
||||||
return medThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int highThreshold() {
|
|
||||||
return highThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String mediumEvent() {
|
|
||||||
return eventMed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String highEvent() {
|
|
||||||
return eventHigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String chatActionKick() {
|
public String chatActionKick() {
|
||||||
return chatActionKick;
|
return chatActionKick;
|
||||||
}
|
}
|
||||||
@@ -159,12 +150,86 @@ public class Configuration {
|
|||||||
public Language getLang() {
|
public Language getLang() {
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Level> getLevels() {
|
||||||
|
return levels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHighestLevel() {
|
||||||
|
return highestLevel = -99;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateEvents() {
|
||||||
|
// Update the old event system to events.yml
|
||||||
|
CommentedConfiguration config = CommentedConfiguration.loadConfig(configFile);
|
||||||
|
events = YamlConfiguration.loadConfiguration(Anticheat.getPlugin().getResource("events.yml"));
|
||||||
|
String medium = config.getString("Events.Level Medium");
|
||||||
|
String high = config.getString("Events.Level High");
|
||||||
|
int medValue = config.getString("Events.Medium threshold") != null ? config.getInt("Events.Medium threshold") : -1;
|
||||||
|
int highValue = config.getString("Events.High threshold") != null ? config.getInt("Events.High threshold") : -1;
|
||||||
|
|
||||||
|
System.out.println("Set event null");
|
||||||
|
config.set("Events", null);
|
||||||
|
System.out.println(config.get("Events.Level Medium"));
|
||||||
|
Level mediumLevel = new Level("Medium", medValue != -1 ? medValue : 20, ChatColor.YELLOW);
|
||||||
|
Level highLevel = new Level("High", highValue != -1 ? highValue : 50, ChatColor.RED);
|
||||||
|
Level customLevel = new Level("Custom", -1, ChatColor.GREEN);
|
||||||
|
mediumLevel.addAction(medium != null ? medium : "WARN");
|
||||||
|
highLevel.addAction(high != null ? high : "KICK");
|
||||||
|
customLevel.addAction("COMMAND[ban &player;say hello world]");
|
||||||
|
|
||||||
|
levels.add(mediumLevel);
|
||||||
|
levels.add(highLevel);
|
||||||
|
levels.add(customLevel);
|
||||||
|
|
||||||
|
writeEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeEvents() {
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
List<String> list2 = new ArrayList<String>();
|
||||||
|
for(Level level : levels) {
|
||||||
|
list.add(level.toString());
|
||||||
|
for(String string : level.getActions()) {
|
||||||
|
list2.add(level.getName()+": "+string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
events.set("levels", list);
|
||||||
|
events.set("actions", list2);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readEvents() {
|
||||||
|
levels = new ArrayList<Level>();
|
||||||
|
for(String string : events.getStringList("levels")) {
|
||||||
|
Level level = Level.load(string);
|
||||||
|
levels.add(level);
|
||||||
|
highestLevel = level.getValue() > highestLevel ? level.getValue() : highestLevel;
|
||||||
|
}
|
||||||
|
for(String string : events.getStringList("actions")) {
|
||||||
|
String name;
|
||||||
|
String action;
|
||||||
|
try {
|
||||||
|
name = string.split(": ")[0];
|
||||||
|
action = string.split(": ")[1];
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Anticheat.getPlugin().getLogger().warning("Couldn't load action '"+string+"' from config. Improper formatting used.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for(Level level : levels) {
|
||||||
|
if(level.getName().equalsIgnoreCase(name)) {
|
||||||
|
level.addAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final void load() {
|
public final void load() {
|
||||||
micromanage.getPlugin().checkConfigs();
|
boolean secondLoad = config != null;
|
||||||
config = CommentedConfiguration.loadConfig(configFile);
|
config = CommentedConfiguration.loadConfig(configFile);
|
||||||
level = YamlConfiguration.loadConfiguration(levelFile);
|
level = YamlConfiguration.loadConfiguration(levelFile);
|
||||||
magic = YamlConfiguration.loadConfiguration(magicFile);
|
magic = YamlConfiguration.loadConfiguration(magicFile);
|
||||||
|
events = YamlConfiguration.loadConfiguration(eventsFile);
|
||||||
language = new Language(YamlConfiguration.loadConfiguration(langFile), langFile);
|
language = new Language(YamlConfiguration.loadConfiguration(langFile), langFile);
|
||||||
updateFolder = Bukkit.getUpdateFolder();
|
updateFolder = Bukkit.getUpdateFolder();
|
||||||
|
|
||||||
@@ -176,13 +241,9 @@ public class Configuration {
|
|||||||
alertXRay = getBoolean("XRay.Alert when xray is found", false);
|
alertXRay = getBoolean("XRay.Alert when xray is found", false);
|
||||||
fileLogLevel = getInt("System.File log level", 1);
|
fileLogLevel = getInt("System.File log level", 1);
|
||||||
silentMode = getBoolean("System.Silent mode", false);
|
silentMode = getBoolean("System.Silent mode", false);
|
||||||
medThreshold = getInt("Events.Medium threshold", 20);
|
|
||||||
highThreshold = getInt("Events.High threshold", 50);
|
|
||||||
opExempt = getBoolean("System.Exempt op", false);
|
opExempt = getBoolean("System.Exempt op", false);
|
||||||
trackCreativeXRay = getBoolean("XRay.Track creative", true);
|
trackCreativeXRay = getBoolean("XRay.Track creative", true);
|
||||||
eventChains = getBoolean("System.Event Chains", true);
|
eventChains = getBoolean("System.Event Chains", true);
|
||||||
eventMed = getString("Events.Level Medium", "WARN");
|
|
||||||
eventHigh = getString("Events.Level High", "KICK");
|
|
||||||
chatActionKick = getString("Chat.Kick Action", "KICK");
|
chatActionKick = getString("Chat.Kick Action", "KICK");
|
||||||
chatActionBan = getString("Chat.Ban Action", "BAN");
|
chatActionBan = getString("Chat.Ban Action", "BAN");
|
||||||
chatSpam = getBoolean("Chat.Block chat spam", true);
|
chatSpam = getBoolean("Chat.Block chat spam", true);
|
||||||
@@ -218,6 +279,10 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exemptWorlds = config.getStringList("Disable in");
|
exemptWorlds = config.getStringList("Disable in");
|
||||||
|
|
||||||
|
if(secondLoad) {
|
||||||
|
readEvents();
|
||||||
|
}
|
||||||
// End pulling values from config
|
// End pulling values from config
|
||||||
save();
|
save();
|
||||||
magicInstance = new Magic(getMagic(), this, CommentedConfiguration.loadConfiguration(micromanage.getPlugin().getResource("magic.yml")));
|
magicInstance = new Magic(getMagic(), this, CommentedConfiguration.loadConfiguration(micromanage.getPlugin().getResource("magic.yml")));
|
||||||
@@ -259,7 +324,7 @@ public class Configuration {
|
|||||||
try {
|
try {
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Configuration.class.getName()).severe(ex.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +352,7 @@ public class Configuration {
|
|||||||
try {
|
try {
|
||||||
level.save(levelFile);
|
level.save(levelFile);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Configuration.class.getName()).severe(ex.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +360,7 @@ public class Configuration {
|
|||||||
try {
|
try {
|
||||||
newMagic.save(magicFile);
|
newMagic.save(magicFile);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(Configuration.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Configuration.class.getName()).severe(ex.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,8 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
public class Language {
|
public class Language {
|
||||||
private static String[] medAlert = null;
|
private static List<String> alert = null;
|
||||||
private static String[] highAlert = null;
|
private static List<String> warning = null;
|
||||||
private static String[] warning = null;
|
|
||||||
private static String banReason = null;
|
private static String banReason = null;
|
||||||
private static String banBroadcast = null;
|
private static String banBroadcast = null;
|
||||||
private static String kickReason = null;
|
private static String kickReason = null;
|
||||||
@@ -45,25 +44,31 @@ public class Language {
|
|||||||
private static final ChatColor GOLD = ChatColor.GOLD;
|
private static final ChatColor GOLD = ChatColor.GOLD;
|
||||||
private static final ChatColor GRAY = ChatColor.GRAY;
|
private static final ChatColor GRAY = ChatColor.GRAY;
|
||||||
private FileConfiguration file;
|
private FileConfiguration file;
|
||||||
|
private File f;
|
||||||
|
|
||||||
public Language(FileConfiguration file, File f) {
|
public Language(FileConfiguration file, File f) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
String[] temp = file.getList("alert.medium_alert").toArray(new String[file.getList("alert.medium_alert").size()]);
|
this.f = f;
|
||||||
medAlert = new String[temp.length + 2];
|
|
||||||
medAlert[0] = GOLD + "----------------------[" + GRAY + "AntiCheat" + GOLD + "]----------------------";
|
// Begin medium_alert / high_alert -> alert swap
|
||||||
for (int i = 0; i < temp.length; i++) {
|
List<String> list = file.getStringList("alert.medium_alert");
|
||||||
medAlert[i + 1] = GRAY + temp[i];
|
if(list != null && list.size() > 0) {
|
||||||
|
list.set(1, "&player has just entered the &level hack level.");
|
||||||
|
file.set("alert", null);
|
||||||
|
file.set("alert", list);
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
medAlert[medAlert.length - 1] = GOLD + "-----------------------------------------------------";
|
// End swap
|
||||||
temp = file.getList("alert.high_alert").toArray(new String[file.getList("alert.high_alert").size()]);
|
|
||||||
highAlert = new String[temp.length + 2];
|
List<String> temp = file.getStringList("alert");
|
||||||
highAlert[0] = GOLD + "----------------------[" + GRAY + "AntiCheat" + GOLD + "]----------------------";
|
alert = new ArrayList<String>();
|
||||||
for (int i = 0; i < temp.length; i++) {
|
alert.add(GOLD + "----------------------[" + GRAY + "AntiCheat" + GOLD + "]----------------------");
|
||||||
highAlert[i + 1] = GRAY + temp[i];
|
for (int i = 0; i < temp.size(); i++) {
|
||||||
|
alert.add(GRAY + temp.get(i));
|
||||||
}
|
}
|
||||||
highAlert[highAlert.length - 1] = GOLD + "-----------------------------------------------------";
|
alert.add(GOLD + "-----------------------------------------------------");
|
||||||
|
|
||||||
warning = file.getList("warning.player_warning").toArray(new String[file.getList("warning.player_warning").size()]);
|
warning = file.getStringList("warning.player_warning");
|
||||||
banReason = getString("ban.ban_reason", "Banned by AntiCheat");
|
banReason = getString("ban.ban_reason", "Banned by AntiCheat");
|
||||||
banBroadcast = getString("ban.ban_broadcast", "[AntiCheat] &player was banned for hacking.");
|
banBroadcast = getString("ban.ban_broadcast", "[AntiCheat] &player was banned for hacking.");
|
||||||
kickReason = getString("kick.kick_reason", "Kicked by AntiCheat");
|
kickReason = getString("kick.kick_reason", "Kicked by AntiCheat");
|
||||||
@@ -73,6 +78,10 @@ public class Language {
|
|||||||
chatBanReason = getString("chat.ban_reason", "Banned for spamming");
|
chatBanReason = getString("chat.ban_reason", "Banned for spamming");
|
||||||
chatKickBroadcast = getString("chat.kick_broadcast", "[AntiCheat] &player was kicked for spamming");
|
chatKickBroadcast = getString("chat.kick_broadcast", "[AntiCheat] &player was kicked for spamming");
|
||||||
chatBanBroadcast = getString("chat.ban_broadcast", "[AntiCheat] &player was banned for spamming");
|
chatBanBroadcast = getString("chat.ban_broadcast", "[AntiCheat] &player was banned for spamming");
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save() {
|
||||||
try {
|
try {
|
||||||
file.save(f);
|
file.save(f);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
@@ -80,16 +89,12 @@ public class Language {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getMediumAlert() {
|
public List<String> getAlert() {
|
||||||
return new ArrayList<String>(Arrays.asList(medAlert));
|
return alert;
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getHighAlert() {
|
|
||||||
return new ArrayList<String>(Arrays.asList(highAlert));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getWarning() {
|
public List<String> getWarning() {
|
||||||
return new ArrayList<String>(Arrays.asList(warning));
|
return warning;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBanReason() {
|
public String getBanReason() {
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* AntiCheat for Bukkit.
|
||||||
|
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.h31ix.anticheat.util;
|
||||||
|
|
||||||
|
import net.h31ix.anticheat.Anticheat;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Level {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int value;
|
||||||
|
private ChatColor color = ChatColor.RED;
|
||||||
|
private boolean customColor = false;
|
||||||
|
private List<String> actions = new ArrayList<String>();
|
||||||
|
|
||||||
|
public Level(String name, int value) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Level(String name, int value, ChatColor color) {
|
||||||
|
this(name, value);
|
||||||
|
this.color = color;
|
||||||
|
customColor = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Level(String name, int value, String color) {
|
||||||
|
this(name, value);
|
||||||
|
ChatColor c = ChatColor.valueOf(color);
|
||||||
|
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;
|
||||||
|
customColor = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAction(String string) {
|
||||||
|
actions.add(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatColor getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getActions() {
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Level load(String string) {
|
||||||
|
try {
|
||||||
|
string = string.trim();
|
||||||
|
String name = string.split(":")[0];
|
||||||
|
int level = Integer.parseInt(string.split(":")[1]);
|
||||||
|
if(string.split(":").length == 3) {
|
||||||
|
String color = string.split(":")[2];
|
||||||
|
return new Level(name, level, color);
|
||||||
|
} else {
|
||||||
|
return new Level(name, level);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Anticheat.getPlugin().getLogger().warning("An event was intialized with an invalid string: '"+string+"'");
|
||||||
|
Anticheat.getPlugin().getLogger().warning("The proper format is: 'name: threshold, color' such as 'high: 50, RED'");
|
||||||
|
Anticheat.getPlugin().getLogger().warning("This event will NOT run. ("+ex.getMessage()+")");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name + " : " + value + (customColor ? " : "+color.name() : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,12 +50,6 @@ public class CommentedConfiguration extends YamlConfiguration {
|
|||||||
comments.put("Chat:", " # Should AntiCheat block players spamming messages in chat?");
|
comments.put("Chat:", " # Should AntiCheat block players spamming messages in chat?");
|
||||||
comments.put("Block chat spam:", " # Should AntiCheat block players spamming commands in chat?");
|
comments.put("Block chat spam:", " # Should AntiCheat block players spamming commands in chat?");
|
||||||
comments.put("Block command spam:", " # Valid actions = NONE,KICK,BAN,COMMAND[command]");
|
comments.put("Block command spam:", " # Valid actions = NONE,KICK,BAN,COMMAND[command]");
|
||||||
comments.put("Ban Action:", "# Events occur when a player's hack level changes. You may configure reactions to these events here.");
|
|
||||||
comments.put("# Events occur when a player's hack level changes. You may configure reactions to these events here.", "# Valid events = NONE,WARN,KICK,BAN,COMMAND[command]");
|
|
||||||
comments.put("# Valid events = NONE,WARN,KICK,BAN,COMMAND[command]", "# Use commands like so: COMMAND[ban &player 30] or COMMAND[kick &player hacking] or COMMAND[jail &player 10]");
|
|
||||||
comments.put("# Use commands like so: COMMAND[ban &player 30] or COMMAND[kick &player hacking] or COMMAND[jail &player 10]", "# &player will be replaced with player's name, and &world will be replaced with the player's world");
|
|
||||||
comments.put("Level High:", " # How many warnings should the player get before entering medium?");
|
|
||||||
comments.put("Medium threshold:", " # How many warnings should the player get before entering high?");
|
|
||||||
comments.put("System:", " # Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so, and will have to update manually.");
|
comments.put("System:", " # Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so, and will have to update manually.");
|
||||||
comments.put("# Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so, and will have to update manually.", " # Should AntiCheat log ALL failed checks to console?");
|
comments.put("# Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so, and will have to update manually.", " # Should AntiCheat log ALL failed checks to console?");
|
||||||
comments.put("Log to console:", " # Should AntiCheat log to files?");
|
comments.put("Log to console:", " # Should AntiCheat log to files?");
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# AntiCheat configuration file
|
||||||
|
# Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/
|
||||||
|
levels:
|
||||||
|
- 'Medium : 20 : YELLOW'
|
||||||
|
- 'High : 50 : RED'
|
||||||
|
- 'Custom : -1 : GREEN'
|
||||||
|
actions:
|
||||||
|
- 'Medium: WARN'
|
||||||
|
- 'High: KICK'
|
||||||
|
- 'Custom: COMMAND[ban &player;say hello world]'
|
||||||
|
rules:
|
||||||
|
# if spider check is over 0, set level to 20. otherwise, do nothing
|
||||||
|
- 'Check:SPIDER > 0 ? Level=20 : none'
|
||||||
@@ -1,14 +1,9 @@
|
|||||||
# AntiCheat language file
|
# AntiCheat language file
|
||||||
# Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/
|
# Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/
|
||||||
alert:
|
alert:
|
||||||
medium_alert:
|
- "&player has just entered the &level hack level."
|
||||||
- "&player has just entered the medium hack level."
|
- "&player's last failed check was: &check."
|
||||||
- "&player's last failed check was: &check."
|
- "Type '/anticheat report &player' for more information."
|
||||||
- "Type '/anticheat report &player' for more information."
|
|
||||||
high_alert:
|
|
||||||
- "&player has just entered the high hack level."
|
|
||||||
- "&player's last failed check was: &check."
|
|
||||||
- "Type '/anticheat report &player' for more information."
|
|
||||||
warning:
|
warning:
|
||||||
player_warning:
|
player_warning:
|
||||||
- '[AntiCheat] Hacking is not permitted.'
|
- '[AntiCheat] Hacking is not permitted.'
|
||||||
|
|||||||
Reference in new issue
Block a user