mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 22:14:49 +00:00
Refactor package to new namespace
This commit is contained in:
1 parent
089759dbad
commit
fd1e5232e0
55 files changed
+5632
-5624
No files matched your search
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.config.holders.mysql;
|
||||
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Events;
|
||||
import net.gravitydevelopment.anticheat.util.Level;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MySQLEventsHolder extends ConfigurationTable implements Events {
|
||||
|
||||
private static final String TABLE = "events";
|
||||
|
||||
private List<Level> levels;
|
||||
private int highestLevel;
|
||||
|
||||
public MySQLEventsHolder(Configuration config) {
|
||||
super(config, TABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
highestLevel = 0;
|
||||
levels = new ArrayList<Level>();
|
||||
|
||||
String sqlCreate = "CREATE TABLE IF NOT EXISTS " + getFullTable() + "(" +
|
||||
" `id` INT NOT NULL," +
|
||||
" `name` VARCHAR(45) NOT NULL," +
|
||||
" `level` INT NOT NULL," +
|
||||
" `color` VARCHAR(45) NOT NULL," +
|
||||
" `actions` VARCHAR(45) NOT NULL," +
|
||||
" PRIMARY KEY (`id`));";
|
||||
String sqlLoad = "SELECT * FROM " + getFullTable();
|
||||
|
||||
try {
|
||||
getConnection().prepareStatement(sqlCreate).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(","));
|
||||
|
||||
levels.add(new Level(name, level, color, actions));
|
||||
if (level > highestLevel) {
|
||||
highestLevel = level;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Level> getLevels() {
|
||||
return levels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestLevel() {
|
||||
return highestLevel;
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.config.holders.mysql;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
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 String sqlSave;
|
||||
private String sqlLoad;
|
||||
|
||||
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 = ?";
|
||||
|
||||
String sqlCreate = "CREATE TABLE IF NOT EXISTS " + 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 {
|
||||
getConnection().prepareStatement(sqlCreate).executeUpdate();
|
||||
getConnection().commit();
|
||||
} 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("Syncing to " + user.getName() + " value " + user.getLevel());
|
||||
try {
|
||||
PreparedStatement statement = getConnection().prepareStatement(sqlSave);
|
||||
statement.setString(1, user.getName());
|
||||
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.getName());
|
||||
|
||||
ResultSet set = statement.executeQuery();
|
||||
|
||||
boolean has = false;
|
||||
while (set.next()) {
|
||||
has = true;
|
||||
AntiCheat.debugLog("Syncing from " + user.getName() + " 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.getName());
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.config.holders.mysql;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Rules;
|
||||
import net.gravitydevelopment.anticheat.util.rule.Rule;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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 IF NOT EXISTS " + getFullTable() + "(" +
|
||||
" `id` INT NOT NULL AUTO_INCREMENT," +
|
||||
" `rule` VARCHAR(45) NOT NULL," +
|
||||
" PRIMARY KEY (`id`));";
|
||||
|
||||
String sqlLoad = "SELECT * FROM " + getFullTable();
|
||||
|
||||
try {
|
||||
getConnection().prepareStatement(sqlCreate).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;
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.config.holders.yaml;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Events;
|
||||
import net.gravitydevelopment.anticheat.util.Level;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class YamlEventsHolder extends ConfigurationFile implements Events {
|
||||
|
||||
public static final String FILENAME = "events.yml";
|
||||
|
||||
private List<Level> levels;
|
||||
|
||||
private int highestLevel;
|
||||
|
||||
public YamlEventsHolder(AntiCheat plugin, Configuration config) {
|
||||
super(plugin, config, FILENAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Level> getLevels() {
|
||||
return levels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestLevel() {
|
||||
return highestLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
ConfigValue<List<String>> levels = new ConfigValue<List<String>>("events");
|
||||
|
||||
// Clean up old values
|
||||
if(levels.didLoadDefault()) {
|
||||
new ConfigValue<List<String>>("levels").setValue(null);
|
||||
new ConfigValue<List<String>>("actions").setValue(null);
|
||||
save();
|
||||
}
|
||||
|
||||
// Convert levels list to Levels
|
||||
this.levels = new ArrayList<Level>();
|
||||
for (String string : levels.getValue()) {
|
||||
Level level = Level.load(string);
|
||||
if (level == null || level.getValue() < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.levels.add(level);
|
||||
highestLevel = level.getValue() > highestLevel ? level.getValue() : highestLevel;
|
||||
}
|
||||
|
||||
// Sort levels
|
||||
Collections.sort(this.levels, new Comparator<Level>() {
|
||||
public int compare(Level l1, Level l2) {
|
||||
if (l1.getValue() == l2.getValue()) {
|
||||
return 0;
|
||||
} else if (l1.getValue() < l2.getValue()) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.config.holders.yaml;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Levels;
|
||||
import net.gravitydevelopment.anticheat.manage.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLevelFromUser(User user) {
|
||||
saveLevelFromUser(user, true);
|
||||
}
|
||||
|
||||
private void saveLevelFromUser(User user, boolean remove) {
|
||||
saveLevel(user.getName(), user.getLevel());
|
||||
if (remove) AntiCheat.getManager().getUserManager().remove(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLevelsFromUsers(List<User> users) {
|
||||
for (User user : users) {
|
||||
saveLevelFromUser(user, false);
|
||||
}
|
||||
}
|
||||
|
||||
private int getLevel(String name) {
|
||||
ConfigValue<Integer> level = new ConfigValue<Integer>(name, false);
|
||||
if (level.hasValue()) {
|
||||
return level.getValue();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLevel(String name, int level) {
|
||||
new ConfigValue<Integer>(name, false).setValue(new Integer(level));
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* AntiCheat for Bukkit.
|
||||
* Copyright (C) 2012-2013 AntiCheat Team | http://gravitydevelopment.net
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.gravitydevelopment.anticheat.config.holders.yaml;
|
||||
|
||||
import net.gravitydevelopment.anticheat.AntiCheat;
|
||||
import net.gravitydevelopment.anticheat.config.Configuration;
|
||||
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
|
||||
import net.gravitydevelopment.anticheat.config.providers.Rules;
|
||||
import net.gravitydevelopment.anticheat.util.rule.Rule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class YamlRulesHolder extends ConfigurationFile implements Rules {
|
||||
|
||||
public static final String FILENAME = "events.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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user