diff --git a/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java b/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java index 7972cf8..5f20cff 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/Backend.java @@ -19,7 +19,8 @@ package net.gravitydevelopment.anticheat.check; import net.gravitydevelopment.anticheat.AntiCheat; -import net.gravitydevelopment.anticheat.config.files.Lang; +import net.gravitydevelopment.anticheat.config.Configuration; +import net.gravitydevelopment.anticheat.config.providers.Lang; import net.gravitydevelopment.anticheat.config.providers.Magic; import net.gravitydevelopment.anticheat.manage.AntiCheatManager; import net.gravitydevelopment.anticheat.util.User; @@ -100,8 +101,9 @@ public class Backend { transparent.add((byte) -1); } - public void updateMagic(Magic magic) { - this.magic = magic; + public void updateConfig(Configuration config) { + magic = config.getMagic(); + lang = config.getLang(); } public void resetChatLevel(User user) { @@ -768,10 +770,10 @@ public class Backend { } else { if (manager.getConfiguration().getConfig().blockChatSpamRepetition.getValue() && m.equalsIgnoreCase(msg) && i == 1) { manager.getLoggingManager().logFineInfo(player.getName() + " spam-repeated \"" + msg + "\""); - return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue()); + return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING()); } else if (manager.getConfiguration().getConfig().blockChatSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN() * 2) { manager.getLoggingManager().logFineInfo(player.getName() + " spammed quickly \"" + msg + "\""); - return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue()); + return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING()); } } } @@ -796,9 +798,9 @@ public class Backend { break; } else { if (manager.getConfiguration().getConfig().blockCommandSpamRepetition.getValue() && m.equalsIgnoreCase(cmd) && i == 1) { - return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue()); + return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING()); } else if (manager.getConfiguration().getConfig().blockCommandSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN() * 2) { - return new CheckResult(CheckResult.Result.FAILED, lang.spamWarning.getValue()); + return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING()); } } } @@ -1069,7 +1071,7 @@ public class Backend { int level = chatLevel.containsKey(user.getName()) ? chatLevel.get(user.getName()) : 0; if (player != null && player.isOnline() && level >= magic.CHAT_ACTION_ONE_LEVEL()) { String event = level >= magic.CHAT_ACTION_TWO_LEVEL() ? manager.getConfiguration().getConfig().chatSpamActionTwo.getValue() : manager.getConfiguration().getConfig().chatSpamActionOne.getValue(); - manager.getUserManager().execute(manager.getUserManager().getUser(player.getName()), Utilities.stringToList(event), CheckType.CHAT_SPAM, lang.spamKickReason.getValue(), Utilities.stringToList(lang.spamWarning.getValue()), lang.spamBanReason.getValue()); + manager.getUserManager().execute(manager.getUserManager().getUser(player.getName()), Utilities.stringToList(event), CheckType.CHAT_SPAM, lang.SPAM_KICK_REASON(), Utilities.stringToList(lang.SPAM_WARNING()), lang.SPAM_BAN_REASON()); } chatLevel.put(user.getName(), level + 1); } @@ -1079,7 +1081,7 @@ public class Backend { int level = commandLevel.containsKey(user.getName()) ? commandLevel.get(user.getName()) : 0; if (player != null && player.isOnline() && level >= magic.COMMAND_ACTION_ONE_LEVEL()) { String event = level >= magic.COMMAND_ACTION_TWO_LEVEL() ? manager.getConfiguration().getConfig().commandSpamActionTwo.getValue() : manager.getConfiguration().getConfig().commandSpamActionOne.getValue(); - manager.getUserManager().execute(manager.getUserManager().getUser(player.getName()), Utilities.stringToList(event), CheckType.COMMAND_SPAM, lang.spamKickReason.getValue(), Utilities.stringToList(lang.spamWarning.getValue()), lang.spamBanReason.getValue()); + manager.getUserManager().execute(manager.getUserManager().getUser(player.getName()), Utilities.stringToList(event), CheckType.COMMAND_SPAM, lang.SPAM_KICK_REASON(), Utilities.stringToList(lang.SPAM_WARNING()), lang.SPAM_BAN_REASON()); } commandLevel.put(user.getName(), level + 1); } diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java index 2f02ec1..3bfe232 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/Configuration.java @@ -21,19 +21,9 @@ package net.gravitydevelopment.anticheat.config; import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.config.files.Config; import net.gravitydevelopment.anticheat.config.files.Enterprise; -import net.gravitydevelopment.anticheat.config.files.Lang; -import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLGroupsHolder; -import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLLevelsHolder; -import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLMagicHolder; -import net.gravitydevelopment.anticheat.config.holders.mysql.MySQLRulesHolder; -import net.gravitydevelopment.anticheat.config.holders.yaml.YamlGroupsHolder; -import net.gravitydevelopment.anticheat.config.holders.yaml.YamlLevelsHolder; -import net.gravitydevelopment.anticheat.config.holders.yaml.YamlMagicHolder; -import net.gravitydevelopment.anticheat.config.holders.yaml.YamlRulesHolder; -import net.gravitydevelopment.anticheat.config.providers.Groups; -import net.gravitydevelopment.anticheat.config.providers.Levels; -import net.gravitydevelopment.anticheat.config.providers.Magic; -import net.gravitydevelopment.anticheat.config.providers.Rules; +import net.gravitydevelopment.anticheat.config.holders.mysql.*; +import net.gravitydevelopment.anticheat.config.holders.yaml.*; +import net.gravitydevelopment.anticheat.config.providers.*; import net.gravitydevelopment.anticheat.manage.AntiCheatManager; import org.bukkit.configuration.file.YamlConfiguration; @@ -47,8 +37,8 @@ public class Configuration { private AntiCheatManager manager; private Config config; private Enterprise enterprise; - private Lang lang; + private Lang lang; private Magic magic; private Groups groups; private Levels levels; @@ -64,12 +54,10 @@ public class Configuration { plugin.setVerbose(config.verboseStartup.getValue()); // Now load others enterprise = new Enterprise(plugin, this); - lang = new Lang(plugin, this); flatfiles = new ArrayList() {{ add(config); add(enterprise); - add(lang); }}; dbfiles = new ArrayList(); @@ -106,6 +94,20 @@ public class Configuration { flatfiles.add((YamlMagicHolder) handler); } + if (config.enterprise.getValue() && enterprise.configLang.getValue()) { + handler = new MySQLLangHolder(this); + lang = (Lang) Proxy.newProxyInstance(Lang.class.getClassLoader(), + new Class[] { Lang.class }, + handler); + dbfiles.add((MySQLLangHolder) handler); + } else { + handler = new YamlLangHolder(plugin, this); + lang = (Lang) Proxy.newProxyInstance(Lang.class.getClassLoader(), + new Class[] { Lang.class }, + handler); + flatfiles.add((YamlLangHolder) handler); + } + if (config.enterprise.getValue() && enterprise.syncLevels.getValue()) { levels = new MySQLLevelsHolder(this); dbfiles.add((MySQLLevelsHolder) levels); @@ -130,7 +132,7 @@ public class Configuration { table.load(); } if (manager.getBackend() != null) { - manager.getBackend().updateMagic(magic); + manager.getBackend().updateConfig(this); } } diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/ConfigurationTable.java b/src/main/java/net/gravitydevelopment/anticheat/config/ConfigurationTable.java index 502761c..868dec9 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/ConfigurationTable.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/ConfigurationTable.java @@ -18,7 +18,9 @@ package net.gravitydevelopment.anticheat.config; +import net.gravitydevelopment.anticheat.AntiCheat; import net.gravitydevelopment.anticheat.util.enterprise.Database; +import org.bukkit.Bukkit; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -53,6 +55,16 @@ public class ConfigurationTable { // Nothing to do } + public void reload() { + // For after sql inserts have been made + Bukkit.getScheduler().runTask(AntiCheat.getPlugin(), new Runnable() { + @Override + public void run() { + load(); + } + }); + } + public Database getDatabase() { return database; } diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/files/Enterprise.java b/src/main/java/net/gravitydevelopment/anticheat/config/files/Enterprise.java index c7c36d6..6e0d286 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/files/Enterprise.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/files/Enterprise.java @@ -39,6 +39,7 @@ public class Enterprise extends ConfigurationFile { public ConfigValue configGroups; public ConfigValue configRules; public ConfigValue configMagic; + public ConfigValue configLang; public Database database; @@ -60,6 +61,7 @@ public class Enterprise extends ConfigurationFile { configGroups = new ConfigValue("config.groups"); configRules = new ConfigValue("config.rules"); configMagic = new ConfigValue("config.magic"); + configLang = new ConfigValue("config.lang"); ConfigValue databaseType = new ConfigValue("database.type"); ConfigValue databaseHostname = new ConfigValue("database.hostname"); diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/files/Lang.java b/src/main/java/net/gravitydevelopment/anticheat/config/files/Lang.java deleted file mode 100644 index bbac12c..0000000 --- a/src/main/java/net/gravitydevelopment/anticheat/config/files/Lang.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * AntiCheat for Bukkit. - * Copyright (C) 2012-2014 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 . - */ - -package net.gravitydevelopment.anticheat.config.files; - -import net.gravitydevelopment.anticheat.AntiCheat; -import net.gravitydevelopment.anticheat.config.Configuration; -import net.gravitydevelopment.anticheat.config.ConfigurationFile; - -import java.util.List; - -public class Lang extends ConfigurationFile { - - public static final String FILENAME = "lang.yml"; - - public ConfigValue> alert; - public ConfigValue> playerWarning; - public ConfigValue spamWarning; - public ConfigValue spamKickReason; - public ConfigValue spamBanReason; - public ConfigValue spamKickBroadcast; - public ConfigValue spamBanBroadcast; - public ConfigValue banReason; - public ConfigValue banBroadcast; - public ConfigValue kickReason; - public ConfigValue kickBroadcast; - - public Lang(AntiCheat plugin, Configuration config) { - super(plugin, config, FILENAME); - } - - @Override - public void open() { - alert = new ConfigValue>("alert"); - playerWarning = new ConfigValue>("warning.player_warning"); - spamWarning = new ConfigValue("chat.warning"); - spamKickReason = new ConfigValue("chat.kick_reason"); - spamBanReason = new ConfigValue("chat.ban_reason"); - spamKickBroadcast = new ConfigValue("chat.kick_broadcast"); - spamBanBroadcast = new ConfigValue("chat.ban_broadcast"); - banReason = new ConfigValue("ban.ban_reason"); - banBroadcast = new ConfigValue("ban.ban_broadcast"); - kickReason = new ConfigValue("kick.kick_reason"); - kickBroadcast = new ConfigValue("kick.kick_broadcast"); - } -} diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLLangHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLLangHolder.java new file mode 100644 index 0000000..b2bd4d7 --- /dev/null +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLLangHolder.java @@ -0,0 +1,156 @@ +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012-2014 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 . + */ + +package net.gravitydevelopment.anticheat.config.holders.mysql; + +import net.gravitydevelopment.anticheat.AntiCheat; +import net.gravitydevelopment.anticheat.config.Configuration; +import net.gravitydevelopment.anticheat.config.ConfigurationTable; +import net.gravitydevelopment.anticheat.config.providers.Lang; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class MySQLLangHolder extends ConfigurationTable implements InvocationHandler { + + private static final String TABLE = "lang"; + + private HashMap stringValues; + private HashMap> listValues; + + private FileConfiguration defaults; + + public MySQLLangHolder(Configuration config) { + super(config, TABLE); + } + + @Override + public void open() { + defaults = YamlConfiguration.loadConfiguration(AntiCheat.getPlugin().getResource("lang.yml")); + + stringValues = new HashMap(); + listValues = new HashMap>(); + + String sqlCreate = "CREATE TABLE " + getFullTable() + "(" + + " `id` INT NOT NULL AUTO_INCREMENT," + + " `key` VARCHAR(45) NOT NULL," + + " `value` TEXT," + + " PRIMARY KEY (`id`));"; + + String sqlPopulate = "INSERT INTO " + getFullTable() + + " (`key`, `value`) " + + "SELECT t.*" + + "FROM ("; + + Method[] methods = Lang.class.getMethods(); + for (int i=1;i<=methods.length;i++) { + sqlPopulate += "(SELECT ? as `key`, ? as `value`)"; + if (i < methods.length) sqlPopulate += " UNION ALL "; + } + sqlPopulate += ") t;"; + + String sqlLoad = "SELECT * FROM " + getFullTable(); + + try { + PreparedStatement insert = getConnection().prepareStatement(sqlPopulate); + int strings = 1; + for (int i=1;i<=methods.length;i++) { + String key = methods[i-1].getName(); + String value = defaults.getString(key); + insert.setString(strings, key); + strings++; + insert.setString(strings, value); + strings++; + } + + if (!tableExists()) { + getConnection().prepareStatement(sqlCreate).executeUpdate(); + insert.executeUpdate(); + getConnection().commit(); + } + + ResultSet set = getConnection().prepareStatement(sqlLoad).executeQuery(); + while (set.next()) { + String key = set.getString("key"); + String value = set.getString("value"); + if (value.matches("^\\[.*\\]$")) { + listValues.put(key, getList(value)); + } else { + stringValues.put(key, value); + } + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public Object invoke(Object proxy, Method method, Object[] args) { + String key = method.getName(); + + if (method.getReturnType() == List.class) { + if (listValues.containsKey(key)) { + return listValues.get(key); + } else if (defaults.getString(key) != null) { + String value = defaults.getString(key); + try { + PreparedStatement s = getConnection().prepareStatement("INSERT INTO " + getFullTable() + " (key, value) VALUES (?, ?)"); + s.setString(1, key); + s.setString(2, value); + } catch (SQLException e) { + e.printStackTrace(); + } + reload(); + return getList(value); + } + } else { + if (stringValues.containsKey(key)) { + return stringValues.get(key); + } else if (defaults.getString(key) != null) { + String value = defaults.getString(key); + try { + PreparedStatement s = getConnection().prepareStatement("INSERT INTO " + getFullTable() + " (key, value) VALUES (?, ?)"); + s.setString(1, key); + s.setString(2, value); + } catch (SQLException e) { + e.printStackTrace(); + } + reload(); + return value; + } + } + AntiCheat.getPlugin().getLogger().severe("The lang value " + key + " couldn't be found."); + return "Language error. See console for details."; + } + + private List getList(String value) { + value = value.substring(1, value.length() - 1); + ArrayList list = new ArrayList(); + for (String s : value.split(", ")) { + list.add(s); + } + return list; + } +} diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLMagicHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLMagicHolder.java index 48b2c7f..c021dcc 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLMagicHolder.java +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/mysql/MySQLMagicHolder.java @@ -59,8 +59,9 @@ public class MySQLMagicHolder extends ConfigurationTable implements InvocationHa " PRIMARY KEY (`id`));"; String sqlPopulate = "INSERT INTO " + getFullTable() + - " SELECT t.*" + - " FROM ("; + " (`key`, `value_int`, `value_double`) " + + "SELECT t.*" + + "FROM ("; Method[] methods = Magic.class.getMethods(); for (int i=1;i<=methods.length;i++) { @@ -68,8 +69,8 @@ public class MySQLMagicHolder extends ConfigurationTable implements InvocationHa Object value = defaults.get(key); String type1 = methods[i-1].getReturnType().getSimpleName(); String type2 = type1.equals("int") ? "double" : "int"; - sqlPopulate += "(SELECT " + i + " as id, '" + key + "' as `key`, " + (type1.equals("int") ? value : "null") + " as value_" + type1 + ", " + (type1.equals("double") ? value : "null") + " as value_" + type2 + ") "; - if (i < methods.length) sqlPopulate += "UNION ALL "; + sqlPopulate += "(SELECT '" + key + "' as `key`, " + (type1.equals("int") ? value : "null") + " as value_" + type1 + ", " + (type1.equals("double") ? value : "null") + " as value_" + type2 + ")"; + if (i < methods.length) sqlPopulate += " UNION ALL "; } sqlPopulate += ") t;"; @@ -114,29 +115,32 @@ public class MySQLMagicHolder extends ConfigurationTable implements InvocationHa public Object invoke(Object proxy, Method method, Object[] args) { String key = method.getName(); - if (ints.containsKey(key)) return ints.get(key).intValue(); - else if (doubles.containsKey(key)) return doubles.get(key).doubleValue(); - else { + if (ints.containsKey(key)) { + return ints.get(key).intValue(); + } else if (doubles.containsKey(key)) { + return doubles.get(key).doubleValue(); + } else if (defaults.getString(key) != null ) { if (method.getReturnType().getSimpleName().equals("int")) { int value = defaults.getInt(key); try { - getConnection().prepareStatement("INSERT INTO " + getFullTable() + " (value_int) VALUES (" + value + ")").executeUpdate(); + getConnection().prepareStatement("INSERT INTO " + getFullTable() + " (key, value_int) VALUES ('" + key + "' , '" + value + "')").executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } + reload(); return value; } else if (method.getReturnType().getSimpleName().equals("double")) { double value = defaults.getDouble(key); try { - getConnection().prepareStatement("INSERT INTO " + getFullTable() + " (key, value_double) VALUES (" + key + " , " + value + ")").executeUpdate(); + getConnection().prepareStatement("INSERT INTO " + getFullTable() + " (key, value_double) VALUES ('" + key + "' , '" + value + "')").executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } + reload(); return value; - } else { - AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found."); - return -1; } } + AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found."); + return 0; } } diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlLangHolder.java b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlLangHolder.java new file mode 100644 index 0000000..10ee77c --- /dev/null +++ b/src/main/java/net/gravitydevelopment/anticheat/config/holders/yaml/YamlLangHolder.java @@ -0,0 +1,68 @@ +/* + * AntiCheat for Bukkit. + * Copyright (C) 2012-2014 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 . + */ + +package net.gravitydevelopment.anticheat.config.holders.yaml; + +import net.gravitydevelopment.anticheat.AntiCheat; +import net.gravitydevelopment.anticheat.config.Configuration; +import net.gravitydevelopment.anticheat.config.ConfigurationFile; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.List; + +public class YamlLangHolder extends ConfigurationFile implements InvocationHandler { + + public static final String FILENAME = "lang.yml"; + + public YamlLangHolder(AntiCheat plugin, Configuration config) { + super(plugin, config, FILENAME); + } + + @Override + public void open() { + if (new ConfigValue("chat.ban_broadcast").getValue() != null) { + update(); + } + } + + private void update() { + new ConfigValue>("ALERT").setValue(new ConfigValue>("alert").getValue()); + new ConfigValue>("WARNING").setValue(new ConfigValue>("warning.player_warning").getValue()); + new ConfigValue>("alert").setValue(null); + new ConfigValue>("warning.player_warning").setValue(null); + updateValue("ban.ban_reason", "BAN_REASON"); + updateValue("ban.ban_broadcast", "BAN_BROADCAST"); + updateValue("kick.kick_reason", "KICK_REASON"); + updateValue("kick.kick_broadcast", "KICK_BROADCAST"); + updateValue("chat.warning", "SPAM_WARNING"); + updateValue("chat.kick_reason", "SPAM_KICK_REASON"); + updateValue("chat.kick_broadcast", "SPAM_KICK_BROADCAST"); + updateValue("chat.ban_reason", "SPAM_BAN_REASON"); + updateValue("chat.ban_broadcast", "SPAM_BAN_BROADCAST"); + } + + private void updateValue(String oldValue, String newValue) { + new ConfigValue(newValue).setValue(new ConfigValue(oldValue).getValue()); + new ConfigValue(oldValue).setValue(null); + } + + public Object invoke(Object proxy, Method method, Object[] args) { + return new ConfigValue(method.getName()).getValue(); + } +} diff --git a/src/main/java/net/gravitydevelopment/anticheat/config/providers/Lang.java b/src/main/java/net/gravitydevelopment/anticheat/config/providers/Lang.java new file mode 100644 index 0000000..990f2ad --- /dev/null +++ b/src/main/java/net/gravitydevelopment/anticheat/config/providers/Lang.java @@ -0,0 +1,83 @@ +package net.gravitydevelopment.anticheat.config.providers; + +import java.util.List; + +public interface Lang { + + /** + * Get the alert to send when a player's hack group changes. + * + * @return Alert + */ + public List ALERT(); + + /** + * Get the warning to send players when they enter a group. + * + * @return Warning. + */ + public List WARNING(); + + /** + * Get the warning to send players for spamming. + * + * @return Spam warning. + */ + public String SPAM_WARNING(); + + /** + * Get the reason for kicking a player for spam. + * + * @return Spam kicking reason. + */ + public String SPAM_KICK_REASON(); + + /** + * Get the reason for banning a player for spam. + * + * @return Spam banning reason. + */ + public String SPAM_BAN_REASON(); + + /** + * Get the broadcast for kicking a player for spam. + * + * @return Spam kicking broadcast. + */ + public String SPAM_KICK_BROADCAST(); + + /** + * Get the broadcast for banning a player for spam. + * + * @return Spam banning broadcast. + */ + public String SPAM_BAN_BROADCAST(); + + /** + * Get the reason for banning a player. + * + * @return Banning reason. + */ + public String BAN_REASON(); + + /** + * Get the broadcast for banning a player. + * + * @return Banning broadcast. + */ + public String BAN_BROADCAST(); + + /** + * Get the reason for kicking a player. + * + * @return Kicking reason. + */ + public String KICK_REASON(); + + /** + * Get the broadcast for kicking a player. + * + * @return Kicking broadcast. + */ + public String KICK_BROADCAST(); +} diff --git a/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java b/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java index a3e4ce9..dfee2d7 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java +++ b/src/main/java/net/gravitydevelopment/anticheat/manage/UserManager.java @@ -164,7 +164,7 @@ public class UserManager { * @return check fail alert message */ public List getAlert() { - return config.getLang().alert.getValue(); + return config.getLang().ALERT(); } /** @@ -199,7 +199,7 @@ public class UserManager { * @param type The CheckType that triggered the alert */ public void execute(User user, List actions, CheckType type) { - execute(user, actions, type, config.getLang().kickReason.getValue(), config.getLang().playerWarning.getValue(), config.getLang().banReason.getValue()); + execute(user, actions, type, config.getLang().KICK_REASON(), config.getLang().WARNING(), config.getLang().BAN_REASON()); } /** @@ -227,7 +227,7 @@ public class UserManager { } } else if (event.equalsIgnoreCase("KICK")) { user.getPlayer().kickPlayer(RED + kickReason); - String msg = RED + config.getLang().kickBroadcast.getValue().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")"; + String msg = RED + config.getLang().KICK_BROADCAST().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")"; if (!msg.equals("")) { manager.log(msg); manager.playerLog(msg); @@ -242,7 +242,7 @@ public class UserManager { } else if (event.equalsIgnoreCase("BAN")) { user.getPlayer().setBanned(true); user.getPlayer().kickPlayer(RED + banReason); - String msg = RED + config.getLang().banBroadcast.getValue().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")"; + String msg = RED + config.getLang().BAN_BROADCAST().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")"; if (!msg.equals("")) { manager.log(msg); manager.playerLog(msg); diff --git a/src/main/resources/enterprise.yml b/src/main/resources/enterprise.yml index 6c64b2b..5ad3eb9 100644 --- a/src/main/resources/enterprise.yml +++ b/src/main/resources/enterprise.yml @@ -42,3 +42,5 @@ config: rules: true # Load magic configuration from the database? magic: false + # Load language configuration from the database? + lang: false diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 355796a..c7f261a 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -1,22 +1,18 @@ # AntiCheat language file # Please report any bugs: https://github.com/gravitylow/AntiCheat/issues -alert: +ALERT: - '&player has just entered the &group hack group.' - '&player''s last failed check was: &check.' - 'Type ''/anticheat report &player'' for more information.' -warning: - player_warning: - - '[AntiCheat] Hacking is not permitted.' - - '[AntiCheat] If you continue to hack, action will be taken.' -chat: - warning: 'Stop spamming the server or you will be kicked!' - kick_reason: 'Kicked for spamming' - ban_reason: 'Banned for spamming' - kick_broadcast: '&player was kicked for spamming' - ban_broadcast: '&player was banned for spamming' -ban: - ban_reason: 'Banned by AntiCheat' - ban_broadcast: '&player was banned for hacking.' -kick: - kick_reason: 'Kicked by AntiCheat' - kick_broadcast: '&player was kicked for hacking.' +WARNING: +- '[AntiCheat] Hacking is not permitted.' +- '[AntiCheat] If you continue to hack, action will be taken.' +BAN_REASON: 'Banned by AntiCheat' +BAN_BROADCAST: '&player was banned for hacking.' +KICK_REASON: 'Kicked by AntiCheat' +KICK_BROADCAST: '&player was kicked for hacking.' +SPAM_WARNING: 'Stop spamming the server or you will be kicked!' +SPAM_KICK_REASON: 'Kicked for spamming' +SPAM_KICK_BROADCAST: '&player was kicked for spamming' +SPAM_BAN_REASON: 'Banned for spamming' +SPAM_BAN_BROADCAST: '&player was banned for spamming' \ No newline at end of file