mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 14:38:46 +00:00
Renamed package and groupId
This commit is contained in:
1 parent
21d0108c16
commit
7f13a0ad4c
78 files changed
+396
-370
No files matched your search
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.files.Config;
|
||||
import com.rammelkast.anticheatreloaded.config.files.Enterprise;
|
||||
import com.rammelkast.anticheatreloaded.config.holders.mysql.*;
|
||||
import com.rammelkast.anticheatreloaded.config.holders.yaml.*;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.*;
|
||||
import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
private AntiCheatManager manager;
|
||||
private Config config;
|
||||
private Enterprise enterprise;
|
||||
|
||||
private Lang lang;
|
||||
private Magic magic;
|
||||
private Groups groups;
|
||||
private Levels levels;
|
||||
private Rules rules;
|
||||
|
||||
private ArrayList<ConfigurationFile> flatfiles;
|
||||
private ArrayList<ConfigurationTable> dbfiles;
|
||||
|
||||
public Configuration(AntiCheat plugin, AntiCheatManager manager) {
|
||||
removeOldFiles();
|
||||
this.manager = manager;
|
||||
config = new Config(plugin, this);
|
||||
plugin.setVerbose(config.verboseStartup.getValue());
|
||||
// Now load others
|
||||
enterprise = new Enterprise(plugin, this);
|
||||
|
||||
flatfiles = new ArrayList<ConfigurationFile>() {{
|
||||
add(config);
|
||||
add(enterprise);
|
||||
}};
|
||||
|
||||
dbfiles = new ArrayList<ConfigurationTable>();
|
||||
|
||||
// The following values can be configuration from a database, or from flatfile.
|
||||
if (config.enterprise.getValue() && enterprise.configGroups.getValue()) {
|
||||
groups = new MySQLGroupsHolder(this);
|
||||
dbfiles.add((MySQLGroupsHolder) groups);
|
||||
} else {
|
||||
groups = new YamlGroupsHolder(plugin, this);
|
||||
flatfiles.add((YamlGroupsHolder) groups);
|
||||
}
|
||||
|
||||
if (config.enterprise.getValue() && enterprise.configRules.getValue()) {
|
||||
rules = new MySQLRulesHolder(this);
|
||||
dbfiles.add((MySQLRulesHolder) rules);
|
||||
} else {
|
||||
rules = new YamlRulesHolder(plugin, this);
|
||||
flatfiles.add((YamlRulesHolder) rules);
|
||||
}
|
||||
|
||||
InvocationHandler handler;
|
||||
if (config.enterprise.getValue() && enterprise.configMagic.getValue()) {
|
||||
handler = new MySQLMagicHolder(this);
|
||||
magic = (Magic) Proxy.newProxyInstance(Magic.class.getClassLoader(),
|
||||
new Class[] { Magic.class },
|
||||
handler);
|
||||
dbfiles.add((MySQLMagicHolder) handler);
|
||||
} else {
|
||||
handler = new YamlMagicHolder(plugin, this);
|
||||
magic = (Magic) Proxy.newProxyInstance(Magic.class.getClassLoader(),
|
||||
new Class[] { Magic.class },
|
||||
handler);
|
||||
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);
|
||||
} else {
|
||||
levels = new YamlLevelsHolder(plugin, this);
|
||||
flatfiles.add((YamlLevelsHolder) levels);
|
||||
}
|
||||
// End
|
||||
|
||||
for (ConfigurationFile file : flatfiles) {
|
||||
file.save();
|
||||
checkReload(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
for (ConfigurationFile file : flatfiles) {
|
||||
file.load();
|
||||
checkReload(file);
|
||||
}
|
||||
for (ConfigurationTable table : dbfiles) {
|
||||
table.load();
|
||||
}
|
||||
if (manager.getBackend() != null) {
|
||||
manager.getBackend().updateConfig(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkReload(ConfigurationFile file) {
|
||||
if (file.needsReload()) {
|
||||
file.reload();
|
||||
file.setNeedsReload(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeOldFiles() {
|
||||
ArrayList<String> removed = new ArrayList<String>();
|
||||
File configFile = new File(AntiCheat.getPlugin().getDataFolder(), "config.yml");
|
||||
if (configFile.exists() && YamlConfiguration.loadConfiguration(configFile).getString("System.Auto update") != null) {
|
||||
configFile.renameTo(new File(AntiCheat.getPlugin().getDataFolder(), "config.old"));
|
||||
removed.add("config.yml has been renamed to config.old and replaced with the new config.yml");
|
||||
}
|
||||
File eventsFile = new File(AntiCheat.getPlugin().getDataFolder(), "events.yml");
|
||||
if (eventsFile.exists()) {
|
||||
eventsFile.renameTo(new File(AntiCheat.getPlugin().getDataFolder(), "events.old"));
|
||||
removed.add("events.yml has been renamed to events.old and replaced with groups.yml and rules.yml");
|
||||
}
|
||||
if (removed.size() > 0) {
|
||||
AntiCheat.getPlugin().getLogger().info("You are upgrading from an old version of AntiCheat. Due to configuration changes, the following files have been modified:");
|
||||
for (String s : removed) {
|
||||
AntiCheat.getPlugin().getLogger().info(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Groups getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
public Rules getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
public Lang getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public Enterprise getEnterprise() {
|
||||
return enterprise;
|
||||
}
|
||||
|
||||
public Levels getLevels() {
|
||||
return levels;
|
||||
}
|
||||
|
||||
public Magic getMagic() {
|
||||
return magic;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.yaml.CommentedConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConfigurationFile {
|
||||
|
||||
private File rawFile;
|
||||
private String fileName;
|
||||
|
||||
private CommentedConfiguration configFile;
|
||||
private FileConfiguration defaultConfigFile;
|
||||
private Configuration config;
|
||||
|
||||
private AntiCheat plugin;
|
||||
|
||||
private boolean saveDefault;
|
||||
|
||||
protected boolean needsReload;
|
||||
|
||||
public ConfigurationFile(AntiCheat plugin, Configuration config, String fileName) {
|
||||
this(plugin, config, fileName, true);
|
||||
}
|
||||
|
||||
public ConfigurationFile(AntiCheat plugin, Configuration config, String fileName, boolean saveDefault) {
|
||||
this(plugin, config, fileName, saveDefault, new File(plugin.getDataFolder(), fileName));
|
||||
}
|
||||
|
||||
public ConfigurationFile(AntiCheat plugin, Configuration config, String fileName, boolean saveDefault, File rawFile) {
|
||||
// Can't change with user editing
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.fileName = fileName;
|
||||
this.rawFile = rawFile;
|
||||
this.saveDefault = saveDefault;
|
||||
|
||||
if (saveDefault) {
|
||||
defaultConfigFile = YamlConfiguration.loadConfiguration(plugin.getResource(fileName));
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
// Can change with user editing
|
||||
if (!rawFile.exists()) {
|
||||
if (saveDefault) {
|
||||
plugin.saveResource(fileName, true);
|
||||
} else {
|
||||
if (!rawFile.getParentFile().exists()) {
|
||||
rawFile.getParentFile().mkdir();
|
||||
}
|
||||
try {
|
||||
rawFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configFile = CommentedConfiguration.loadConfiguration(rawFile);
|
||||
|
||||
open();
|
||||
}
|
||||
|
||||
public void open() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
public void close() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
public void save() {
|
||||
close();
|
||||
try {
|
||||
configFile.save(rawFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
save();
|
||||
load();
|
||||
}
|
||||
|
||||
public File getRawFile() {
|
||||
return rawFile;
|
||||
}
|
||||
|
||||
public CommentedConfiguration getConfigFile() {
|
||||
return configFile;
|
||||
}
|
||||
|
||||
public FileConfiguration getDefaultConfigFile() {
|
||||
return defaultConfigFile;
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void setNeedsReload(boolean reload) {
|
||||
this.needsReload = reload;
|
||||
}
|
||||
|
||||
public boolean needsReload() {
|
||||
return needsReload;
|
||||
}
|
||||
|
||||
public class ConfigValue<T> {
|
||||
|
||||
private String path;
|
||||
|
||||
private Object value = null;
|
||||
|
||||
private boolean didLoadDefault;
|
||||
|
||||
public ConfigValue(String path) {
|
||||
this(path, true);
|
||||
}
|
||||
|
||||
public ConfigValue(String path, boolean loadDefault) {
|
||||
this.path = path;
|
||||
|
||||
if (getConfigFile().contains(path)) {
|
||||
value = getConfigFile().get(path);
|
||||
} else if (loadDefault) {
|
||||
getConfigFile().set(path, getDefaultConfigFile().get(path));
|
||||
value = getDefaultConfigFile().get(path);
|
||||
getConfigFile().set(path, value);
|
||||
save();
|
||||
didLoadDefault = true;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
public T setValue(T value) {
|
||||
getConfigFile().set(path, value);
|
||||
save();
|
||||
return value;
|
||||
}
|
||||
|
||||
public T getDefaultValue() {
|
||||
return (T) getDefaultConfigFile().get(path);
|
||||
}
|
||||
|
||||
public boolean hasValue() {
|
||||
return value != null;
|
||||
}
|
||||
|
||||
public boolean didLoadDefault() {
|
||||
return didLoadDefault;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.util.enterprise.Database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ConfigurationTable {
|
||||
|
||||
private final String table;
|
||||
private final Configuration config;
|
||||
|
||||
private Database database;
|
||||
private String prefix;
|
||||
private String serverName;
|
||||
|
||||
public ConfigurationTable(Configuration config, String table) {
|
||||
this.config = config;
|
||||
this.table = table;
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.database = config.getEnterprise().database;
|
||||
this.prefix = database.getPrefix();
|
||||
this.serverName = config.getEnterprise().serverName.getValue();
|
||||
|
||||
open();
|
||||
}
|
||||
|
||||
public void open() {
|
||||
// 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;
|
||||
}
|
||||
|
||||
public String getFullTable() {
|
||||
return prefix + table;
|
||||
}
|
||||
|
||||
public boolean tableExists() {
|
||||
try {
|
||||
return getConnection().getMetaData().getTables(null, null, getFullTable(), null).next();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUUIDFormatted(String colName) {
|
||||
String sqlSelect = "SELECT " + colName + " FROM " + getFullTable() + " LIMIT 1";
|
||||
String user;
|
||||
|
||||
try {
|
||||
ResultSet res = getConnection().prepareStatement(sqlSelect).executeQuery();
|
||||
|
||||
if (res.next() && (user = res.getString(colName)) != null) {
|
||||
try {
|
||||
return UUID.fromString(user) != null;
|
||||
} catch (IllegalArgumentException e) {}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void convertToUUID(String colName) {
|
||||
String sqlSelect = "SELECT " + colName + " FROM " + getFullTable();
|
||||
String sqlUpdate = "UPDATE " + getFullTable() + " SET " + colName + " = ? WHERE " + colName + " = ?";
|
||||
|
||||
try {
|
||||
ResultSet res = getConnection().prepareStatement(sqlSelect).executeQuery();
|
||||
|
||||
while (res.next()) {
|
||||
PreparedStatement stmt = getConnection().prepareStatement(sqlUpdate);
|
||||
stmt.setString(1, (Bukkit.getOfflinePlayer(res.getString(1)).getUniqueId().toString()));
|
||||
stmt.setString(2, res.getString(1));
|
||||
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return database.getConnection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.files;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
|
||||
|
||||
public class Config extends ConfigurationFile {
|
||||
|
||||
public static final String FILENAME = "config.yml";
|
||||
|
||||
public ConfigValue<Boolean> logToConsole;
|
||||
public ConfigValue<Boolean> autoUpdate;
|
||||
public ConfigValue<Boolean> verboseStartup;
|
||||
public ConfigValue<Boolean> silentMode;
|
||||
public ConfigValue<Boolean> exemptOp;
|
||||
|
||||
public ConfigValue<Boolean> eventChains;
|
||||
public ConfigValue<Boolean> enterprise;
|
||||
|
||||
public ConfigValue<Boolean> blockChatSpamSpeed;
|
||||
public ConfigValue<Boolean> blockCommandSpamSpeed;
|
||||
public ConfigValue<Boolean> blockChatSpamRepetition;
|
||||
public ConfigValue<Boolean> blockCommandSpamRepetition;
|
||||
public ConfigValue<String> chatSpamActionOne;
|
||||
public ConfigValue<String> chatSpamActionTwo;
|
||||
public ConfigValue<String> commandSpamActionOne;
|
||||
public ConfigValue<String> commandSpamActionTwo;
|
||||
|
||||
public ConfigValue<Boolean> logToFile;
|
||||
|
||||
public ConfigValue<List<String>> disabledWorlds;
|
||||
public ConfigValue<List<String>> disabledChecks;
|
||||
|
||||
public Config(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
logToConsole = new ConfigValue<Boolean>("system.log-to-console");
|
||||
|
||||
autoUpdate = new ConfigValue<Boolean>("system.auto-update");
|
||||
verboseStartup = new ConfigValue<Boolean>("system.verbose-startup");
|
||||
silentMode = new ConfigValue<Boolean>("system.silent-mode");
|
||||
exemptOp = new ConfigValue<Boolean>("system.exempt-op");
|
||||
eventChains = new ConfigValue<Boolean>("system.event-chains");
|
||||
enterprise = new ConfigValue<Boolean>("system.enterprise");
|
||||
|
||||
blockChatSpamSpeed = new ConfigValue<Boolean>("spam.chat.block-speed");
|
||||
blockChatSpamRepetition = new ConfigValue<Boolean>("spam.chat.block-repetition");
|
||||
chatSpamActionOne = new ConfigValue<String>("spam.chat.action-one");
|
||||
chatSpamActionTwo = new ConfigValue<String>("spam.chat.action-two");
|
||||
|
||||
blockCommandSpamSpeed = new ConfigValue<Boolean>("spam.command.block-speed");
|
||||
blockCommandSpamRepetition = new ConfigValue<Boolean>("spam.command.block-repetition");
|
||||
commandSpamActionOne = new ConfigValue<String>("spam.command.action-one");
|
||||
commandSpamActionTwo = new ConfigValue<String>("spam.command.action-two");
|
||||
|
||||
logToFile = new ConfigValue<Boolean>("system.log-to-file");
|
||||
|
||||
disabledWorlds = new ConfigValue<List<String>>("disable-in");
|
||||
disabledChecks = new ConfigValue<List<String>>("disabled-checks");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.files;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
|
||||
import com.rammelkast.anticheatreloaded.util.enterprise.Database;
|
||||
|
||||
public class Enterprise extends ConfigurationFile {
|
||||
|
||||
public static final String FILENAME = "enterprise.yml";
|
||||
|
||||
public ConfigValue<String> serverName;
|
||||
|
||||
public ConfigValue<Boolean> loggingEnabled;
|
||||
public ConfigValue<String> loggingLife;
|
||||
public ConfigValue<String> loggingInterval;
|
||||
|
||||
public ConfigValue<Boolean> syncLevels;
|
||||
public ConfigValue<String> syncInterval;
|
||||
|
||||
public ConfigValue<Boolean> configGroups;
|
||||
public ConfigValue<Boolean> configRules;
|
||||
public ConfigValue<Boolean> configMagic;
|
||||
public ConfigValue<Boolean> configLang;
|
||||
|
||||
public Database database;
|
||||
|
||||
public Enterprise(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
serverName = new ConfigValue<String>("server.name");
|
||||
|
||||
loggingEnabled = new ConfigValue<Boolean>("log.enable");
|
||||
loggingLife = new ConfigValue<String>("log.life");
|
||||
loggingInterval = new ConfigValue<String>("log.interval");
|
||||
|
||||
syncLevels = new ConfigValue<Boolean>("sync.levels");
|
||||
syncInterval = new ConfigValue<String>("sync.interval");
|
||||
|
||||
configGroups = new ConfigValue<Boolean>("config.groups");
|
||||
configRules = new ConfigValue<Boolean>("config.rules");
|
||||
configMagic = new ConfigValue<Boolean>("config.magic");
|
||||
configLang = new ConfigValue<Boolean>("config.lang");
|
||||
|
||||
ConfigValue<String> databaseType = new ConfigValue<String>("database.type");
|
||||
ConfigValue<String> databaseHostname = new ConfigValue<String>("database.hostname");
|
||||
ConfigValue<String> databaseUsername = new ConfigValue<String>("database.username");
|
||||
ConfigValue<String> databasePassword = new ConfigValue<String>("database.password");
|
||||
ConfigValue<String> databasePrefix = new ConfigValue<String>("database.prefix");
|
||||
ConfigValue<String> databaseSchema = new ConfigValue<String>("database.database");
|
||||
ConfigValue<Integer> databasePort = new ConfigValue<Integer>("database.port");
|
||||
|
||||
if (getConfiguration().getConfig().enterprise.getValue()) {
|
||||
// Convert database values to Database
|
||||
database = new Database(
|
||||
Database.DatabaseType.valueOf(databaseType.getValue()),
|
||||
databaseHostname.getValue(),
|
||||
databasePort.getValue(),
|
||||
databaseUsername.getValue(),
|
||||
databasePassword.getValue(),
|
||||
databasePrefix.getValue(),
|
||||
databaseSchema.getValue(),
|
||||
serverName.getValue(),
|
||||
loggingInterval.getValue(),
|
||||
loggingLife.getValue(),
|
||||
syncLevels.getValue(),
|
||||
syncInterval.getValue()
|
||||
);
|
||||
|
||||
database.connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.mysql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Groups;
|
||||
import com.rammelkast.anticheatreloaded.util.Group;
|
||||
|
||||
public class MySQLGroupsHolder extends ConfigurationTable implements Groups {
|
||||
|
||||
private static final String TABLE = "groups";
|
||||
|
||||
private List<Group> groups;
|
||||
private int highestLevel;
|
||||
|
||||
public MySQLGroupsHolder(Configuration config) {
|
||||
super(config, TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
highestLevel = 0;
|
||||
groups = new ArrayList<Group>();
|
||||
|
||||
String sqlCreate = "CREATE TABLE " + getFullTable() + "(" +
|
||||
" `id` INT NOT NULL AUTO_INCREMENT," +
|
||||
" `name` VARCHAR(45) NOT NULL," +
|
||||
" `level` INT NOT NULL," +
|
||||
" `color` VARCHAR(45) NOT NULL," +
|
||||
" `actions` VARCHAR(45) NOT NULL," +
|
||||
" PRIMARY KEY (`id`));";
|
||||
String sqlPopulate = "INSERT INTO " + getFullTable() +
|
||||
" SELECT t.*" +
|
||||
" FROM (" +
|
||||
" (SELECT 1 as id, 'Medium' as name, 20 as level, 'YELLOW' as color, 'WARN' as actions)" +
|
||||
" UNION ALL " +
|
||||
" (SELECT 2 as id, 'High' as name, 50 as level, 'RED' as color, 'KICK' as actions)" +
|
||||
" ) t;";
|
||||
String sqlLoad = "SELECT * FROM " + getFullTable();
|
||||
|
||||
try {
|
||||
if (!tableExists()) {
|
||||
getConnection().prepareStatement(sqlCreate).executeUpdate();
|
||||
getConnection().prepareStatement(sqlPopulate).executeUpdate();
|
||||
getConnection().commit();
|
||||
}
|
||||
|
||||
ResultSet set = getConnection().prepareStatement(sqlLoad).executeQuery();
|
||||
while (set.next()) {
|
||||
String name = set.getString("name");
|
||||
int level = set.getInt("level");
|
||||
String color = set.getString("color");
|
||||
List<String> actions = Arrays.asList(set.getString("actions").split(","));
|
||||
|
||||
groups.add(new Group(name, level, color, actions));
|
||||
if (level > highestLevel) {
|
||||
highestLevel = level;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestLevel() {
|
||||
return highestLevel;
|
||||
}
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.mysql;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Lang;
|
||||
|
||||
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<String, String> stringValues;
|
||||
private HashMap<String, List<String>> 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<String, String>();
|
||||
listValues = new HashMap<String, List<String>>();
|
||||
|
||||
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<String> getList(String value) {
|
||||
value = value.substring(1, value.length() - 1);
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for (String s : value.split(", ")) {
|
||||
list.add(s);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.mysql;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Levels;
|
||||
import com.rammelkast.anticheatreloaded.util.User;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
|
||||
|
||||
private static final String TABLE = "levels";
|
||||
private static final String MANUAL_EDIT_TAG = "MANUAL";
|
||||
|
||||
private String sqlSave;
|
||||
private String sqlLoad;
|
||||
private String sqlUpdate;
|
||||
|
||||
public MySQLLevelsHolder(Configuration config) {
|
||||
super(config, TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
sqlSave = "INSERT INTO " + getFullTable() +
|
||||
" (user, level, last_update_server) " +
|
||||
"VALUES (?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE " +
|
||||
"level = IF(last_update = ?, ?, level+?), " +
|
||||
"last_update=CURRENT_TIMESTAMP, " +
|
||||
"last_update_server=?";
|
||||
|
||||
sqlLoad = "SELECT level, last_update FROM " + getFullTable() + " " +
|
||||
"WHERE user = ?";
|
||||
|
||||
sqlUpdate = "SELECT level, last_update FROM " + getFullTable() + " " +
|
||||
"WHERE user = ? AND last_update <> ? AND last_update_server = ?";
|
||||
|
||||
String sqlCreate = "CREATE TABLE " + getFullTable() + "(" +
|
||||
" `user` VARCHAR(45) NOT NULL," +
|
||||
" `level` INT NOT NULL," +
|
||||
" `last_update` TIMESTAMP NOT NULL DEFAULT NOW()," +
|
||||
" `last_update_server` VARCHAR(45) NOT NULL," +
|
||||
" PRIMARY KEY (`user`));";
|
||||
|
||||
try {
|
||||
if (!tableExists()) {
|
||||
getConnection().prepareStatement(sqlCreate).executeUpdate();
|
||||
getConnection().commit();
|
||||
} else if (!isUUIDFormatted("user")) {
|
||||
convertToUUID("user");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLevelFromUser(final User user) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!user.isWaitingOnLevelSync()) {
|
||||
AntiCheat.debugLog("Saving level from " + user.getUUID() + ". Value: " + user.getLevel());
|
||||
try {
|
||||
PreparedStatement statement = getConnection().prepareStatement(sqlSave);
|
||||
statement.setString(1, user.getUUID().toString());
|
||||
statement.setInt(2, user.getLevel());
|
||||
statement.setString(3, getServerName());
|
||||
statement.setTimestamp(4, user.getLevelSyncTimestamp());
|
||||
statement.setInt(5, user.getLevel());
|
||||
statement.setInt(6, user.getLevel());
|
||||
statement.setString(7, getServerName());
|
||||
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
AntiCheat.getManager().getUserManager().remove(user);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadLevelToUser(final User user) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PreparedStatement statement = getConnection().prepareStatement(sqlLoad);
|
||||
statement.setString(1, user.getUUID().toString());
|
||||
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
boolean has = false;
|
||||
while (set.next()) {
|
||||
has = true;
|
||||
AntiCheat.debugLog("Syncing level to " + user.getUUID() + ". Value: " + set.getInt("level"));
|
||||
user.setLevel(set.getInt("level"));
|
||||
user.setLevelSyncTimestamp(set.getTimestamp("last_update"));
|
||||
}
|
||||
if (!has) user.setLevel(0);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLevelsFromUsers(List<User> users) {
|
||||
try {
|
||||
PreparedStatement statement = getConnection().prepareStatement(sqlSave);
|
||||
for (User user : users) {
|
||||
if (!user.isWaitingOnLevelSync()) {
|
||||
try {
|
||||
statement.setString(1, user.getUUID().toString());
|
||||
statement.setInt(2, user.getLevel());
|
||||
statement.setString(3, getServerName());
|
||||
statement.setTimestamp(4, user.getLevelSyncTimestamp());
|
||||
statement.setInt(5, user.getLevel());
|
||||
statement.setInt(6, user.getLevel());
|
||||
statement.setString(7, getServerName());
|
||||
|
||||
statement.addBatch();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
statement.executeBatch();
|
||||
getConnection().commit();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLevelToUser(final User user) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
PreparedStatement statement = getConnection().prepareStatement(sqlUpdate);
|
||||
statement.setString(1, user.getUUID().toString());
|
||||
statement.setTimestamp(2, user.getLevelSyncTimestamp());
|
||||
statement.setString(3, MANUAL_EDIT_TAG);
|
||||
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
while (set.next()) {
|
||||
AntiCheat.debugLog("Syncing level to " + user.getUUID() + ". Value: " + set.getInt("level"));
|
||||
user.setLevel(set.getInt("level"));
|
||||
user.setLevelSyncTimestamp(set.getTimestamp("last_update"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.mysql;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Magic;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MySQLMagicHolder extends ConfigurationTable implements InvocationHandler {
|
||||
|
||||
private static final String TABLE = "magic";
|
||||
|
||||
private HashMap<String, Integer> ints;
|
||||
private HashMap<String, Double> doubles;
|
||||
|
||||
private FileConfiguration defaults;
|
||||
|
||||
public MySQLMagicHolder(Configuration config) {
|
||||
super(config, TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
defaults = YamlConfiguration.loadConfiguration(AntiCheat.getPlugin().getResource("magic.yml"));
|
||||
|
||||
ints = new HashMap<String, Integer>();
|
||||
doubles = new HashMap<String, Double>();
|
||||
|
||||
String sqlCreate = "CREATE TABLE " + getFullTable() + "(" +
|
||||
" `id` INT NOT NULL AUTO_INCREMENT," +
|
||||
" `key` VARCHAR(45) NOT NULL," +
|
||||
" `value_int` INT," +
|
||||
" `value_double` DOUBLE," +
|
||||
" PRIMARY KEY (`id`));";
|
||||
|
||||
String sqlPopulate = "INSERT INTO " + getFullTable() +
|
||||
" (`key`, `value_int`, `value_double`) " +
|
||||
"SELECT t.*" +
|
||||
"FROM (";
|
||||
|
||||
Method[] methods = Magic.class.getMethods();
|
||||
for (int i=1;i<=methods.length;i++) {
|
||||
String key = methods[i-1].getName();
|
||||
Object value = defaults.get(key);
|
||||
String type1 = methods[i-1].getReturnType().getSimpleName();
|
||||
String type2 = type1.equals("int") ? "double" : "int";
|
||||
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;";
|
||||
|
||||
String sqlLoad = "SELECT * FROM " + getFullTable();
|
||||
|
||||
try {
|
||||
if (!tableExists()) {
|
||||
getConnection().prepareStatement(sqlCreate).executeUpdate();
|
||||
getConnection().prepareStatement(sqlPopulate).executeUpdate();
|
||||
getConnection().commit();
|
||||
}
|
||||
|
||||
ResultSet set = getConnection().prepareStatement(sqlLoad).executeQuery();
|
||||
while (set.next()) {
|
||||
String key = set.getString("key");
|
||||
|
||||
if (set.getObject("value_int") != null) {
|
||||
ints.put(key, set.getInt("value_int"));
|
||||
} else if (set.getObject("value_double") != null) {
|
||||
doubles.put(key, set.getDouble("value_double"));
|
||||
} else {
|
||||
AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " loaded from the database did not have a value configured. Using the default value.");
|
||||
for (int i=1;i<=methods.length;i++) {
|
||||
String name = methods[i-1].getName();
|
||||
if (name.equalsIgnoreCase(key)) {
|
||||
String type = methods[i-1].getReturnType().getSimpleName();
|
||||
if (type.equals("int")) {
|
||||
ints.put(key, defaults.getInt(key));
|
||||
} else if (type.equals("double")) {
|
||||
doubles.put(key, defaults.getDouble(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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 (defaults.getString(key) != null ) {
|
||||
if (method.getReturnType().getSimpleName().equals("int")) {
|
||||
int value = defaults.getInt(key);
|
||||
try {
|
||||
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();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
reload();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.mysql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Rules;
|
||||
import com.rammelkast.anticheatreloaded.util.rule.Rule;
|
||||
|
||||
public class MySQLRulesHolder extends ConfigurationTable implements Rules {
|
||||
|
||||
private static final String TABLE = "rules";
|
||||
|
||||
private List<Rule> rules;
|
||||
|
||||
public MySQLRulesHolder(Configuration config) {
|
||||
super(config, TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
String sqlCreate = "CREATE TABLE " + getFullTable() + "(" +
|
||||
" `id` INT NOT NULL AUTO_INCREMENT," +
|
||||
" `rule` VARCHAR(256) NOT NULL," +
|
||||
" PRIMARY KEY (`id`));";
|
||||
String sqlPopulate = "INSERT INTO " + getFullTable() +
|
||||
" VALUES (1, 'Check_SPIDER < 0 ? Player.KICK : null')";
|
||||
|
||||
String sqlLoad = "SELECT * FROM " + getFullTable();
|
||||
|
||||
try {
|
||||
if (!tableExists()) {
|
||||
getConnection().prepareStatement(sqlCreate).executeUpdate();
|
||||
getConnection().prepareStatement(sqlPopulate).executeUpdate();
|
||||
getConnection().commit();
|
||||
}
|
||||
|
||||
this.rules = new ArrayList<Rule>();
|
||||
ResultSet set = getConnection().prepareStatement(sqlLoad).executeQuery();
|
||||
while (set.next()) {
|
||||
String string = set.getString("rule");
|
||||
Rule rule = Rule.load(string);
|
||||
if (rule != null) {
|
||||
this.rules.add(rule);
|
||||
} else {
|
||||
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from the database. Improper format used.");
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Rule> getRules() {
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.yaml;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Groups;
|
||||
import com.rammelkast.anticheatreloaded.util.Group;
|
||||
|
||||
public class YamlGroupsHolder extends ConfigurationFile implements Groups {
|
||||
|
||||
public static final String FILENAME = "groups.yml";
|
||||
|
||||
private List<Group> groups;
|
||||
|
||||
private int highestLevel;
|
||||
|
||||
public YamlGroupsHolder(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Group> getGroups() {
|
||||
return groups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestLevel() {
|
||||
return highestLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
ConfigValue<List<String>> groups = new ConfigValue<List<String>>("groups");
|
||||
|
||||
// Convert groups list to Levels
|
||||
this.groups = new ArrayList<Group>();
|
||||
for (String string : groups.getValue()) {
|
||||
Group group = Group.load(string);
|
||||
if (group == null || group.getLevel() < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.groups.add(group);
|
||||
highestLevel = group.getLevel() > highestLevel ? group.getLevel() : highestLevel;
|
||||
}
|
||||
|
||||
// Sort groups
|
||||
Collections.sort(this.groups, new Comparator<Group>() {
|
||||
public int compare(Group l1, Group l2) {
|
||||
if (l1.getLevel() == l2.getLevel()) {
|
||||
return 0;
|
||||
} else if (l1.getLevel() < l2.getLevel()) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.yaml;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
|
||||
|
||||
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<String>("chat.ban_broadcast").getValue() != null) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
new ConfigValue<List<String>>("ALERT").setValue(new ConfigValue<List<String>>("alert").getValue());
|
||||
new ConfigValue<List<String>>("WARNING").setValue(new ConfigValue<List<String>>("warning.player_warning").getValue());
|
||||
new ConfigValue<List<String>>("alert").setValue(null);
|
||||
new ConfigValue<List<String>>("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<String>(newValue).setValue(new ConfigValue<String>(oldValue).getValue());
|
||||
new ConfigValue<String>(oldValue).setValue(null);
|
||||
}
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||
String key = method.getName();
|
||||
|
||||
if (method.getReturnType() == List.class) {
|
||||
ConfigValue<List<String>> value = new ConfigValue<List<String>>(key);
|
||||
if (value.getValue() != null) {
|
||||
return value.getValue();
|
||||
}
|
||||
} else {
|
||||
ConfigValue<String> value = new ConfigValue<String>(key);
|
||||
if (value.getValue() != null) {
|
||||
return value.getValue();
|
||||
}
|
||||
}
|
||||
AntiCheat.getPlugin().getLogger().severe("The lang value " + key + " couldn't be found.");
|
||||
return "Language error. See console for details.";
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.yaml;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Levels;
|
||||
import com.rammelkast.anticheatreloaded.util.User;
|
||||
|
||||
public class YamlLevelsHolder extends ConfigurationFile implements Levels {
|
||||
|
||||
public static final String FILENAME = "data/levels.yml";
|
||||
|
||||
public YamlLevelsHolder(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadLevelToUser(User user) {
|
||||
user.setLevel(getLevel(user.getUUID()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLevelFromUser(User user) {
|
||||
saveLevelFromUser(user, true);
|
||||
}
|
||||
|
||||
private void saveLevelFromUser(User user, boolean remove) {
|
||||
saveLevel(user.getUUID(), user.getLevel());
|
||||
if (remove) AntiCheat.getManager().getUserManager().remove(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLevelsFromUsers(List<User> users) {
|
||||
for (User user : users) {
|
||||
saveLevelFromUser(user, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLevelToUser(User user) {
|
||||
// This method intentionally left blank.
|
||||
return;
|
||||
}
|
||||
|
||||
private int getLevel(UUID uuid) {
|
||||
ConfigValue<Integer> level = new ConfigValue<Integer>(uuid.toString(), false);
|
||||
if (level.hasValue()) {
|
||||
return level.getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLevel(UUID uuid, int level) {
|
||||
new ConfigValue<Integer>(uuid.toString(), false).setValue(new Integer(level));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.yaml;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
|
||||
|
||||
public class YamlMagicHolder extends ConfigurationFile implements InvocationHandler {
|
||||
|
||||
public static final String FILENAME = "magic.yml";
|
||||
|
||||
public YamlMagicHolder(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME);
|
||||
}
|
||||
|
||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
||||
String key = method.getName();
|
||||
|
||||
if (method.getReturnType().getSimpleName().equals("int")) {
|
||||
return new ConfigValue<Integer>(key).getValue();
|
||||
} else if (method.getReturnType().getSimpleName().equals("double")) {
|
||||
return new ConfigValue<Double>(key).getValue();
|
||||
} else {
|
||||
AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.holders.yaml;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheat;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Rules;
|
||||
import com.rammelkast.anticheatreloaded.util.rule.Rule;
|
||||
|
||||
public class YamlRulesHolder extends ConfigurationFile implements Rules {
|
||||
|
||||
public static final String FILENAME = "rules.yml";
|
||||
|
||||
private List<Rule> rules;
|
||||
|
||||
public YamlRulesHolder(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Rule> getRules() {
|
||||
return rules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
ConfigValue<List<String>> rules = new ConfigValue<List<String>>("rules");
|
||||
|
||||
// Convert rules list to Rules
|
||||
this.rules = new ArrayList<Rule>();
|
||||
List<String> tempRules = rules.getValue();
|
||||
for (int i = 0; i < tempRules.size(); i++) {
|
||||
String string = tempRules.get(i);
|
||||
|
||||
if (string.equals("Check_SPIDER < 0 ? Player.KICK : null")) {
|
||||
// Default rule, won't ever run so we shouldn't load it; only used as example
|
||||
continue;
|
||||
}
|
||||
|
||||
Rule rule = Rule.load(string);
|
||||
if (rule != null) {
|
||||
this.rules.add(rule);
|
||||
} else {
|
||||
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from config. Improper format used.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.providers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.util.Group;
|
||||
|
||||
public interface Groups {
|
||||
|
||||
/**
|
||||
* Get all groups.
|
||||
*
|
||||
* @return List of groups.
|
||||
*/
|
||||
public List<Group> getGroups();
|
||||
|
||||
/**
|
||||
* Get the highest level value assigned to a group.
|
||||
* Used as a maximum cap to rising hack levels.
|
||||
*
|
||||
* @return Highest group level.
|
||||
*/
|
||||
public int getHighestLevel();
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.rammelkast.anticheatreloaded.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<String> ALERT();
|
||||
|
||||
/**
|
||||
* Get the warning to send players when they enter a group.
|
||||
*
|
||||
* @return Warning.
|
||||
*/
|
||||
public List<String> 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();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.providers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.util.User;
|
||||
|
||||
public interface Levels {
|
||||
|
||||
/**
|
||||
* Checks for a stored level for this user, and loads it to their object if found.
|
||||
*
|
||||
* @param user User to load.
|
||||
*/
|
||||
public void loadLevelToUser(User user);
|
||||
|
||||
/**
|
||||
* Saves the user's level to storage.
|
||||
*
|
||||
* @param user User to save.
|
||||
*/
|
||||
public void saveLevelFromUser(User user);
|
||||
|
||||
/**
|
||||
* Saves a list of user's levels to storage.
|
||||
* Used on server shutdown / reload.
|
||||
*
|
||||
* @param users List of users to save.
|
||||
*/
|
||||
public void saveLevelsFromUsers(List<User> users);
|
||||
|
||||
/**
|
||||
* Check to see if the user's level has been manually changed since it was loaded, and update it if needed
|
||||
*
|
||||
* @param user User to update.
|
||||
*/
|
||||
public void updateLevelToUser(User user);
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.providers;
|
||||
|
||||
/**
|
||||
* Magic number class. Modifications to values in magic.yml will be accepted here.
|
||||
* <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 (more precise) 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 make larger modifications to it.
|
||||
* <p/>
|
||||
* <b>How to read the value documentation:</b>
|
||||
* <p/>
|
||||
* First, you will see a description of the value. Then, you will see a type: <br>
|
||||
* <b>Type SYSTEM:</b> This is a millisecond value 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/>
|
||||
* 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.<br>
|
||||
* Some values may not have a leniency recommendation because they are internal numbers used for running checks. Values without these recommendations would be best left alone.
|
||||
*/
|
||||
|
||||
public interface Magic {
|
||||
/**
|
||||
* Time to exempt a player from moving because of entering/exiting a vehicle; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int ENTERED_EXITED_TIME();
|
||||
/**
|
||||
* Time to exempt a player from moving because of entering/exiting sneak mode; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int SNEAK_TIME();
|
||||
/**
|
||||
* Time to exempt a player from moving because of teleporting; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int TELEPORT_TIME();
|
||||
/**
|
||||
* Time to exempt a player from moving because of exiting fly mode; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int EXIT_FLY_TIME();
|
||||
/**
|
||||
* Time to exempt a player from moving because of joining the server; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int JOIN_TIME();
|
||||
/**
|
||||
* Time to exempt a player from fastbreak check because of using instant break; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int INSTANT_BREAK_TIME();
|
||||
/**
|
||||
* Time to exempt a player from moving because of taking damage; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int DAMAGE_TIME();
|
||||
/**
|
||||
* Time to exempt a player from moving because of taking damage with knockback effects; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int KNOCKBACK_DAMAGE_TIME();
|
||||
/**
|
||||
* Time to exempt a player from moving because of taking damage from an explosion; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int EXPLOSION_DAMAGE_TIME();
|
||||
/**
|
||||
* Minimum time it takes to fire X projectiles; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int PROJECTILE_TIME_MIN();
|
||||
/**
|
||||
* Number of projectiles to wait for before checking how long they took to fire off; Type=INTEGER.
|
||||
*/
|
||||
public int PROJECTILE_CHECK();
|
||||
/**
|
||||
* Minimum time it takes to drop X items; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int DROP_TIME_MIN();
|
||||
/**
|
||||
* Number of item drops to wait for before checking how long they took to drop; Type=INTEGER.
|
||||
*/
|
||||
public int DROP_CHECK();
|
||||
/**
|
||||
* Max number of blocks that can be broken in a given time; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTBREAK_LIMIT();
|
||||
/**
|
||||
* Time to wait before checking block breaks; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTBREAK_TIMEMAX();
|
||||
/**
|
||||
* Time to wait before checking block breaks in creative mode; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTBREAK_TIMEMAX_CREATIVE();
|
||||
/**
|
||||
* Number of times fastbreak can be observed before taking action; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTBREAK_MAXVIOLATIONS();
|
||||
/**
|
||||
* Number of times fastbreak can be observed before taking action in creative mode; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTBREAK_MAXVIOLATIONS_CREATIVE();
|
||||
/**
|
||||
* Time a player is forced to wait after fastbreak has been detected; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int FASTBREAK_MAXVIOLATIONTIME();
|
||||
/**
|
||||
* Number of blocks that can be broken without being hit before taking action; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTPLACE_ZEROLIMIT();
|
||||
/**
|
||||
* Minimum time in between block places; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int FASTPLACE_TIMEMIN();
|
||||
/**
|
||||
* Number of times fastplace can be observed before taking action; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTPLACE_MAXVIOLATIONS();
|
||||
/**
|
||||
* Number of times fastplace can be observed before taking action in creative mode; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FASTPLACE_MAXVIOLATIONS_CREATIVE();
|
||||
/**
|
||||
* Time a player is forced to wait after fastplace has been detected; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int FASTPLACE_MAXVIOLATIONTIME();
|
||||
/**
|
||||
* Number of times required to punch a block before it breaks; Type=INTEGER, Leniency=DECREASE.
|
||||
*/
|
||||
public int BLOCK_PUNCH_MIN();
|
||||
/**
|
||||
* Number of command spam violations before action one is executed; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int COMMAND_ACTION_ONE_LEVEL();
|
||||
/**
|
||||
* Number of command spam violations before action two is executed; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int COMMAND_ACTION_TWO_LEVEL();
|
||||
/**
|
||||
* Number of chat spam violations before action one is executed; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int CHAT_ACTION_ONE_LEVEL();
|
||||
/**
|
||||
* Number of chat spam violations before action two is executed; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int CHAT_ACTION_TWO_LEVEL();
|
||||
/**
|
||||
* Number of times a player can be caught in-flight before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FLIGHT_LIMIT();
|
||||
/**
|
||||
* Number of times a player can be caught in-glide before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int GLIDE_LIMIT();
|
||||
/**
|
||||
* How many blocks you can travel before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public double FLIGHT_BLOCK_LIMIT();
|
||||
/**
|
||||
* Maximum speed that a player can climb a waterfall; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double WATER_CLIMB_MAX();
|
||||
/**
|
||||
* Number of times a player can fly on the y-axis before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int Y_MAXVIOLATIONS();
|
||||
/**
|
||||
* Time a player is forced to wait after flying on the y-axis; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int Y_MAXVIOTIME();
|
||||
/**
|
||||
* Number of times a player can fail a velocity check before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int VELOCITY_TIME();
|
||||
/**
|
||||
* Time used to schedule increasing a players velocity count - probably not touching this would be good; Type=INTEGER.
|
||||
*/
|
||||
public int VELOCITY_SCHETIME();
|
||||
/**
|
||||
* Maximum time a player is considered to have a change in velocity; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int VELOCITY_CHECKTIME();
|
||||
/**
|
||||
* Time to extend a player's velocity count by; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int VELOCITY_PREVENT();
|
||||
/**
|
||||
* Number of times a player can fail the velocity check before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int VELOCITY_MAXTIMES();
|
||||
/**
|
||||
* Number of times a player can fail the nofall check before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int NOFALL_LIMIT();
|
||||
/**
|
||||
* Number of times a player can fail the ascension check before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int ASCENSION_COUNT_MAX();
|
||||
/**
|
||||
* Number of times a player can fail the ascension check while in water before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int WATER_ASCENSION_VIOLATION_MAX();
|
||||
/**
|
||||
* Number of times a player can be caught speeding in water before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int WATER_SPEED_VIOLATION_MAX();
|
||||
/**
|
||||
* Number of times a player can sprint without proper food level before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int SPRINT_FOOD_MIN();
|
||||
/**
|
||||
* Maximum times a player can interact between animations; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int ANIMATION_INTERACT_MAX();
|
||||
/**
|
||||
* Minimum time between animations; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int ANIMATION_MIN();
|
||||
/**
|
||||
* Minimum time between commands; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int COMMAND_MIN();
|
||||
/**
|
||||
* Minimum time before repeating a command is ignored; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int COMMAND_REPEAT_MIN();
|
||||
/**
|
||||
* Minimum time between chats; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int CHAT_MIN();
|
||||
/**
|
||||
* Time before repeating yourself in chat is ignored; Type=SYSTEM, Leniency=INCREASE.
|
||||
*/
|
||||
public int CHAT_REPEAT_MIN();
|
||||
/**
|
||||
* Maximum speed you can travel while sprinting; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double SPRINT_MIN();
|
||||
/**
|
||||
* Minimum time in between block breaks; Type=INTEGER, Leniency=DECREASE.
|
||||
*/
|
||||
public double BLOCK_BREAK_MIN();
|
||||
/**
|
||||
* Minimum time in between block placing; Type=INTEGER, Leniency=DECREASE.
|
||||
*/
|
||||
public double BLOCK_PLACE_MIN();
|
||||
/**
|
||||
* Minimum time in between eating; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int EAT_TIME_MIN();
|
||||
/**
|
||||
* Maximum percent error between predicted bow force and actual bow force; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double BOW_ERROR();
|
||||
/**
|
||||
* Minimum distance a player can break a block from; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double BLOCK_MAX_DISTANCE();
|
||||
/**
|
||||
* Minimum distance a player can break a block from in creative mode; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double BLOCK_MAX_DISTANCE_CREATIVE();
|
||||
/**
|
||||
* Minimum distance a player can damage an entity from; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double ENTITY_MAX_DISTANCE();
|
||||
/**
|
||||
* Minimum distance a player can damage an entity from in creative mode; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double ENTITY_MAX_DISTANCE_CREATIVE();
|
||||
/**
|
||||
* Maximum speed a player on a ladder can travel; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double LADDER_Y_MAX();
|
||||
/**
|
||||
* Minimum speed a player on a ladder can travel; Type=DOUBLE, Leniency=DECREASE.
|
||||
*/
|
||||
public double LADDER_Y_MIN();
|
||||
/**
|
||||
* Maximum speed a player can travel up; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double Y_SPEED_MAX();
|
||||
/**
|
||||
* Maximum difference between the player's last 2 Y values when traveling up; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double Y_MAXDIFF();
|
||||
/**
|
||||
* Time in between Y difference measures; Type=SYSTEM, Leniency=DECREASE.
|
||||
*/
|
||||
public int Y_TIME();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards while sprinting; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_SPRINT();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards while flying; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_FLY();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards while under the influence; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_POTION();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards while sprinting while under the influence; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_POTION_SPRINT();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards while sneaking; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_SNEAK();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards in water; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_WATER();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards in water while sprinting; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_WATER_SPRINT();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards on soul sand; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_SOULSAND();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards on soul sand while sprinting; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_SOULSAND_SPRINT();
|
||||
/**
|
||||
* Maximum speed a player can travel forwards or backwards on soul sand while under the influence; Type=DOUBLE, Leniency=INCREASE.
|
||||
*/
|
||||
public double XZ_SPEED_MAX_SOULSAND_POTION();
|
||||
/**
|
||||
* Maximum times a player can fail the speed check before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int SPEED_MAX();
|
||||
/**
|
||||
* The number of clicks we should wait before checking if the player has used fast inventory; Type=INTEGER; Leniency=INCREASE.
|
||||
*/
|
||||
public int INVENTORY_CHECK();
|
||||
/**
|
||||
* The minimum time it should have taken for the player to click X times; Type=INTEGER; Leniency=INCREASE.
|
||||
*/
|
||||
public int INVENTORY_TIMEMIN();
|
||||
/**
|
||||
* The number of steps we should wait before checking if the player has used timer cheating; Type=INTEGER; Leniency=INCREASE.
|
||||
*/
|
||||
public int TIMER_STEP_CHECK();
|
||||
/**
|
||||
* The minimum time it should have taken for the player to travel X steps; Type=SYSTEM; Leniency=DECREASE.
|
||||
*/
|
||||
public int TIMER_TIMEMIN();
|
||||
/**
|
||||
* Minimum travel distance for move to be considered a teleport and subsequently be ignored; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int TELEPORT_MIN();
|
||||
/**
|
||||
* Maximum amount of times a player can hit a killaura bot; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int KILLAURA_BOTHITS();
|
||||
/**
|
||||
* Maximum amount of packets a player can send in a second; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int BLINK_PACKET();
|
||||
/**
|
||||
* Maximum amount of low/zero velocity before flagging; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int VELOCITY_AMT();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.providers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.util.rule.Rule;
|
||||
|
||||
public interface Rules {
|
||||
|
||||
/**
|
||||
* Get all rules.
|
||||
*
|
||||
* @return List of rules.
|
||||
*/
|
||||
public List<Rule> getRules();
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.config.yaml;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConstructor;
|
||||
import org.bukkit.configuration.file.YamlRepresenter;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
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.
|
||||
* <br>
|
||||
* Some overridden code has been moved to this file from its parent & modified.
|
||||
*/
|
||||
public class CommentedConfiguration extends YamlConfiguration {
|
||||
private Map<Integer, String> comments = new HashMap<Integer, String>();
|
||||
|
||||
private final DumperOptions yamlOptions = new DumperOptions();
|
||||
private final Representer yamlRepresenter = new YamlRepresenter();
|
||||
private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions);
|
||||
|
||||
@Override
|
||||
public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||
Validate.notNull(contents, "Contents cannot be null");
|
||||
|
||||
Map<?, ?> input;
|
||||
try {
|
||||
input = (Map<?, ?>) yaml.load(contents);
|
||||
} catch (YAMLException e) {
|
||||
throw new InvalidConfigurationException(e);
|
||||
} catch (ClassCastException e) {
|
||||
throw new InvalidConfigurationException("Top level is not a Map.");
|
||||
}
|
||||
|
||||
/** - CommentedConfiguration
|
||||
String header = parseHeader(contents);
|
||||
if (header.length() > 0) {
|
||||
options().header(header);
|
||||
}
|
||||
**/
|
||||
|
||||
if (input != null) {
|
||||
convertMapsToSections(input, this);
|
||||
}
|
||||
|
||||
// Begin CommentedConfiguration
|
||||
int i = 0;
|
||||
int blank = 0;
|
||||
String[] lines = contents.split("\n");
|
||||
while (i < lines.length) {
|
||||
if (lines[i].trim().equalsIgnoreCase("")) {
|
||||
i++;
|
||||
blank++;
|
||||
continue;
|
||||
}
|
||||
if (lines[i].contains(COMMENT_PREFIX)) {
|
||||
comments.put(i - blank, lines[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
// End CommentedConfiguration
|
||||
}
|
||||
|
||||
@Override
|
||||
public String saveToString() {
|
||||
yamlOptions.setIndent(options().indent());
|
||||
yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||
|
||||
// String header = buildHeader(); - CommentedConfiguration
|
||||
String dump = yaml.dump(getValues(false));
|
||||
|
||||
if (dump.equals(BLANK_CONFIG)) {
|
||||
dump = "";
|
||||
}
|
||||
|
||||
// Begin CommentedConfiguration
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
String[] lines = dump.split("\n");
|
||||
ArrayDeque<String> queue = new ArrayDeque<String>();
|
||||
for (String string : lines) {
|
||||
queue.add(string);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (queue.size() > 0) {
|
||||
if (comments.containsKey(i)) {
|
||||
builder.append(comments.get(i));
|
||||
|
||||
// Handle subsequent comments
|
||||
int b = i;
|
||||
while (true) {
|
||||
b++;
|
||||
if (comments.containsKey(b)) {
|
||||
builder.append('\n');
|
||||
builder.append(comments.get(b));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.append('\n');
|
||||
i = b;
|
||||
}
|
||||
|
||||
builder.append(queue.getFirst());
|
||||
builder.append('\n');
|
||||
queue.pop();
|
||||
i++;
|
||||
}
|
||||
// End CommentedConfiguration
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommentedConfiguration}, loading from the given file.
|
||||
* <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.
|
||||
*
|
||||
* @param file Input file
|
||||
* @return Resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if file is null
|
||||
*/
|
||||
public static CommentedConfiguration loadConfiguration(File file) {
|
||||
Validate.notNull(file, "File cannot be null");
|
||||
|
||||
CommentedConfiguration config = new CommentedConfiguration();
|
||||
|
||||
try {
|
||||
config.load(file);
|
||||
} catch (FileNotFoundException ex) {
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link CommentedConfiguration}, loading from the given stream.
|
||||
* <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.
|
||||
*
|
||||
* @param stream Input stream
|
||||
* @return Resulting configuration
|
||||
* @throws IllegalArgumentException Thrown if stream is null
|
||||
*/
|
||||
public static CommentedConfiguration loadConfiguration(InputStream stream) {
|
||||
Validate.notNull(stream, "Stream cannot be null");
|
||||
|
||||
CommentedConfiguration config = new CommentedConfiguration();
|
||||
|
||||
try {
|
||||
config.load(stream);
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex);
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user