forked from zhdev/griefus
CoreProtect v20.0 release
This commit is contained in:
parent
415d7b323a
commit
48ef18e2c8
173 changed files with 25072 additions and 1 deletions
161
src/main/java/net/coreprotect/database/ContainerRollback.java
Normal file
161
src/main/java/net/coreprotect/database/ContainerRollback.java
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
package net.coreprotect.database;
|
||||
|
||||
import java.sql.Statement;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class ContainerRollback extends Queue {
|
||||
|
||||
public static void performContainerRollbackRestore(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, String timeString, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, final Location location, Integer[] radius, int checkTime, boolean restrictWorld, boolean lookup, boolean verbose, final int rollbackType) {
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
final List<Object[]> lookupList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, -1, -1, restrictWorld, lookup);
|
||||
if (rollbackType == 1) {
|
||||
Collections.reverse(lookupList);
|
||||
}
|
||||
|
||||
String userString = "#server";
|
||||
if (user != null) {
|
||||
userString = user.getName();
|
||||
}
|
||||
|
||||
Queue.queueContainerRollbackUpdate(userString, location, lookupList, rollbackType); // Perform update transaction in consumer
|
||||
|
||||
final String finalUserString = userString;
|
||||
ConfigHandler.rollbackHash.put(userString, new int[] { 0, 0, 0, 0 });
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int[] rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||
int itemCount = rollbackHashData[0];
|
||||
// int blockCount = rollbackHashData[1];
|
||||
int entityCount = rollbackHashData[2];
|
||||
Block block = location.getBlock();
|
||||
|
||||
if (!block.getWorld().isChunkLoaded(block.getChunk())) {
|
||||
block.getWorld().getChunkAt(block.getLocation());
|
||||
}
|
||||
Object container = null;
|
||||
Material type = block.getType();
|
||||
|
||||
if (BlockGroup.CONTAINERS.contains(type)) {
|
||||
container = Util.getContainerInventory(block.getState(), false);
|
||||
}
|
||||
else {
|
||||
for (Entity entity : block.getChunk().getEntities()) {
|
||||
if (entity instanceof ArmorStand) {
|
||||
if (entity.getLocation().getBlockX() == location.getBlockX() && entity.getLocation().getBlockY() == location.getBlockY() && entity.getLocation().getBlockZ() == location.getBlockZ()) {
|
||||
type = Material.ARMOR_STAND;
|
||||
container = Util.getEntityEquipment((LivingEntity) entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int modifyCount = 0;
|
||||
if (container != null) {
|
||||
for (Object[] lookupRow : lookupList) {
|
||||
// int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
// int rowId = lookupRow[0];
|
||||
// int rowTime = (Integer)lookupRow[1];
|
||||
// int rowUserId = (Integer)lookupRow[2];
|
||||
// int rowX = (Integer)lookupRow[3];
|
||||
// int rowY = (Integer)lookupRow[4];
|
||||
// int rowZ = (Integer)lookupRow[5];
|
||||
int rowTypeRaw = (Integer) lookupRow[6];
|
||||
int rowData = (Integer) lookupRow[7];
|
||||
int rowAction = (Integer) lookupRow[8];
|
||||
int rowRolledBack = (Integer) lookupRow[9];
|
||||
// int rowWid = (Integer)lookupRow[10];
|
||||
int rowAmount = (Integer) lookupRow[11];
|
||||
byte[] rowMetadata = (byte[]) lookupRow[12];
|
||||
Material rowType = Util.getType(rowTypeRaw);
|
||||
|
||||
if ((rollbackType == 0 && rowRolledBack == 0) || (rollbackType == 1 && rowRolledBack == 1)) {
|
||||
modifyCount = modifyCount + rowAmount;
|
||||
int action = 0;
|
||||
|
||||
if (rollbackType == 0 && rowAction == 0) {
|
||||
action = 1;
|
||||
}
|
||||
|
||||
if (rollbackType == 1 && rowAction == 1) {
|
||||
action = 1;
|
||||
}
|
||||
|
||||
ItemStack itemstack = new ItemStack(rowType, rowAmount, (short) rowData);
|
||||
Object[] populatedStack = Rollback.populateItemStack(itemstack, rowMetadata);
|
||||
int slot = (Integer) populatedStack[0];
|
||||
itemstack = (ItemStack) populatedStack[1];
|
||||
|
||||
Rollback.modifyContainerItems(type, container, slot, itemstack, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigHandler.rollbackHash.put(finalUserString, new int[] { itemCount, modifyCount, entityCount, 1 });
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, 0);
|
||||
|
||||
int[] rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||
int next = rollbackHashData[3];
|
||||
int sleepTime = 0;
|
||||
|
||||
while (next == 0) {
|
||||
sleepTime = sleepTime + 5;
|
||||
Thread.sleep(5);
|
||||
rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||
next = rollbackHashData[3];
|
||||
if (sleepTime > 300000) {
|
||||
Chat.console(Phrase.build(Phrase.ROLLBACK_ABORTED));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rollbackHashData = ConfigHandler.rollbackHash.get(finalUserString);
|
||||
int blockCount = rollbackHashData[1];
|
||||
long endTime = System.currentTimeMillis();
|
||||
double totalSeconds = (endTime - startTime) / 1000.0;
|
||||
|
||||
if (user != null) {
|
||||
int file = -1;
|
||||
if (blockCount > 0) {
|
||||
file = 1;
|
||||
}
|
||||
int itemCount = 0;
|
||||
int entityCount = 0;
|
||||
|
||||
Rollback.finishRollbackRestore(user, location, checkUsers, restrictList, excludeList, excludeUserList, actionList, timeString, file, totalSeconds, itemCount, blockCount, entityCount, rollbackType, radius, verbose, restrictWorld, 0);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
564
src/main/java/net/coreprotect/database/Database.java
Executable file
564
src/main/java/net/coreprotect/database/Database.java
Executable file
|
|
@ -0,0 +1,564 @@
|
|||
package net.coreprotect.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Consumer;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
import net.coreprotect.consumer.process.Process;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class Database extends Queue {
|
||||
|
||||
public static final int SIGN = 0;
|
||||
public static final int BLOCK = 1;
|
||||
public static final int SKULL = 2;
|
||||
public static final int CONTAINER = 3;
|
||||
public static final int WORLD = 4;
|
||||
public static final int CHAT = 5;
|
||||
public static final int COMMAND = 6;
|
||||
public static final int SESSION = 7;
|
||||
public static final int ENTITY = 8;
|
||||
public static final int MATERIAL = 9;
|
||||
public static final int ART = 10;
|
||||
public static final int ENTITY_MAP = 11;
|
||||
public static final int BLOCKDATA = 12;
|
||||
public static final int ITEM = 13;
|
||||
|
||||
public static void beginTransaction(Statement statement) {
|
||||
Consumer.transacting = true;
|
||||
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("START TRANSACTION");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("BEGIN TRANSACTION");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void commitTransaction(Statement statement) throws Exception {
|
||||
int count = 0;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
statement.executeUpdate("COMMIT");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("COMMIT TRANSACTION");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e.getMessage().startsWith("[SQLITE_BUSY]") && count < 30) {
|
||||
Thread.sleep(1000);
|
||||
count++;
|
||||
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Consumer.transacting = false;
|
||||
Consumer.interrupt = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setMultiInt(PreparedStatement statement, int value, int count) {
|
||||
try {
|
||||
for (int i = 1; i <= count; i++) {
|
||||
statement.setInt(i, value);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void containerBreakCheck(String user, Material type, Object container, ItemStack[] contents, Location location) {
|
||||
if (BlockGroup.CONTAINERS.contains(type) && !BlockGroup.SHULKER_BOXES.contains(type)) {
|
||||
if (Config.getConfig(location.getWorld()).ITEM_TRANSACTIONS) {
|
||||
try {
|
||||
if (contents == null) {
|
||||
contents = Util.getContainerContents(type, container, location);
|
||||
}
|
||||
if (contents != null) {
|
||||
List<ItemStack[]> forceList = new ArrayList<>();
|
||||
forceList.add(Util.getContainerState(contents));
|
||||
ConfigHandler.forceContainer.put(user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ(), forceList);
|
||||
Queue.queueContainerBreak(user, location, type, contents);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection(boolean onlyCheckTransacting) {
|
||||
// Previously 250ms; long consumer commit time may be due to batching
|
||||
// TODO: Investigate, potentially remove batching for SQLite connections
|
||||
return getConnection(false, false, onlyCheckTransacting, 1000);
|
||||
}
|
||||
|
||||
public static Connection getConnection(boolean force, int waitTime) {
|
||||
return getConnection(force, false, false, waitTime);
|
||||
}
|
||||
|
||||
public static Connection getConnection(boolean force, boolean startup, boolean onlyCheckTransacting, int waitTime) {
|
||||
Connection connection = null;
|
||||
try {
|
||||
if (!force && (ConfigHandler.converterRunning || ConfigHandler.purgeRunning)) {
|
||||
return connection;
|
||||
}
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
try {
|
||||
/* Using useServerPrepStmts, cachePrepStmts, and rewriteBatchedStatements per https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration */
|
||||
String database = "jdbc:mysql://" + ConfigHandler.host + ":" + ConfigHandler.port + "/" + ConfigHandler.database + "?useUnicode=true&characterEncoding=utf-8&connectTimeout=10000&useSSL=false&allowPublicKeyRetrieval=true&useCursorFetch=true&useLocalSessionState=true&rewriteBatchedStatements=true&maintainTimeStats=false";
|
||||
connection = DriverManager.getConnection(database, ConfigHandler.username, ConfigHandler.password);
|
||||
|
||||
/* Recommended implementation per https://dev.mysql.com/doc/refman/5.0/en/charset-applications.html & https://dev.mysql.com/doc/refman/5.0/en/charset-syntax.html */
|
||||
Statement statement = connection.createStatement();
|
||||
statement.executeUpdate("SET NAMES 'utf8mb4'"); // COLLATE 'utf8mb4mb4_general_ci'
|
||||
statement.close();
|
||||
|
||||
ConfigHandler.databaseReachable = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
ConfigHandler.databaseReachable = false;
|
||||
Chat.sendConsoleMessage(Color.RED + "[CoreProtect] " + Phrase.build(Phrase.MYSQL_UNAVAILABLE));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Consumer.transacting && onlyCheckTransacting) {
|
||||
Consumer.interrupt = true;
|
||||
}
|
||||
|
||||
long startTime = System.nanoTime();
|
||||
while (Consumer.isPaused && !force && (Consumer.transacting || !onlyCheckTransacting)) {
|
||||
Thread.sleep(1);
|
||||
long pauseTime = (System.nanoTime() - startTime) / 1000000;
|
||||
|
||||
if (pauseTime >= waitTime) {
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
String database = "jdbc:sqlite:" + ConfigHandler.path + ConfigHandler.sqlite + "";
|
||||
connection = DriverManager.getConnection(database);
|
||||
|
||||
ConfigHandler.databaseReachable = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
public static void performUpdate(Statement statement, long id, int action, int table) {
|
||||
try {
|
||||
int rolledBack = 1;
|
||||
if (action == 1) {
|
||||
rolledBack = 0;
|
||||
}
|
||||
|
||||
if (table == 1) {
|
||||
statement.executeUpdate("UPDATE " + ConfigHandler.prefix + "container SET rolled_back='" + rolledBack + "' WHERE rowid='" + id + "'");
|
||||
}
|
||||
else {
|
||||
statement.executeUpdate("UPDATE " + ConfigHandler.prefix + "block SET rolled_back='" + rolledBack + "' WHERE rowid='" + id + "'");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static PreparedStatement prepareStatement(Connection connection, int type, boolean keys) {
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
String signInsert = "INSERT INTO " + ConfigHandler.prefix + "sign (time, user, wid, x, y, z, action, color, data, line_1, line_2, line_3, line_4) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String blockInsert = "INSERT INTO " + ConfigHandler.prefix + "block (time, user, wid, x, y, z, type, data, meta, blockdata, action, rolled_back) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String skullInsert = "INSERT INTO " + ConfigHandler.prefix + "skull (time, owner) VALUES (?, ?)";
|
||||
String containerInsert = "INSERT INTO " + ConfigHandler.prefix + "container (time, user, wid, x, y, z, type, data, amount, metadata, action, rolled_back) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String itemInsert = "INSERT INTO " + ConfigHandler.prefix + "item (time, user, wid, x, y, z, type, data, amount, action) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String worldInsert = "INSERT INTO " + ConfigHandler.prefix + "world (id, world) VALUES (?, ?)";
|
||||
String chatInsert = "INSERT INTO " + ConfigHandler.prefix + "chat (time, user, wid, x, y, z, message) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
String commandInsert = "INSERT INTO " + ConfigHandler.prefix + "command (time, user, wid, x, y, z, message) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
String sessionInsert = "INSERT INTO " + ConfigHandler.prefix + "session (time, user, wid, x, y, z, action) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||
String entityInsert = "INSERT INTO " + ConfigHandler.prefix + "entity (time, data) VALUES (?, ?)";
|
||||
String materialInsert = "INSERT INTO " + ConfigHandler.prefix + "material_map (id, material) VALUES (?, ?)";
|
||||
String artInsert = "INSERT INTO " + ConfigHandler.prefix + "art_map (id, art) VALUES (?, ?)";
|
||||
String entityMapInsert = "INSERT INTO " + ConfigHandler.prefix + "entity_map (id, entity) VALUES (?, ?)";
|
||||
String blockdataInsert = "INSERT INTO " + ConfigHandler.prefix + "blockdata_map (id, data) VALUES (?, ?)";
|
||||
|
||||
switch (type) {
|
||||
case SIGN:
|
||||
preparedStatement = prepareStatement(connection, signInsert, keys);
|
||||
break;
|
||||
case BLOCK:
|
||||
preparedStatement = prepareStatement(connection, blockInsert, keys);
|
||||
break;
|
||||
case SKULL:
|
||||
preparedStatement = prepareStatement(connection, skullInsert, keys);
|
||||
break;
|
||||
case CONTAINER:
|
||||
preparedStatement = prepareStatement(connection, containerInsert, keys);
|
||||
break;
|
||||
case ITEM:
|
||||
preparedStatement = prepareStatement(connection, itemInsert, keys);
|
||||
break;
|
||||
case WORLD:
|
||||
preparedStatement = prepareStatement(connection, worldInsert, keys);
|
||||
break;
|
||||
case CHAT:
|
||||
preparedStatement = prepareStatement(connection, chatInsert, keys);
|
||||
break;
|
||||
case COMMAND:
|
||||
preparedStatement = prepareStatement(connection, commandInsert, keys);
|
||||
break;
|
||||
case SESSION:
|
||||
preparedStatement = prepareStatement(connection, sessionInsert, keys);
|
||||
break;
|
||||
case ENTITY:
|
||||
preparedStatement = prepareStatement(connection, entityInsert, keys);
|
||||
break;
|
||||
case MATERIAL:
|
||||
preparedStatement = prepareStatement(connection, materialInsert, keys);
|
||||
break;
|
||||
case ART:
|
||||
preparedStatement = prepareStatement(connection, artInsert, keys);
|
||||
break;
|
||||
case ENTITY_MAP:
|
||||
preparedStatement = prepareStatement(connection, entityMapInsert, keys);
|
||||
break;
|
||||
case BLOCKDATA:
|
||||
preparedStatement = prepareStatement(connection, blockdataInsert, keys);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return preparedStatement;
|
||||
}
|
||||
|
||||
private static PreparedStatement prepareStatement(Connection connection, String query, boolean keys) {
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
if (keys) {
|
||||
preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
||||
}
|
||||
else {
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return preparedStatement;
|
||||
}
|
||||
|
||||
private static void initializeTables(String prefix, Statement statement) {
|
||||
try {
|
||||
boolean lockInitialized = false;
|
||||
String query = "SELECT rowid as id FROM " + prefix + "database_lock WHERE rowid='1' LIMIT 1";
|
||||
ResultSet rs = statement.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
lockInitialized = true;
|
||||
}
|
||||
rs.close();
|
||||
|
||||
if (!lockInitialized) {
|
||||
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
statement.executeUpdate("INSERT INTO " + prefix + "database_lock (rowid, status, time) VALUES ('1', '0', '" + unixtimestamp + "')");
|
||||
Process.lastLockUpdate = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void createDatabaseTables(String prefix, boolean purge) {
|
||||
ConfigHandler.databaseTables.clear();
|
||||
ConfigHandler.databaseTables.addAll(Arrays.asList("art_map", "block", "chat", "command", "container", "item", "database_lock", "entity", "entity_map", "material_map", "blockdata_map", "session", "sign", "skull", "user", "username_log", "version", "world"));
|
||||
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
boolean success = false;
|
||||
try {
|
||||
Connection connection = Database.getConnection(true, true, true, 0);
|
||||
if (connection != null) {
|
||||
String index = "";
|
||||
Statement statement = connection.createStatement();
|
||||
index = ", INDEX(id)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "art_map(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),id int(8),art varchar(255)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "block(rowid bigint(20) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int(10), user int(8), wid int(4), x int(8), y int(3), z int(8), type int(6), data int(8), meta mediumblob, blockdata blob, action int(2), rolled_back tinyint(1)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(time), INDEX(user,time), INDEX(wid,x,z,time)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "chat(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10), user int(8), wid int(4), x int(8), y int (3), z int(8), message varchar(16000)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(time), INDEX(user,time), INDEX(wid,x,z,time)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "command(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10), user int(8), wid int(4), x int(8), y int (3), z int(8), message varchar(16000)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container(rowid int(10) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int(10), user int(8), wid int(4), x int(8), y int(3), z int(8), type int(6), data int(6), amount int(4), metadata blob, action int(2), rolled_back tinyint(1)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(type,time)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item(rowid int(10) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int(10), user int(8), wid int(4), x int(8), y int(3), z int(8), type int(6), data blob, amount int(4), action tinyint(1)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "database_lock(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),status tinyint(1),time int(10)) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "entity(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int(10), data blob) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(id)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "entity_map(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),id int(8),entity varchar(255)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(id)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "material_map(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),id int(8),material varchar(255)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(id)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "blockdata_map(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),id int(8),data varchar(255)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(wid,x,z,time), INDEX(action,time), INDEX(user,time), INDEX(time)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "session(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10), user int(8), wid int(4), x int(8), y int (3), z int(8), action int(1)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(wid,x,z,time), INDEX(user,time), INDEX(time)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10), user int(8), wid int(4), x int(8), y int(3), z int(8), action tinyint(1), color int(8), data tinyint(1), line_1 varchar(100), line_2 varchar(100), line_3 varchar(100), line_4 varchar(100)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "skull(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid), time int(10), owner varchar(64)) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(user), INDEX(uuid)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "user(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10),user varchar(100),uuid varchar(64)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(uuid,user)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "username_log(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10),uuid varchar(64),user varchar(100)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "version(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),time int(10),version varchar(16)) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
index = ", INDEX(id)";
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "world(rowid int(8) NOT NULL AUTO_INCREMENT,PRIMARY KEY(rowid),id int(8),world varchar(255)" + index + ") ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4");
|
||||
if (!purge) {
|
||||
initializeTables(prefix, statement);
|
||||
}
|
||||
statement.close();
|
||||
connection.close();
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!success) {
|
||||
Config.getGlobal().MYSQL = false;
|
||||
}
|
||||
}
|
||||
if (!Config.getGlobal().MYSQL) {
|
||||
try {
|
||||
Connection connection = Database.getConnection(true, 0);
|
||||
Statement statement = connection.createStatement();
|
||||
List<String> tableData = new ArrayList<>();
|
||||
List<String> indexData = new ArrayList<>();
|
||||
String attachDatabase = "";
|
||||
|
||||
if (purge) {
|
||||
String query = "ATTACH DATABASE '" + ConfigHandler.path + ConfigHandler.sqlite + ".tmp' AS tmp_db";
|
||||
PreparedStatement preparedStmt = connection.prepareStatement(query);
|
||||
preparedStmt.execute();
|
||||
preparedStmt.close();
|
||||
attachDatabase = "tmp_db.";
|
||||
}
|
||||
|
||||
String query = "SELECT type,name FROM " + attachDatabase + "sqlite_master WHERE type='table' OR type='index';";
|
||||
ResultSet rs = statement.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
String type = rs.getString("type");
|
||||
if (type.equalsIgnoreCase("table")) {
|
||||
tableData.add(rs.getString("name"));
|
||||
}
|
||||
else if (type.equalsIgnoreCase("index")) {
|
||||
indexData.add(rs.getString("name"));
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
|
||||
if (!tableData.contains(prefix + "art_map")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "art_map (id INTEGER, art TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "block")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "block (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data INTEGER, meta BLOB, blockdata BLOB, action INTEGER, rolled_back INTEGER);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "chat")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "chat (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, message TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "command")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "command (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, message TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "container")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "container (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data INTEGER, amount INTEGER, metadata BLOB, action INTEGER, rolled_back INTEGER);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "item")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "item (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, type INTEGER, data BLOB, amount INTEGER, action INTEGER);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "database_lock")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "database_lock (status INTEGER, time INTEGER);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "entity")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "entity (id INTEGER PRIMARY KEY ASC, time INTEGER, data BLOB);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "entity_map")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "entity_map (id INTEGER, entity TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "material_map")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "material_map (id INTEGER, material TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "blockdata_map")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "blockdata_map (id INTEGER, data TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "session")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "session (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "sign")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "sign (time INTEGER, user INTEGER, wid INTEGER, x INTEGER, y INTEGER, z INTEGER, action INTEGER, color INTEGER, data INTEGER, line_1 TEXT, line_2 TEXT, line_3 TEXT, line_4 TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "skull")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "skull (id INTEGER PRIMARY KEY ASC, time INTEGER, owner TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "user")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "user (id INTEGER PRIMARY KEY ASC, time INTEGER, user TEXT, uuid TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "username_log")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "username_log (id INTEGER PRIMARY KEY ASC, time INTEGER, uuid TEXT, user TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "version")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "version (time INTEGER, version TEXT);");
|
||||
}
|
||||
if (!tableData.contains(prefix + "world")) {
|
||||
statement.executeUpdate("CREATE TABLE IF NOT EXISTS " + prefix + "world (id INTEGER, world TEXT);");
|
||||
}
|
||||
try {
|
||||
if (!indexData.contains("art_map_id_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "art_map_id_index ON " + ConfigHandler.prefix + "art_map(id);");
|
||||
}
|
||||
if (!indexData.contains("block_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "block_index ON " + ConfigHandler.prefix + "block(wid,x,z,time);");
|
||||
}
|
||||
if (!indexData.contains("block_user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "block_user_index ON " + ConfigHandler.prefix + "block(user,time);");
|
||||
}
|
||||
if (!indexData.contains("block_type_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "block_type_index ON " + ConfigHandler.prefix + "block(type,time);");
|
||||
}
|
||||
if (!indexData.contains("blockdata_map_id_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "blockdata_map_id_index ON " + ConfigHandler.prefix + "blockdata_map(id);");
|
||||
}
|
||||
if (!indexData.contains("chat_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "chat_index ON " + ConfigHandler.prefix + "chat(time);");
|
||||
}
|
||||
if (!indexData.contains("chat_user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "chat_user_index ON " + ConfigHandler.prefix + "chat(user,time);");
|
||||
}
|
||||
if (!indexData.contains("chat_wid_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "chat_wid_index ON " + ConfigHandler.prefix + "chat(wid,x,z,time);");
|
||||
}
|
||||
if (!indexData.contains("command_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "command_index ON " + ConfigHandler.prefix + "command(time);");
|
||||
}
|
||||
if (!indexData.contains("command_user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "command_user_index ON " + ConfigHandler.prefix + "command(user,time);");
|
||||
}
|
||||
if (!indexData.contains("command_wid_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "command_wid_index ON " + ConfigHandler.prefix + "command(wid,x,z,time);");
|
||||
}
|
||||
if (!indexData.contains("container_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "container_index ON " + ConfigHandler.prefix + "container(wid,x,z,time);");
|
||||
}
|
||||
if (!indexData.contains("container_user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "container_user_index ON " + ConfigHandler.prefix + "container(user,time);");
|
||||
}
|
||||
if (!indexData.contains("container_type_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "container_type_index ON " + ConfigHandler.prefix + "container(type,time);");
|
||||
}
|
||||
if (!indexData.contains("item_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "item_index ON " + ConfigHandler.prefix + "item(wid,x,z,time);");
|
||||
}
|
||||
if (!indexData.contains("item_user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "item_user_index ON " + ConfigHandler.prefix + "item(user,time);");
|
||||
}
|
||||
if (!indexData.contains("item_type_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "item_type_index ON " + ConfigHandler.prefix + "item(type,time);");
|
||||
}
|
||||
if (!indexData.contains("entity_map_id_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "entity_map_id_index ON " + ConfigHandler.prefix + "entity_map(id);");
|
||||
}
|
||||
if (!indexData.contains("material_map_id_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "material_map_id_index ON " + ConfigHandler.prefix + "material_map(id);");
|
||||
}
|
||||
if (!indexData.contains("session_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "session_index ON " + ConfigHandler.prefix + "session(wid,x,z,time);");
|
||||
}
|
||||
if (!indexData.contains("session_action_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "session_action_index ON " + ConfigHandler.prefix + "session(action,time);");
|
||||
}
|
||||
if (!indexData.contains("session_user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "session_user_index ON " + ConfigHandler.prefix + "session(user,time);");
|
||||
}
|
||||
if (!indexData.contains("session_time_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "session_time_index ON " + ConfigHandler.prefix + "session(time);");
|
||||
}
|
||||
if (!indexData.contains("sign_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "sign_index ON " + ConfigHandler.prefix + "sign(wid,x,z,time);");
|
||||
}
|
||||
if (!indexData.contains("sign_user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "sign_user_index ON " + ConfigHandler.prefix + "sign(user,time);");
|
||||
}
|
||||
if (!indexData.contains("sign_time_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "sign_time_index ON " + ConfigHandler.prefix + "sign(time);");
|
||||
}
|
||||
if (!indexData.contains("user_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "user_index ON " + ConfigHandler.prefix + "user(user);");
|
||||
}
|
||||
if (!indexData.contains("uuid_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "uuid_index ON " + ConfigHandler.prefix + "user(uuid);");
|
||||
}
|
||||
if (!indexData.contains("username_log_uuid_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "username_log_uuid_index ON " + ConfigHandler.prefix + "username_log(uuid,user);");
|
||||
}
|
||||
if (!indexData.contains("world_id_index")) {
|
||||
statement.executeUpdate("CREATE INDEX IF NOT EXISTS " + attachDatabase + "world_id_index ON " + ConfigHandler.prefix + "world(id);");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.DATABASE_INDEX_ERROR));
|
||||
if (purge) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!purge) {
|
||||
initializeTables(prefix, statement);
|
||||
}
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
781
src/main/java/net/coreprotect/database/Lookup.java
Executable file
781
src/main/java/net/coreprotect/database/Lookup.java
Executable file
|
|
@ -0,0 +1,781 @@
|
|||
package net.coreprotect.database;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Consumer;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
import net.coreprotect.database.logger.ItemLogger;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class Lookup extends Queue {
|
||||
|
||||
static List<String[]> convertRawLookup(Statement statement, List<Object[]> list) {
|
||||
List<String[]> newList = new ArrayList<>();
|
||||
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Object[] map : list) {
|
||||
int newLength = map.length - 1;
|
||||
String[] results = new String[newLength];
|
||||
|
||||
for (int i = 0; i < map.length; i++) {
|
||||
try {
|
||||
int newId = i - 1;
|
||||
if (i == 2) {
|
||||
if (map[i] instanceof Integer) {
|
||||
int userId = (Integer) map[i];
|
||||
if (ConfigHandler.playerIdCacheReversed.get(userId) == null) {
|
||||
UserStatement.loadName(statement.getConnection(), userId);
|
||||
}
|
||||
String userResult = ConfigHandler.playerIdCacheReversed.get(userId);
|
||||
results[newId] = userResult;
|
||||
}
|
||||
else {
|
||||
results[newId] = (String) map[i];
|
||||
}
|
||||
}
|
||||
else if (i == 13 && map[i] instanceof Byte[]) {
|
||||
results[newId] = Util.byteDataToString((byte[]) map[i], (int) map[6]);
|
||||
}
|
||||
else if (i > 0) {
|
||||
if (map[i] instanceof Integer) {
|
||||
results[newId] = map[i].toString();
|
||||
}
|
||||
else if (map[i] instanceof String) {
|
||||
results[newId] = (String) map[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
newList.add(results);
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
public static int countLookupRows(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, boolean restrictWorld, boolean lookup) {
|
||||
int rows = 0;
|
||||
|
||||
try {
|
||||
while (Consumer.isPaused) {
|
||||
Thread.sleep(1);
|
||||
}
|
||||
Consumer.isPaused = true;
|
||||
|
||||
ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, -1, -1, restrictWorld, lookup, true);
|
||||
while (results.next()) {
|
||||
rows += results.getInt("count");
|
||||
}
|
||||
results.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Consumer.isPaused = false;
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
public static List<String[]> performLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, boolean restrictWorld, boolean lookup) {
|
||||
List<String[]> newList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
List<Object[]> lookupList = performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, -1, -1, restrictWorld, lookup);
|
||||
newList = convertRawLookup(statement, lookupList);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
static List<Object[]> performLookupRaw(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
|
||||
List<Object[]> list = new ArrayList<>();
|
||||
List<Integer> invalidRollbackActions = new ArrayList<>();
|
||||
invalidRollbackActions.add(2);
|
||||
|
||||
if (!Config.getGlobal().ROLLBACK_ENTITIES && !actionList.contains(3)) {
|
||||
invalidRollbackActions.add(3);
|
||||
}
|
||||
|
||||
try {
|
||||
while (Consumer.isPaused) {
|
||||
Thread.sleep(1);
|
||||
}
|
||||
|
||||
Consumer.isPaused = true;
|
||||
|
||||
ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, limitOffset, limitCount, restrictWorld, lookup, false);
|
||||
|
||||
while (results.next()) {
|
||||
if (actionList.contains(6) || actionList.contains(7)) {
|
||||
long resultId = results.getLong("id");
|
||||
int resultTime = results.getInt("time");
|
||||
int resultUserId = results.getInt("user");
|
||||
String resultMessage = results.getString("message");
|
||||
|
||||
Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultMessage };
|
||||
list.add(dataArray);
|
||||
}
|
||||
else if (actionList.contains(8)) {
|
||||
long resultId = results.getLong("id");
|
||||
int resultTime = results.getInt("time");
|
||||
int resultUserId = results.getInt("user");
|
||||
int resultWorldId = results.getInt("wid");
|
||||
int resultX = results.getInt("x");
|
||||
int resultY = results.getInt("y");
|
||||
int resultZ = results.getInt("z");
|
||||
int resultAction = results.getInt("action");
|
||||
|
||||
Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultWorldId, resultX, resultY, resultZ, resultAction };
|
||||
list.add(dataArray);
|
||||
}
|
||||
else if (actionList.contains(9)) {
|
||||
long resultId = results.getLong("id");
|
||||
int resultTime = results.getInt("time");
|
||||
String resultUuid = results.getString("uuid");
|
||||
String resultUser = results.getString("user");
|
||||
|
||||
Object[] dataArray = new Object[] { resultId, resultTime, resultUuid, resultUser };
|
||||
list.add(dataArray);
|
||||
}
|
||||
else if (actionList.contains(10)) {
|
||||
long resultId = results.getLong("id");
|
||||
int resultTime = results.getInt("time");
|
||||
int resultUserId = results.getInt("user");
|
||||
int resultWorldId = results.getInt("wid");
|
||||
int resultX = results.getInt("x");
|
||||
int resultY = results.getInt("y");
|
||||
int resultZ = results.getInt("z");
|
||||
String line1 = results.getString("line_1");
|
||||
String line2 = results.getString("line_2");
|
||||
String line3 = results.getString("line_3");
|
||||
String line4 = results.getString("line_4");
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (line1 != null && line1.length() > 0) {
|
||||
message.append(line1);
|
||||
if (!line1.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
if (line2 != null && line2.length() > 0) {
|
||||
message.append(line2);
|
||||
if (!line2.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
if (line3 != null && line3.length() > 0) {
|
||||
message.append(line3);
|
||||
if (!line3.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
if (line4 != null && line4.length() > 0) {
|
||||
message.append(line4);
|
||||
if (!line4.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultWorldId, resultX, resultY, resultZ, message.toString() };
|
||||
list.add(dataArray);
|
||||
}
|
||||
else {
|
||||
int resultData = 0;
|
||||
int resultAmount = -1;
|
||||
byte[] resultMeta = null;
|
||||
byte[] resultBlockData = null;
|
||||
long resultId = results.getLong("id");
|
||||
int resultUserId = results.getInt("user");
|
||||
int resultAction = results.getInt("action");
|
||||
int resultRolledBack = results.getInt("rolled_back");
|
||||
int resultType = results.getInt("type");
|
||||
int resultTime = results.getInt("time");
|
||||
int resultX = results.getInt("x");
|
||||
int resultY = results.getInt("y");
|
||||
int resultZ = results.getInt("z");
|
||||
int resultWorldId = results.getInt("wid");
|
||||
|
||||
if ((lookup && actionList.size() == 0) || actionList.contains(4) || actionList.contains(5) || actionList.contains(11)) {
|
||||
resultData = results.getInt("data");
|
||||
resultAmount = results.getInt("amount");
|
||||
resultMeta = results.getBytes("metadata");
|
||||
}
|
||||
else {
|
||||
resultData = results.getInt("data");
|
||||
resultMeta = results.getBytes("meta");
|
||||
resultBlockData = results.getBytes("blockdata");
|
||||
}
|
||||
|
||||
boolean valid = true;
|
||||
|
||||
if (!lookup) {
|
||||
if (invalidRollbackActions.contains(resultAction)) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
Object[] dataArray = new Object[] { resultId, resultTime, resultUserId, resultX, resultY, resultZ, resultType, resultData, resultAction, resultRolledBack, resultWorldId, resultAmount, resultMeta, resultBlockData };
|
||||
list.add(dataArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
results.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Consumer.isPaused = false;
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<String[]> performPartialLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
|
||||
List<String[]> newList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
List<Object[]> lookupList = performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, limitOffset, limitCount, restrictWorld, lookup);
|
||||
newList = convertRawLookup(statement, lookupList);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
private static ResultSet rawLookupResultSet(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, int checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup, boolean count) {
|
||||
ResultSet results = null;
|
||||
|
||||
try {
|
||||
List<Integer> validActions = Arrays.asList(0, 1, 2, 3);
|
||||
if (radius != null) {
|
||||
restrictWorld = true;
|
||||
}
|
||||
|
||||
boolean validAction = false;
|
||||
String queryBlock = "";
|
||||
String queryEntity = "";
|
||||
String queryLimit = "";
|
||||
String queryTable = "block";
|
||||
String action = "";
|
||||
String includeBlock = "";
|
||||
String includeEntity = "";
|
||||
String excludeBlock = "";
|
||||
String excludeEntity = "";
|
||||
String users = "";
|
||||
String uuids = "";
|
||||
String excludeUsers = "";
|
||||
String index = "";
|
||||
String query = "";
|
||||
|
||||
if (checkUuids.size() > 0) {
|
||||
String list = "";
|
||||
|
||||
for (String value : checkUuids) {
|
||||
if (list.length() == 0) {
|
||||
list = "'" + value + "'";
|
||||
}
|
||||
else {
|
||||
list = list + ",'" + value + "'";
|
||||
}
|
||||
}
|
||||
|
||||
uuids = list;
|
||||
}
|
||||
|
||||
if (!checkUsers.contains("#global")) {
|
||||
StringBuilder checkUserText = new StringBuilder();
|
||||
|
||||
for (String checkUser : checkUsers) {
|
||||
if (!checkUser.equals("#container")) {
|
||||
if (ConfigHandler.playerIdCache.get(checkUser.toLowerCase(Locale.ROOT)) == null) {
|
||||
UserStatement.loadId(statement.getConnection(), checkUser, null);
|
||||
}
|
||||
|
||||
int userId = ConfigHandler.playerIdCache.get(checkUser.toLowerCase(Locale.ROOT));
|
||||
if (checkUserText.length() == 0) {
|
||||
checkUserText = checkUserText.append(userId);
|
||||
}
|
||||
else {
|
||||
checkUserText.append(",").append(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
users = checkUserText.toString();
|
||||
}
|
||||
|
||||
if (restrictList.size() > 0) {
|
||||
StringBuilder includeListMaterial = new StringBuilder();
|
||||
StringBuilder includeListEntity = new StringBuilder();
|
||||
|
||||
for (Object restrictTarget : restrictList) {
|
||||
String targetName = "";
|
||||
|
||||
if (restrictTarget instanceof Material) {
|
||||
targetName = ((Material) restrictTarget).name();
|
||||
if (includeListMaterial.length() == 0) {
|
||||
includeListMaterial = includeListMaterial.append(Util.getBlockId(targetName, false));
|
||||
}
|
||||
else {
|
||||
includeListMaterial.append(",").append(Util.getBlockId(targetName, false));
|
||||
}
|
||||
|
||||
/* Include legacy IDs */
|
||||
int legacyId = BukkitAdapter.ADAPTER.getLegacyBlockId((Material) restrictTarget);
|
||||
if (legacyId > 0) {
|
||||
includeListMaterial.append(",").append(legacyId);
|
||||
}
|
||||
}
|
||||
else if (restrictTarget instanceof EntityType) {
|
||||
targetName = ((EntityType) restrictTarget).name();
|
||||
if (includeListEntity.length() == 0) {
|
||||
includeListEntity = includeListEntity.append(Util.getEntityId(targetName, false));
|
||||
}
|
||||
else {
|
||||
includeListEntity.append(",").append(Util.getEntityId(targetName, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
includeBlock = includeListMaterial.toString();
|
||||
includeEntity = includeListEntity.toString();
|
||||
}
|
||||
|
||||
if (excludeList.size() > 0) {
|
||||
StringBuilder excludeListMaterial = new StringBuilder();
|
||||
StringBuilder excludeListEntity = new StringBuilder();
|
||||
|
||||
for (Object restrictTarget : excludeList) {
|
||||
String targetName = "";
|
||||
|
||||
if (restrictTarget instanceof Material) {
|
||||
targetName = ((Material) restrictTarget).name();
|
||||
if (excludeListMaterial.length() == 0) {
|
||||
excludeListMaterial = excludeListMaterial.append(Util.getBlockId(targetName, false));
|
||||
}
|
||||
else {
|
||||
excludeListMaterial.append(",").append(Util.getBlockId(targetName, false));
|
||||
}
|
||||
|
||||
/* Include legacy IDs */
|
||||
int legacyId = BukkitAdapter.ADAPTER.getLegacyBlockId((Material) restrictTarget);
|
||||
if (legacyId > 0) {
|
||||
excludeListMaterial.append(",").append(legacyId);
|
||||
}
|
||||
}
|
||||
else if (restrictTarget instanceof EntityType) {
|
||||
targetName = ((EntityType) restrictTarget).name();
|
||||
if (excludeListEntity.length() == 0) {
|
||||
excludeListEntity = excludeListEntity.append(Util.getEntityId(targetName, false));
|
||||
}
|
||||
else {
|
||||
excludeListEntity.append(",").append(Util.getEntityId(targetName, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
excludeBlock = excludeListMaterial.toString();
|
||||
excludeEntity = excludeListEntity.toString();
|
||||
}
|
||||
|
||||
if (excludeUserList.size() > 0) {
|
||||
StringBuilder excludeUserText = new StringBuilder();
|
||||
|
||||
for (String excludeTarget : excludeUserList) {
|
||||
if (ConfigHandler.playerIdCache.get(excludeTarget.toLowerCase(Locale.ROOT)) == null) {
|
||||
UserStatement.loadId(statement.getConnection(), excludeTarget, null);
|
||||
}
|
||||
|
||||
int userId = ConfigHandler.playerIdCache.get(excludeTarget.toLowerCase(Locale.ROOT));
|
||||
if (excludeUserText.length() == 0) {
|
||||
excludeUserText = excludeUserText.append(userId);
|
||||
}
|
||||
else {
|
||||
excludeUserText.append(",").append(userId);
|
||||
}
|
||||
}
|
||||
|
||||
excludeUsers = excludeUserText.toString();
|
||||
}
|
||||
|
||||
if (!actionList.isEmpty()) {
|
||||
StringBuilder actionText = new StringBuilder();
|
||||
for (Integer actionTarget : actionList) {
|
||||
if (validActions.contains(actionTarget)) {
|
||||
// If just looking up drops/pickups, remap the actions to the correct values
|
||||
if (actionList.contains(11) && !actionList.contains(4)) {
|
||||
if (actionTarget == ItemLogger.ITEM_REMOVE && !actionList.contains(ItemLogger.ITEM_DROP)) {
|
||||
actionTarget = ItemLogger.ITEM_DROP;
|
||||
}
|
||||
else if (actionTarget == ItemLogger.ITEM_ADD && !actionList.contains(ItemLogger.ITEM_PICKUP)) {
|
||||
actionTarget = ItemLogger.ITEM_PICKUP;
|
||||
}
|
||||
}
|
||||
|
||||
if (actionText.length() == 0) {
|
||||
actionText = actionText.append(actionTarget);
|
||||
}
|
||||
else {
|
||||
actionText.append(",").append(actionTarget);
|
||||
}
|
||||
|
||||
// If selecting from co_item & co_container, add in actions for both transaction types
|
||||
if (actionList.contains(11) && actionList.contains(4)) {
|
||||
if (actionTarget == ItemLogger.ITEM_REMOVE) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_DROP);
|
||||
actionText.append(",").append(ItemLogger.ITEM_ADD_ENDER);
|
||||
}
|
||||
if (actionTarget == ItemLogger.ITEM_ADD) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_PICKUP);
|
||||
actionText.append(",").append(ItemLogger.ITEM_REMOVE_ENDER);
|
||||
}
|
||||
}
|
||||
// If just looking up drops/pickups, include ender chest transactions
|
||||
else if (actionList.contains(11) && !actionList.contains(4)) {
|
||||
if (actionTarget == ItemLogger.ITEM_DROP) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_ADD_ENDER);
|
||||
}
|
||||
if (actionTarget == ItemLogger.ITEM_PICKUP) {
|
||||
actionText.append(",").append(ItemLogger.ITEM_REMOVE_ENDER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
action = actionText.toString();
|
||||
}
|
||||
|
||||
for (Integer value : actionList) {
|
||||
if (validActions.contains(value)) {
|
||||
validAction = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (restrictWorld) {
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
queryBlock = queryBlock + " wid=" + wid + " AND";
|
||||
}
|
||||
|
||||
if (radius != null) {
|
||||
int xmin = radius[1];
|
||||
int xmax = radius[2];
|
||||
int ymin = radius[3];
|
||||
int ymax = radius[4];
|
||||
int zmin = radius[5];
|
||||
int zmax = radius[6];
|
||||
String queryY = "";
|
||||
|
||||
if (ymin > -1 && ymax > -1) {
|
||||
queryY = " y >= '" + ymin + "' AND y <= '" + ymax + "' AND";
|
||||
}
|
||||
|
||||
queryBlock = queryBlock + " x >= '" + xmin + "' AND x <= '" + xmax + "' AND z >= '" + zmin + "' AND z <= '" + zmax + "' AND" + queryY;
|
||||
}
|
||||
else if (actionList.contains(5)) {
|
||||
int worldId = Util.getWorldId(location.getWorld().getName());
|
||||
int x = (int) Math.floor(location.getX());
|
||||
int z = (int) Math.floor(location.getZ());
|
||||
int x2 = (int) Math.ceil(location.getX());
|
||||
int z2 = (int) Math.ceil(location.getZ());
|
||||
|
||||
queryBlock = queryBlock + " wid=" + worldId + " AND (x = '" + x + "' OR x = '" + x2 + "') AND (z = '" + z + "' OR z = '" + z2 + "') AND y = '" + location.getBlockY() + "' AND";
|
||||
}
|
||||
|
||||
if (validAction) {
|
||||
queryBlock = queryBlock + " action IN(" + action + ") AND";
|
||||
}
|
||||
else if (includeBlock.length() > 0 || includeEntity.length() > 0 || excludeBlock.length() > 0 || excludeEntity.length() > 0) {
|
||||
queryBlock = queryBlock + " action NOT IN(-1) AND";
|
||||
}
|
||||
|
||||
if (includeBlock.length() > 0 || includeEntity.length() > 0) {
|
||||
queryBlock = queryBlock + " type IN(" + (includeBlock.length() > 0 ? includeBlock : "0") + ") AND";
|
||||
}
|
||||
|
||||
if (excludeBlock.length() > 0 || excludeEntity.length() > 0) {
|
||||
queryBlock = queryBlock + " type NOT IN(" + (excludeBlock.length() > 0 ? excludeBlock : "0") + ") AND";
|
||||
}
|
||||
|
||||
if (uuids.length() > 0) {
|
||||
queryBlock = queryBlock + " uuid IN(" + uuids + ") AND";
|
||||
}
|
||||
|
||||
if (users.length() > 0) {
|
||||
queryBlock = queryBlock + " user IN(" + users + ") AND";
|
||||
}
|
||||
|
||||
if (excludeUsers.length() > 0) {
|
||||
queryBlock = queryBlock + " user NOT IN(" + excludeUsers + ") AND";
|
||||
}
|
||||
|
||||
if (checkTime > 0) {
|
||||
queryBlock = queryBlock + " time > '" + checkTime + "' AND";
|
||||
}
|
||||
|
||||
if (actionList.contains(10)) {
|
||||
queryBlock = queryBlock + " action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) AND";
|
||||
}
|
||||
|
||||
if (queryBlock.length() > 0) {
|
||||
queryBlock = queryBlock.substring(0, queryBlock.length() - 4);
|
||||
}
|
||||
|
||||
if (queryBlock.length() == 0) {
|
||||
queryBlock = " 1";
|
||||
}
|
||||
|
||||
queryEntity = queryBlock;
|
||||
if (includeBlock.length() > 0 || includeEntity.length() > 0) {
|
||||
queryEntity = queryEntity.replace("type IN(" + (includeBlock.length() > 0 ? includeBlock : "0") + ")", "type IN(" + (includeEntity.length() > 0 ? includeEntity : "0") + ")");
|
||||
}
|
||||
if (excludeBlock.length() > 0 || excludeEntity.length() > 0) {
|
||||
queryEntity = queryEntity.replace("type NOT IN(" + (excludeBlock.length() > 0 ? excludeBlock : "0") + ")", "type NOT IN(" + (excludeEntity.length() > 0 ? excludeEntity : "0") + ")");
|
||||
}
|
||||
|
||||
String baseQuery = (includeEntity.length() > 0 ? queryEntity : queryBlock);
|
||||
if (limitOffset > -1 && limitCount > -1) {
|
||||
queryLimit = " LIMIT " + limitOffset + ", " + limitCount + "";
|
||||
}
|
||||
|
||||
String rows = "rowid as id,time,user,wid,x,y,z,action,type,data,meta,blockdata,rolled_back";
|
||||
String queryOrder = " ORDER BY rowid DESC";
|
||||
|
||||
if (actionList.contains(4) || actionList.contains(5)) {
|
||||
queryTable = "container";
|
||||
rows = "rowid as id,time,user,wid,x,y,z,action,type,data,rolled_back,amount,metadata";
|
||||
}
|
||||
else if (actionList.contains(6) || actionList.contains(7)) {
|
||||
queryTable = "chat";
|
||||
rows = "rowid as id,time,user,message";
|
||||
|
||||
if (actionList.contains(7)) {
|
||||
queryTable = "command";
|
||||
}
|
||||
}
|
||||
else if (actionList.contains(8)) {
|
||||
queryTable = "session";
|
||||
rows = "rowid as id,time,user,wid,x,y,z,action";
|
||||
}
|
||||
else if (actionList.contains(9)) {
|
||||
queryTable = "username_log";
|
||||
rows = "rowid as id,time,uuid,user";
|
||||
}
|
||||
else if (actionList.contains(10)) {
|
||||
queryTable = "sign";
|
||||
rows = "rowid as id,time,user,wid,x,y,z,line_1,line_2,line_3,line_4";
|
||||
}
|
||||
else if (actionList.contains(11)) {
|
||||
queryTable = "item";
|
||||
rows = "rowid as id,time,user,wid,x,y,z,type,data as metadata,0 as data,amount,action,0 as rolled_back";
|
||||
}
|
||||
|
||||
if (count) {
|
||||
rows = "COUNT(*) as count";
|
||||
queryLimit = " LIMIT 0, 3";
|
||||
queryOrder = "";
|
||||
}
|
||||
|
||||
if (Config.getGlobal().MYSQL) {
|
||||
if (radius == null || users.length() > 0 || includeBlock.length() > 0 || includeEntity.length() > 0) {
|
||||
// index_mysql = "IGNORE INDEX(wid) ";
|
||||
if (users.length() > 0) {
|
||||
// index_mysql = "IGNORE INDEX(wid,type,action) ";
|
||||
}
|
||||
}
|
||||
|
||||
if (queryTable.equals("block")) {
|
||||
if (includeBlock.length() > 0 || includeEntity.length() > 0) {
|
||||
index = "USE INDEX(type) ";
|
||||
}
|
||||
if (users.length() > 0) {
|
||||
index = "USE INDEX(user) ";
|
||||
}
|
||||
if ((radius != null || actionList.contains(5)) || (index.equals("") && restrictWorld)) {
|
||||
index = "USE INDEX(wid) ";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (queryTable.equals("block")) {
|
||||
if (includeBlock.length() > 0 || includeEntity.length() > 0) {
|
||||
index = "INDEXED BY block_type_index ";
|
||||
}
|
||||
if (users.length() > 0) {
|
||||
index = "INDEXED BY block_user_index ";
|
||||
}
|
||||
if ((radius != null || actionList.contains(5)) || (index.equals("") && restrictWorld)) {
|
||||
index = "INDEXED BY block_index ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean itemLookup = (actionList.contains(4) && actionList.contains(11));
|
||||
if (lookup && actionList.size() == 0) {
|
||||
if (!count) {
|
||||
rows = "rowid as id,time,user,wid,x,y,z,type,meta as metadata,data,-1 as amount,action,rolled_back";
|
||||
}
|
||||
|
||||
if (includeBlock.length() > 0 || excludeBlock.length() > 0) {
|
||||
baseQuery = baseQuery.replace("action NOT IN(-1)", "action NOT IN(3)"); // if block specified for include/exclude, filter out entity data
|
||||
}
|
||||
|
||||
query = "SELECT " + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery + " UNION ";
|
||||
itemLookup = true;
|
||||
}
|
||||
|
||||
if (itemLookup) {
|
||||
if (!count) {
|
||||
rows = "rowid as id,time,user,wid,x,y,z,type,metadata,data,amount,action,rolled_back";
|
||||
}
|
||||
query = query + "SELECT " + rows + " FROM " + ConfigHandler.prefix + "container WHERE" + queryBlock + " UNION ";
|
||||
|
||||
if (!count) {
|
||||
rows = "rowid as id,time,user,wid,x,y,z,type,data as metadata,0 as data,amount,action,0 as rolled_back";
|
||||
queryOrder = " ORDER BY time DESC, id DESC";
|
||||
}
|
||||
query = query + "SELECT " + rows + " FROM " + ConfigHandler.prefix + "item WHERE" + queryBlock;
|
||||
}
|
||||
|
||||
if (query.length() == 0) {
|
||||
query = "SELECT " + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery;
|
||||
}
|
||||
|
||||
query = query + queryOrder + queryLimit + "";
|
||||
results = statement.executeQuery(query);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public static String whoPlaced(Statement statement, BlockState block) {
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (block == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int worldId = Util.getWorldId(block.getWorld().getName());
|
||||
String query = "SELECT user,type FROM " + ConfigHandler.prefix + "block WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND rolled_back = '0' AND action='1' ORDER BY rowid DESC LIMIT 0, 1";
|
||||
|
||||
ResultSet results = statement.executeQuery(query);
|
||||
while (results.next()) {
|
||||
int resultUserId = results.getInt("user");
|
||||
int resultType = results.getInt("type");
|
||||
|
||||
if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) {
|
||||
UserStatement.loadName(statement.getConnection(), resultUserId);
|
||||
}
|
||||
|
||||
result = ConfigHandler.playerIdCacheReversed.get(resultUserId);
|
||||
if (result.length() > 0) {
|
||||
Material resultMaterial = Util.getType(resultType);
|
||||
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + worldId + "", new Object[] { time, result, resultMaterial });
|
||||
}
|
||||
}
|
||||
results.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String whoPlacedCache(Block block) {
|
||||
if (block == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return whoPlacedCache(block.getState());
|
||||
}
|
||||
|
||||
public static String whoPlacedCache(BlockState block) {
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (block == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int worldId = Util.getWorldId(block.getWorld().getName());
|
||||
|
||||
String cords = "" + x + "." + y + "." + z + "." + worldId + "";
|
||||
Object[] data = CacheHandler.lookupCache.get(cords);
|
||||
|
||||
if (data != null) {
|
||||
result = (String) data[1];
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String whoRemovedCache(BlockState block) {
|
||||
/*
|
||||
* Performs a lookup on who removed a block, from memory. Only searches through the last 30 seconds of block removal data.
|
||||
*/
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (block != null) {
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int worldId = Util.getWorldId(block.getWorld().getName());
|
||||
|
||||
String cords = "" + x + "." + y + "." + z + "." + worldId + "";
|
||||
Object[] data = CacheHandler.breakCache.get(cords);
|
||||
|
||||
if (data != null) {
|
||||
result = (String) data[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
1850
src/main/java/net/coreprotect/database/Rollback.java
Normal file
1850
src/main/java/net/coreprotect/database/Rollback.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,53 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class BlockBreakLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int type, int data, List<Object> meta, String blockData) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || location == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Material checkType = Util.getType(type);
|
||||
if (checkType == null) {
|
||||
return;
|
||||
}
|
||||
else if (checkType.equals(Material.AIR) || checkType.equals(Material.CAVE_AIR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.startsWith("#")) {
|
||||
CacheHandler.spreadCache.remove(location);
|
||||
}
|
||||
|
||||
if (checkType == Material.LECTERN) {
|
||||
blockData = blockData.replaceFirst("has_book=true", "has_book=false");
|
||||
}
|
||||
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, user, type });
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, data, meta, blockData, 0, 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Bed;
|
||||
import org.bukkit.block.data.type.Door;
|
||||
import org.bukkit.block.data.type.Door.Hinge;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class BlockPlaceLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, int replacedType, int replacedData, Material forceType, int forceData, boolean force, List<Object> meta, String blockData, String replaceBlockData) {
|
||||
try {
|
||||
if (user == null || ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
Material type = block.getType();
|
||||
if (blockData == null && (forceType == null || (!forceType.equals(Material.WATER)) && (!forceType.equals(Material.LAVA)))) {
|
||||
blockData = block.getBlockData().getAsString();
|
||||
if (blockData.equals("minecraft:air")) {
|
||||
blockData = null;
|
||||
}
|
||||
}
|
||||
int data = 0;
|
||||
if (forceType != null && force) {
|
||||
type = forceType;
|
||||
if (BukkitAdapter.ADAPTER.isItemFrame(type) || type.equals(Material.SPAWNER) || type.equals(Material.PAINTING) || type.equals(Material.SKELETON_SKULL) || type.equals(Material.SKELETON_WALL_SKULL) || type.equals(Material.WITHER_SKELETON_SKULL) || type.equals(Material.WITHER_SKELETON_WALL_SKULL) || type.equals(Material.ZOMBIE_HEAD) || type.equals(Material.ZOMBIE_WALL_HEAD) || type.equals(Material.PLAYER_HEAD) || type.equals(Material.PLAYER_WALL_HEAD) || type.equals(Material.CREEPER_HEAD) || type.equals(Material.CREEPER_WALL_HEAD) || type.equals(Material.DRAGON_HEAD) || type.equals(Material.DRAGON_WALL_HEAD) || type.equals(Material.ARMOR_STAND) || type.equals(Material.END_CRYSTAL)) {
|
||||
data = forceData; // mob spawner, skull
|
||||
}
|
||||
else if (user.startsWith("#")) {
|
||||
data = forceData;
|
||||
}
|
||||
}
|
||||
else if (forceType != null && !type.equals(forceType)) {
|
||||
type = forceType;
|
||||
data = forceData;
|
||||
}
|
||||
|
||||
if (type.equals(Material.AIR) || type.equals(Material.CAVE_AIR)) {
|
||||
return;
|
||||
}
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int dx = x;
|
||||
int dy = y;
|
||||
int dz = z;
|
||||
Material doubletype = type;
|
||||
int doubledata = data;
|
||||
int logdouble = 0;
|
||||
|
||||
if (user.length() > 0) {
|
||||
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, user, type });
|
||||
}
|
||||
|
||||
String doubleBlockData = null;
|
||||
if (type.name().endsWith("_BED") || type == Material.IRON_DOOR || BlockGroup.DOORS.contains(type)) { // properly log double blocks (doors/beds)
|
||||
BlockData blockStateBlockData = block.getBlockData();
|
||||
if (blockStateBlockData instanceof Bed) {
|
||||
Bed bed = (Bed) blockStateBlockData;
|
||||
Bed.Part bedPart = bed.getPart();
|
||||
BlockFace face = bed.getFacing();
|
||||
|
||||
int bedData = 1;
|
||||
switch (face) {
|
||||
case WEST:
|
||||
dx = ((bedPart == Bed.Part.HEAD) ? (x + 1) : (x - 1));
|
||||
bedData = 2;
|
||||
break;
|
||||
case EAST:
|
||||
dx = ((bedPart == Bed.Part.HEAD) ? (x - 1) : (x + 1));
|
||||
bedData = 3;
|
||||
break;
|
||||
case SOUTH:
|
||||
dz = ((bedPart == Bed.Part.HEAD) ? (z - 1) : (z + 1));
|
||||
bedData = 4;
|
||||
break;
|
||||
default:
|
||||
dz = ((bedPart == Bed.Part.HEAD) ? (z + 1) : (z - 1));
|
||||
break;
|
||||
}
|
||||
|
||||
if (bedPart == Bed.Part.HEAD) {
|
||||
data = 4 + bedData;
|
||||
doubledata = bedData;
|
||||
bed.setPart(Bed.Part.FOOT);
|
||||
doubleBlockData = bed.getAsString();
|
||||
}
|
||||
else {
|
||||
data = bedData;
|
||||
doubledata = 4 + bedData;
|
||||
bed.setPart(Bed.Part.HEAD);
|
||||
doubleBlockData = bed.getAsString();
|
||||
}
|
||||
}
|
||||
else if (blockStateBlockData instanceof Door) {
|
||||
Door door = (Door) blockStateBlockData;
|
||||
BlockFace face = door.getFacing();
|
||||
Hinge hinge = door.getHinge();
|
||||
switch (face) {
|
||||
case EAST:
|
||||
data = 0;
|
||||
break;
|
||||
case SOUTH:
|
||||
data = 1;
|
||||
break;
|
||||
case WEST:
|
||||
data = 2;
|
||||
break;
|
||||
default:
|
||||
data = 3;
|
||||
break;
|
||||
}
|
||||
if (hinge.equals(Hinge.RIGHT)) {
|
||||
data = data + 4;
|
||||
}
|
||||
if (data < 8) {
|
||||
dy = y + 1;
|
||||
doubledata = data + 8;
|
||||
}
|
||||
}
|
||||
logdouble = 1;
|
||||
}
|
||||
|
||||
int internalType = Util.getBlockId(type.name(), true);
|
||||
int internalDoubleType = Util.getBlockId(doubletype.name(), true);
|
||||
|
||||
if (replacedType > 0 && Util.getType(replacedType) != Material.AIR && Util.getType(replacedType) != Material.CAVE_AIR) {
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, replacedType, replacedData, null, replaceBlockData, 0, 0);
|
||||
}
|
||||
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, internalType, data, meta, blockData, 1, 0);
|
||||
if (logdouble == 1) {
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, dx, dy, dz, internalDoubleType, doubledata, null, doubleBlockData, 1, 0);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.ChatStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class ChatLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, int time, Location location, String user, String message) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
ChatStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, message);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.CommandStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class CommandLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, int time, Location location, String user, String message) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
if (ConfigHandler.blacklist.get(((message + " ").split(" "))[0].toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
CommandStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, message);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class ContainerBreakLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String player, Location l, Material type, ItemStack[] oldInventory) {
|
||||
try {
|
||||
Util.mergeItems(type, oldInventory);
|
||||
ContainerLogger.logTransaction(preparedStmt, batchCount, player, type, oldInventory, 0, l);
|
||||
String loggingContainerId = player.toLowerCase(Locale.ROOT) + "." + l.getBlockX() + "." + l.getBlockY() + "." + l.getBlockZ();
|
||||
|
||||
// If there was a pending chest transaction, it would have already been processed.
|
||||
if (ConfigHandler.forceContainer.get(loggingContainerId) != null) {
|
||||
ConfigHandler.forceContainer.remove(loggingContainerId);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
import net.coreprotect.database.statement.ContainerStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
import net.coreprotect.utility.serialize.ItemMetaHandler;
|
||||
|
||||
public class ContainerLogger extends Queue {
|
||||
|
||||
public static void log(PreparedStatement preparedStmtContainer, PreparedStatement preparedStmtItems, int batchCount, String player, Material type, Object container, Location location) {
|
||||
try {
|
||||
ItemStack[] contents = null;
|
||||
if (type.equals(Material.ARMOR_STAND)) {
|
||||
EntityEquipment equipment = (EntityEquipment) container;
|
||||
if (equipment != null) {
|
||||
contents = Util.getArmorStandContents(equipment);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Inventory inventory = (Inventory) container;
|
||||
if (inventory != null) {
|
||||
contents = inventory.getContents();
|
||||
}
|
||||
}
|
||||
|
||||
if (contents == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String loggingContainerId = player.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
List<ItemStack[]> oldList = ConfigHandler.oldContainer.get(loggingContainerId);
|
||||
ItemStack[] oi1 = oldList.get(0);
|
||||
ItemStack[] oldInventory = Util.getContainerState(oi1);
|
||||
ItemStack[] newInventory = Util.getContainerState(contents);
|
||||
if (ConfigHandler.forceContainer.get(loggingContainerId) != null) {
|
||||
List<ItemStack[]> forceList = ConfigHandler.forceContainer.get(loggingContainerId);
|
||||
newInventory = Util.getContainerState(forceList.get(0));
|
||||
int forceSize = modifyForceContainer(loggingContainerId, null);
|
||||
if (forceSize == 0) {
|
||||
ConfigHandler.forceContainer.remove(loggingContainerId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
String transactingChestId = location.getWorld().getUID().toString() + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
if (ConfigHandler.transactingChest.get(transactingChestId) != null) {
|
||||
List<Object> list = Collections.synchronizedList(new ArrayList<>(ConfigHandler.transactingChest.get(transactingChestId)));
|
||||
if (list.size() > 0) {
|
||||
ItemStack[] newMerge = new ItemStack[newInventory.length + list.size()];
|
||||
int count = 0;
|
||||
for (int i = 0; i < newInventory.length; i++) {
|
||||
newMerge[i] = newInventory[i];
|
||||
count++;
|
||||
}
|
||||
for (Object item : list) {
|
||||
ItemStack addItem = null;
|
||||
ItemStack removeItem = null;
|
||||
if (item instanceof ItemStack) {
|
||||
addItem = (ItemStack) item;
|
||||
}
|
||||
else if (item != null) {
|
||||
addItem = ((ItemStack[]) item)[0];
|
||||
removeItem = ((ItemStack[]) item)[1];
|
||||
}
|
||||
|
||||
// item was removed by hopper, add back to state
|
||||
if (addItem != null) {
|
||||
newMerge[count] = addItem;
|
||||
count++;
|
||||
}
|
||||
|
||||
// item was added by hopper, remove from state
|
||||
if (removeItem != null) {
|
||||
for (ItemStack check : newMerge) {
|
||||
if (check != null && check.isSimilar(removeItem)) {
|
||||
check.setAmount(check.getAmount() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
newInventory = newMerge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack oldi : oldInventory) {
|
||||
for (ItemStack newi : newInventory) {
|
||||
if (oldi != null && newi != null) {
|
||||
if (oldi.isSimilar(newi) && !Util.isAir(oldi.getType())) { // Ignores amount
|
||||
int oldAmount = oldi.getAmount();
|
||||
int newAmount = newi.getAmount();
|
||||
if (newAmount >= oldAmount) {
|
||||
newAmount = newAmount - oldAmount;
|
||||
oldi.setAmount(0);
|
||||
newi.setAmount(newAmount);
|
||||
}
|
||||
else {
|
||||
oldAmount = oldAmount - newAmount;
|
||||
oldi.setAmount(oldAmount);
|
||||
newi.setAmount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Util.mergeItems(type, oldInventory);
|
||||
Util.mergeItems(type, newInventory);
|
||||
|
||||
if (type != Material.ENDER_CHEST) {
|
||||
logTransaction(preparedStmtContainer, batchCount, player, type, oldInventory, 0, location);
|
||||
logTransaction(preparedStmtContainer, batchCount, player, type, newInventory, 1, location);
|
||||
}
|
||||
else { // pass ender chest transactions to item logger
|
||||
ItemLogger.logTransaction(preparedStmtItems, batchCount, player, location, oldInventory, ItemLogger.ITEM_REMOVE_ENDER);
|
||||
ItemLogger.logTransaction(preparedStmtItems, batchCount, player, location, newInventory, ItemLogger.ITEM_ADD_ENDER);
|
||||
}
|
||||
|
||||
oldList.remove(0);
|
||||
ConfigHandler.oldContainer.put(loggingContainerId, oldList);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void logTransaction(PreparedStatement preparedStmt, int batchCount, String user, Material type, ItemStack[] items, int action, Location location) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
int slot = 0;
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
if (item.getAmount() > 0 && !Util.isAir(item.getType())) {
|
||||
// Object[] metadata = new Object[] { slot, item.getItemMeta() };
|
||||
List<List<Map<String, Object>>> metadata = ItemMetaHandler.seralize(item, type, slot);
|
||||
if (metadata.size() == 0) {
|
||||
metadata = null;
|
||||
}
|
||||
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int userid = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int typeId = Util.getBlockId(item.getType().name(), true);
|
||||
int data = item.getDurability();
|
||||
int amount = item.getAmount();
|
||||
ContainerStatement.insert(preparedStmt, batchCount, time, userid, wid, x, y, z, typeId, data, amount, metadata, action, 0);
|
||||
}
|
||||
}
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.database.statement.EntityStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class EntityKillLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block, List<Object> data, int type) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int userid = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
EntityStatement.insert(preparedStmt2, time, data);
|
||||
ResultSet keys = preparedStmt2.getGeneratedKeys();
|
||||
keys.next();
|
||||
int entity_key = keys.getInt(1);
|
||||
keys.close();
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userid, wid, x, y, z, type, entity_key, null, null, 3, 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.ItemStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
import net.coreprotect.utility.serialize.ItemMetaHandler;
|
||||
|
||||
public class ItemLogger {
|
||||
|
||||
public static final int ITEM_REMOVE = 0;
|
||||
public static final int ITEM_ADD = 1;
|
||||
public static final int ITEM_DROP = 2;
|
||||
public static final int ITEM_PICKUP = 3;
|
||||
public static final int ITEM_REMOVE_ENDER = 4;
|
||||
public static final int ITEM_ADD_ENDER = 5;
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, Location location, String user) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String loggingItemId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
|
||||
|
||||
List<ItemStack> dropList = ConfigHandler.itemsDrop.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemDrops = new ItemStack[dropList.size()];
|
||||
itemDrops = dropList.toArray(itemDrops);
|
||||
dropList.clear();
|
||||
|
||||
List<ItemStack> pickupList = ConfigHandler.itemsPickup.getOrDefault(loggingItemId, new ArrayList<>());
|
||||
ItemStack[] itemPickups = new ItemStack[pickupList.size()];
|
||||
itemPickups = pickupList.toArray(itemPickups);
|
||||
pickupList.clear();
|
||||
|
||||
Util.mergeItems(null, itemDrops);
|
||||
Util.mergeItems(null, itemPickups);
|
||||
logTransaction(preparedStmt, batchCount, user, location, itemDrops, ITEM_DROP);
|
||||
logTransaction(preparedStmt, batchCount, user, location, itemPickups, ITEM_PICKUP);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void logTransaction(PreparedStatement preparedStmt, int batchCount, String user, Location location, ItemStack[] items, int action) {
|
||||
try {
|
||||
for (ItemStack item : items) {
|
||||
if (item != null && item.getAmount() > 0 && !Util.isAir(item.getType())) {
|
||||
// Object[] metadata = new Object[] { slot, item.getItemMeta() };
|
||||
List<List<Map<String, Object>>> data = ItemMetaHandler.seralize(item, null, 0);
|
||||
if (data.size() == 0) {
|
||||
data = null;
|
||||
}
|
||||
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int userid = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int typeId = Util.getBlockId(item.getType().name(), true);
|
||||
int amount = item.getAmount();
|
||||
ItemStatement.insert(preparedStmt, batchCount, time, userid, wid, x, y, z, typeId, data, amount, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class PlayerInteractLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block) {
|
||||
try {
|
||||
int type = Util.getBlockId(block.getType().name(), true);
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || Util.getType(type).equals(Material.AIR) || Util.getType(type).equals(Material.CAVE_AIR)) {
|
||||
return;
|
||||
}
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int data = 0;
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, data, null, null, 2, 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.BlockStatement;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class PlayerKillLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, BlockState block, String player) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
if (ConfigHandler.playerIdCache.get(player.toLowerCase(Locale.ROOT)) == null) {
|
||||
UserStatement.loadId(preparedStmt.getConnection(), player, null);
|
||||
}
|
||||
int playerId = ConfigHandler.playerIdCache.get(player.toLowerCase(Locale.ROOT));
|
||||
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, 0, playerId, null, null, 3, 0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.SessionStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class PlayerSessionLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int time, int action) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
SessionStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.SignStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class SignTextLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int action, int color, int data, String line1, String line2, String line3, String line4, int timeOffset) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
int userId = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
int wid = Util.getWorldId(location.getWorld().getName());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L) - timeOffset;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
SignStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, action, color, data, line1, line2, line3, line4);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Skull;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.SkullStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class SkullBreakLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || block == null) {
|
||||
return;
|
||||
}
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int type = Util.getBlockId(block.getType().name(), true);
|
||||
Skull skull = (Skull) block;
|
||||
String skullOwner = "";
|
||||
int skullKey = 0;
|
||||
if (skull.hasOwner()) {
|
||||
skullOwner = skull.getOwningPlayer().getUniqueId().toString();
|
||||
SkullStatement.insert(preparedStmt2, time, skullOwner);
|
||||
ResultSet keys = preparedStmt2.getGeneratedKeys();
|
||||
keys.next();
|
||||
skullKey = keys.getInt(1);
|
||||
keys.close();
|
||||
}
|
||||
|
||||
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), type, skullKey, null, block.getBlockData().getAsString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Skull;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.SkullStatement;
|
||||
|
||||
public class SkullPlaceLogger {
|
||||
|
||||
public static void log(PreparedStatement preparedStmt, PreparedStatement preparedStmt2, int batchCount, String user, BlockState block, int replaceType, int replaceData) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || block == null) {
|
||||
return;
|
||||
}
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
Material type = block.getType();
|
||||
int skullKey = 0;
|
||||
|
||||
if (block instanceof Skull) {
|
||||
Skull skull = (Skull) block;
|
||||
String skullOwner = "";
|
||||
if (skull.hasOwner()) {
|
||||
skullOwner = skull.getOwningPlayer().getUniqueId().toString();
|
||||
SkullStatement.insert(preparedStmt2, time, skullOwner);
|
||||
ResultSet keys = preparedStmt2.getGeneratedKeys();
|
||||
keys.next();
|
||||
skullKey = keys.getInt(1);
|
||||
keys.close();
|
||||
}
|
||||
}
|
||||
|
||||
BlockPlaceLogger.log(preparedStmt, batchCount, user, block, replaceType, replaceData, type, skullKey, true, null, null, null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package net.coreprotect.database.logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
|
||||
public class UsernameLogger {
|
||||
|
||||
public static void log(Connection connection, String user, String uuid, int configUsernames, int time) {
|
||||
try {
|
||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int idRow = -1;
|
||||
String userRow = null;
|
||||
String query = "SELECT rowid as id, user FROM " + ConfigHandler.prefix + "user WHERE uuid = ? LIMIT 0, 1";
|
||||
PreparedStatement preparedStmt = connection.prepareStatement(query);
|
||||
preparedStmt.setString(1, uuid);
|
||||
ResultSet rs = preparedStmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
idRow = rs.getInt("id");
|
||||
userRow = rs.getString("user").toLowerCase(Locale.ROOT);
|
||||
}
|
||||
rs.close();
|
||||
preparedStmt.close();
|
||||
|
||||
boolean update = false;
|
||||
if (userRow == null) {
|
||||
idRow = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
|
||||
update = true;
|
||||
}
|
||||
else if (!user.equalsIgnoreCase(userRow)) {
|
||||
update = true;
|
||||
}
|
||||
|
||||
if (update) {
|
||||
preparedStmt = connection.prepareStatement("UPDATE " + ConfigHandler.prefix + "user SET user = ?, uuid = ? WHERE rowid = ?");
|
||||
preparedStmt.setString(1, user);
|
||||
preparedStmt.setString(2, uuid);
|
||||
preparedStmt.setInt(3, idRow);
|
||||
preparedStmt.executeUpdate();
|
||||
preparedStmt.close();
|
||||
|
||||
/*
|
||||
//Commented out to prevent potential issues if player manages to stay logged in with old username
|
||||
if (ConfigHandler.playerIdCache.get(user_row)!=null){
|
||||
int cache_id = ConfigHandler.playerIdCache.get(user_row);
|
||||
if (cache_id==id_row){
|
||||
ConfigHandler.playerIdCache.remove(user_row);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
else {
|
||||
boolean foundUUID = false;
|
||||
query = "SELECT rowid as id FROM " + ConfigHandler.prefix + "username_log WHERE uuid = ? AND user = ? LIMIT 0, 1";
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
||||
preparedStatement.setString(1, uuid);
|
||||
preparedStatement.setString(2, user);
|
||||
rs = preparedStatement.executeQuery();
|
||||
while (rs.next()) {
|
||||
foundUUID = true;
|
||||
}
|
||||
rs.close();
|
||||
preparedStatement.close();
|
||||
|
||||
if (!foundUUID) {
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (update && configUsernames == 1) {
|
||||
preparedStmt = connection.prepareStatement("INSERT INTO " + ConfigHandler.prefix + "username_log (time, uuid, user) VALUES (?, ?, ?)");
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setString(2, uuid);
|
||||
preparedStmt.setString(3, user);
|
||||
preparedStmt.executeUpdate();
|
||||
preparedStmt.close();
|
||||
}
|
||||
|
||||
ConfigHandler.playerIdCache.put(user.toLowerCase(Locale.ROOT), idRow);
|
||||
ConfigHandler.playerIdCacheReversed.put(idRow, user);
|
||||
ConfigHandler.uuidCache.put(user.toLowerCase(Locale.ROOT), uuid);
|
||||
ConfigHandler.uuidCacheReversed.put(uuid, user);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
166
src/main/java/net/coreprotect/database/lookup/BlockLookup.java
Normal file
166
src/main/java/net/coreprotect/database/lookup/BlockLookup.java
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
package net.coreprotect.database.lookup;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class BlockLookup {
|
||||
|
||||
public static String performLookup(String command, Statement statement, BlockState block, CommandSender commandSender, int offset, int page, int limit) {
|
||||
String resultText = "";
|
||||
|
||||
try {
|
||||
if (block == null) {
|
||||
return resultText;
|
||||
}
|
||||
|
||||
if (command == null) {
|
||||
if (commandSender.hasPermission("coreprotect.co")) {
|
||||
command = "co";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.core")) {
|
||||
command = "core";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.coreprotect")) {
|
||||
command = "coreprotect";
|
||||
}
|
||||
else {
|
||||
command = "co";
|
||||
}
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int worldId = Util.getWorldId(block.getWorld().getName());
|
||||
int checkTime = 0;
|
||||
int count = 0;
|
||||
int rowMax = page * limit;
|
||||
int page_start = rowMax - limit;
|
||||
if (offset > 0) {
|
||||
checkTime = time - offset;
|
||||
}
|
||||
|
||||
String blockName = block.getType().name().toLowerCase(Locale.ROOT);
|
||||
|
||||
String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "block WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action IN(0,1) AND time >= '" + checkTime + "' LIMIT 0, 1";
|
||||
ResultSet results = statement.executeQuery(query);
|
||||
while (results.next()) {
|
||||
count = results.getInt("count");
|
||||
}
|
||||
results.close();
|
||||
int totalPages = (int) Math.ceil(count / (limit + 0.0));
|
||||
|
||||
query = "SELECT time,user,action,type,data,rolled_back FROM " + ConfigHandler.prefix + "block WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action IN(0,1) AND time >= '" + checkTime + "' ORDER BY rowid DESC LIMIT " + page_start + ", " + limit + "";
|
||||
results = statement.executeQuery(query);
|
||||
|
||||
StringBuilder resultTextBuilder = new StringBuilder();
|
||||
|
||||
while (results.next()) {
|
||||
int resultUserId = results.getInt("user");
|
||||
int resultAction = results.getInt("action");
|
||||
int resultType = results.getInt("type");
|
||||
int resultData = results.getInt("data");
|
||||
int resultTime = results.getInt("time");
|
||||
int resultRolledBack = results.getInt("rolled_back");
|
||||
|
||||
if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) {
|
||||
UserStatement.loadName(statement.getConnection(), resultUserId);
|
||||
}
|
||||
|
||||
String resultUser = ConfigHandler.playerIdCacheReversed.get(resultUserId);
|
||||
String timeAgo = Util.getTimeSince(resultTime, time, true);
|
||||
|
||||
if (!found) {
|
||||
resultTextBuilder = new StringBuilder(Color.WHITE + "----- " + Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "----- " + Util.getCoordinates(command, worldId, x, y, z, false, false) + "\n");
|
||||
}
|
||||
found = true;
|
||||
|
||||
Phrase phrase = Phrase.LOOKUP_BLOCK;
|
||||
String selector = Selector.FIRST;
|
||||
if (resultAction == 2 || resultAction == 3) {
|
||||
phrase = Phrase.LOOKUP_INTERACTION; // {clicked|killed}
|
||||
selector = (resultAction != 3 ? Selector.FIRST : Selector.SECOND);
|
||||
}
|
||||
else {
|
||||
phrase = Phrase.LOOKUP_BLOCK; // {placed|broke}
|
||||
selector = (resultAction != 0 ? Selector.FIRST : Selector.SECOND);
|
||||
}
|
||||
|
||||
String rbFormat = "";
|
||||
if (resultRolledBack == 1) {
|
||||
rbFormat = Color.STRIKETHROUGH;
|
||||
}
|
||||
|
||||
String target;
|
||||
if (resultAction == 3) {
|
||||
target = Util.getEntityType(resultType).name();
|
||||
}
|
||||
else {
|
||||
Material resultMaterial = Util.getType(resultType);
|
||||
if (resultMaterial == null) {
|
||||
resultMaterial = Material.AIR;
|
||||
}
|
||||
target = Util.nameFilter(resultMaterial.name().toLowerCase(Locale.ROOT), resultData);
|
||||
target = "minecraft:" + target.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
if (target.length() > 0) {
|
||||
target = "" + target + "";
|
||||
}
|
||||
|
||||
// Hide "minecraft:" for now.
|
||||
if (target.startsWith("minecraft:")) {
|
||||
target = target.split(":")[1];
|
||||
}
|
||||
|
||||
resultTextBuilder.append(timeAgo + " " + Color.WHITE + "- ").append(Phrase.build(phrase, Color.DARK_AQUA + rbFormat + resultUser + Color.WHITE + rbFormat, Color.DARK_AQUA + rbFormat + target + Color.WHITE, selector)).append("\n");
|
||||
}
|
||||
|
||||
resultText = resultTextBuilder.toString();
|
||||
results.close();
|
||||
|
||||
if (found) {
|
||||
if (count > limit) {
|
||||
String pageInfo = Color.WHITE + "-----\n";
|
||||
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>") + "\n";
|
||||
resultText = resultText + pageInfo;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (rowMax > count && count > 0) {
|
||||
resultText = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_RESULTS_PAGE, Selector.SECOND);
|
||||
}
|
||||
else {
|
||||
// resultText = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Color.WHITE + "No block data found at " + Color.ITALIC + "x" + x + "/y" + y + "/z" + z + ".";
|
||||
resultText = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_DATA_LOCATION, Selector.FIRST);
|
||||
if (!blockName.equals("air") && !blockName.equals("cave_air")) {
|
||||
resultText = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_DATA, Color.ITALIC + block.getType().name().toLowerCase(Locale.ROOT)) + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigHandler.lookupPage.put(commandSender.getName(), page);
|
||||
ConfigHandler.lookupType.put(commandSender.getName(), 2);
|
||||
ConfigHandler.lookupCommand.put(commandSender.getName(), x + "." + y + "." + z + "." + worldId + ".0." + limit);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return resultText;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package net.coreprotect.database.lookup;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.Database;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class BlockLookupAPI {
|
||||
|
||||
public static List<String[]> performLookup(Block block, int offset) {
|
||||
List<String[]> result = new ArrayList<>();
|
||||
|
||||
try {
|
||||
if (block == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int worldId = Util.getWorldId(block.getWorld().getName());
|
||||
int checkTime = 0;
|
||||
if (offset > 0) {
|
||||
checkTime = time - offset;
|
||||
}
|
||||
|
||||
Connection connection = Database.getConnection(false, 1000);
|
||||
if (connection == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
String query = "SELECT time,user,action,type,data,blockdata,rolled_back FROM " + ConfigHandler.prefix + "block WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND time > '" + checkTime + "' ORDER BY rowid DESC";
|
||||
ResultSet results = statement.executeQuery(query);
|
||||
|
||||
while (results.next()) {
|
||||
String resultTime = results.getString("time");
|
||||
int resultUserId = results.getInt("user");
|
||||
String resultAction = results.getString("action");
|
||||
int resultType = results.getInt("type");
|
||||
String resultData = results.getString("data");
|
||||
byte[] resultBlockData = results.getBytes("blockdata");
|
||||
String resultRolledBack = results.getString("rolled_back");
|
||||
if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) {
|
||||
UserStatement.loadName(connection, resultUserId);
|
||||
}
|
||||
String resultUser = ConfigHandler.playerIdCacheReversed.get(resultUserId);
|
||||
String blockData = Util.byteDataToString(resultBlockData, resultType);
|
||||
|
||||
String[] lookupData = new String[] { resultTime, resultUser, String.valueOf(x), String.valueOf(y), String.valueOf(z), String.valueOf(resultType), resultData, resultAction, resultRolledBack, String.valueOf(worldId), blockData };
|
||||
String[] lineData = Util.toStringArray(lookupData);
|
||||
result.add(lineData);
|
||||
}
|
||||
results.close();
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
package net.coreprotect.database.lookup;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class ChestTransactionLookup {
|
||||
|
||||
public static String performLookup(String command, Statement statement, Location l, CommandSender commandSender, int page, int limit, boolean exact) {
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (l == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (command == null) {
|
||||
if (commandSender.hasPermission("coreprotect.co")) {
|
||||
command = "co";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.core")) {
|
||||
command = "core";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.coreprotect")) {
|
||||
command = "coreprotect";
|
||||
}
|
||||
else {
|
||||
command = "co";
|
||||
}
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
int x = (int) Math.floor(l.getX());
|
||||
int y = (int) Math.floor(l.getY());
|
||||
int z = (int) Math.floor(l.getZ());
|
||||
int x2 = (int) Math.ceil(l.getX());
|
||||
int y2 = (int) Math.ceil(l.getY());
|
||||
int z2 = (int) Math.ceil(l.getZ());
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int worldId = Util.getWorldId(l.getWorld().getName());
|
||||
int count = 0;
|
||||
int rowMax = page * limit;
|
||||
int pageStart = rowMax - limit;
|
||||
|
||||
String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "container WHERE wid = '" + worldId + "' AND (x = '" + x + "' OR x = '" + x2 + "') AND (z = '" + z + "' OR z = '" + z2 + "') AND y = '" + y + "' LIMIT 0, 1";
|
||||
if (exact) {
|
||||
query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "container WHERE wid = '" + worldId + "' AND (x = '" + l.getBlockX() + "') AND (z = '" + l.getBlockZ() + "') AND y = '" + y + "' LIMIT 0, 1";
|
||||
}
|
||||
ResultSet results = statement.executeQuery(query);
|
||||
|
||||
while (results.next()) {
|
||||
count = results.getInt("count");
|
||||
}
|
||||
results.close();
|
||||
|
||||
int totalPages = (int) Math.ceil(count / (limit + 0.0));
|
||||
|
||||
query = "SELECT time,user,action,type,data,amount,rolled_back FROM " + ConfigHandler.prefix + "container WHERE wid = '" + worldId + "' AND (x = '" + x + "' OR x = '" + x2 + "') AND (z = '" + z + "' OR z = '" + z2 + "') AND y = '" + y + "' ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + "";
|
||||
if (exact) {
|
||||
query = "SELECT time,user,action,type,data,amount,rolled_back FROM " + ConfigHandler.prefix + "container WHERE wid = '" + worldId + "' AND (x = '" + l.getBlockX() + "') AND (z = '" + l.getBlockZ() + "') AND y = '" + y + "' ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + "";
|
||||
}
|
||||
results = statement.executeQuery(query);
|
||||
|
||||
StringBuilder resultBuilder = new StringBuilder();
|
||||
while (results.next()) {
|
||||
int resultUserId = results.getInt("user");
|
||||
int resultAction = results.getInt("action");
|
||||
int resultType = results.getInt("type");
|
||||
int resultData = results.getInt("data");
|
||||
int resultTime = results.getInt("time");
|
||||
int resultAmount = results.getInt("amount");
|
||||
int resultRolledBack = results.getInt("rolled_back");
|
||||
|
||||
if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) {
|
||||
UserStatement.loadName(statement.getConnection(), resultUserId);
|
||||
}
|
||||
|
||||
String resultUser = ConfigHandler.playerIdCacheReversed.get(resultUserId);
|
||||
String timeAgo = Util.getTimeSince(resultTime, time, true);
|
||||
|
||||
if (!found) {
|
||||
resultBuilder = new StringBuilder(Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.CONTAINER_HEADER) + Color.WHITE + " ----- " + Util.getCoordinates(command, worldId, x, y, z, false, false) + "\n");
|
||||
}
|
||||
found = true;
|
||||
|
||||
String selector = (resultAction != 0 ? Selector.FIRST : Selector.SECOND);
|
||||
String rbFormat = "";
|
||||
if (resultRolledBack == 1) {
|
||||
rbFormat = Color.STRIKETHROUGH;
|
||||
}
|
||||
|
||||
Material resultMaterial = Util.getType(resultType);
|
||||
if (resultMaterial == null) {
|
||||
resultMaterial = Material.AIR;
|
||||
}
|
||||
String target = resultMaterial.name().toLowerCase(Locale.ROOT);
|
||||
target = Util.nameFilter(target, resultData);
|
||||
if (target.length() > 0) {
|
||||
target = "minecraft:" + target.toLowerCase(Locale.ROOT) + "";
|
||||
}
|
||||
|
||||
// Hide "minecraft:" for now.
|
||||
if (target.startsWith("minecraft:")) {
|
||||
target = target.split(":")[1];
|
||||
}
|
||||
|
||||
resultBuilder.append(timeAgo + " " + Color.WHITE + "- ").append(Phrase.build(Phrase.LOOKUP_CONTAINER, Color.DARK_AQUA + rbFormat + resultUser + Color.WHITE + rbFormat, "x" + resultAmount, Color.DARK_AQUA + rbFormat + target + Color.WHITE, selector)).append("\n");
|
||||
}
|
||||
result = resultBuilder.toString();
|
||||
results.close();
|
||||
|
||||
if (found) {
|
||||
if (count > limit) {
|
||||
String pageInfo = Color.WHITE + "-----\n";
|
||||
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>") + "\n";
|
||||
result = result + pageInfo;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (rowMax > count && count > 0) {
|
||||
result = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_RESULTS_PAGE, Selector.SECOND);
|
||||
}
|
||||
else {
|
||||
result = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_DATA_LOCATION, Selector.SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigHandler.lookupType.put(commandSender.getName(), 1);
|
||||
ConfigHandler.lookupPage.put(commandSender.getName(), page);
|
||||
ConfigHandler.lookupCommand.put(commandSender.getName(), x + "." + y + "." + z + "." + worldId + "." + x2 + "." + y2 + "." + z2 + "." + limit);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
package net.coreprotect.database.lookup;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class InteractionLookup {
|
||||
|
||||
public static String performLookup(String command, Statement statement, Block block, CommandSender commandSender, int offset, int page, int limit) {
|
||||
String result = "";
|
||||
|
||||
try {
|
||||
if (block == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (command == null) {
|
||||
if (commandSender.hasPermission("coreprotect.co")) {
|
||||
command = "co";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.core")) {
|
||||
command = "core";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.coreprotect")) {
|
||||
command = "coreprotect";
|
||||
}
|
||||
else {
|
||||
command = "co";
|
||||
}
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int worldId = Util.getWorldId(block.getWorld().getName());
|
||||
int checkTime = 0;
|
||||
int count = 0;
|
||||
int rowMax = page * limit;
|
||||
int pageStart = rowMax - limit;
|
||||
if (offset > 0) {
|
||||
checkTime = time - offset;
|
||||
}
|
||||
|
||||
String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "block WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action='2' AND time >= '" + checkTime + "' LIMIT 0, 1";
|
||||
ResultSet results = statement.executeQuery(query);
|
||||
|
||||
while (results.next()) {
|
||||
count = results.getInt("count");
|
||||
}
|
||||
results.close();
|
||||
int totalPages = (int) Math.ceil(count / (limit + 0.0));
|
||||
|
||||
query = "SELECT time,user,action,type,data,rolled_back FROM " + ConfigHandler.prefix + "block WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action='2' AND time >= '" + checkTime + "' ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + "";
|
||||
results = statement.executeQuery(query);
|
||||
|
||||
StringBuilder resultBuilder = new StringBuilder();
|
||||
while (results.next()) {
|
||||
int resultUserId = results.getInt("user");
|
||||
int resultAction = results.getInt("action");
|
||||
int resultType = results.getInt("type");
|
||||
int resultData = results.getInt("data");
|
||||
int resultTime = results.getInt("time");
|
||||
int resultRolledBack = results.getInt("rolled_back");
|
||||
|
||||
if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) {
|
||||
UserStatement.loadName(statement.getConnection(), resultUserId);
|
||||
}
|
||||
|
||||
String resultUser = ConfigHandler.playerIdCacheReversed.get(resultUserId);
|
||||
String timeAgo = Util.getTimeSince(resultTime, time, true);
|
||||
|
||||
if (!found) {
|
||||
resultBuilder = new StringBuilder(Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.INTERACTIONS_HEADER) + Color.WHITE + " ----- " + Util.getCoordinates(command, worldId, x, y, z, false, false) + "\n");
|
||||
}
|
||||
found = true;
|
||||
|
||||
String rbFormat = "";
|
||||
if (resultRolledBack == 1) {
|
||||
rbFormat = Color.STRIKETHROUGH;
|
||||
}
|
||||
|
||||
Material resultMaterial = Util.getType(resultType);
|
||||
if (resultMaterial == null) {
|
||||
resultMaterial = Material.AIR;
|
||||
}
|
||||
String target = resultMaterial.name().toLowerCase(Locale.ROOT);
|
||||
target = Util.nameFilter(target, resultData);
|
||||
if (target.length() > 0) {
|
||||
target = "minecraft:" + target.toLowerCase(Locale.ROOT) + "";
|
||||
}
|
||||
|
||||
// Hide "minecraft:" for now.
|
||||
if (target.startsWith("minecraft:")) {
|
||||
target = target.split(":")[1];
|
||||
}
|
||||
|
||||
resultBuilder.append(timeAgo + " " + Color.WHITE + "- ").append(Phrase.build(Phrase.LOOKUP_INTERACTION, Color.DARK_AQUA + rbFormat + resultUser + Color.WHITE + rbFormat, Color.DARK_AQUA + rbFormat + target + Color.WHITE, Selector.FIRST)).append("\n");
|
||||
}
|
||||
result = resultBuilder.toString();
|
||||
results.close();
|
||||
|
||||
if (found) {
|
||||
if (count > limit) {
|
||||
String pageInfo = Color.WHITE + "-----\n";
|
||||
pageInfo = pageInfo + Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>") + "\n";
|
||||
result = result + pageInfo;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (rowMax > count && count > 0) {
|
||||
result = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_RESULTS_PAGE, Selector.SECOND);
|
||||
}
|
||||
else {
|
||||
result = Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_DATA_LOCATION, Selector.THIRD);
|
||||
}
|
||||
}
|
||||
|
||||
ConfigHandler.lookupPage.put(commandSender.getName(), page);
|
||||
ConfigHandler.lookupType.put(commandSender.getName(), 7);
|
||||
ConfigHandler.lookupCommand.put(commandSender.getName(), x + "." + y + "." + z + "." + worldId + ".2." + limit);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package net.coreprotect.database.lookup;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
|
||||
public class PlayerLookup {
|
||||
|
||||
public static boolean playerExists(Connection connection, String user) {
|
||||
try {
|
||||
int id = -1;
|
||||
String uuid = null;
|
||||
|
||||
if (ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT)) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String collate = "";
|
||||
if (!Config.getGlobal().MYSQL) {
|
||||
collate = " COLLATE NOCASE";
|
||||
}
|
||||
|
||||
String query = "SELECT rowid as id, uuid FROM " + ConfigHandler.prefix + "user WHERE user = ?" + collate + " LIMIT 0, 1";
|
||||
PreparedStatement preparedStmt = connection.prepareStatement(query);
|
||||
preparedStmt.setString(1, user);
|
||||
|
||||
ResultSet results = preparedStmt.executeQuery();
|
||||
|
||||
while (results.next()) {
|
||||
id = results.getInt("id");
|
||||
uuid = results.getString("uuid");
|
||||
}
|
||||
results.close();
|
||||
preparedStmt.close();
|
||||
|
||||
if (id > -1) {
|
||||
if (uuid != null) {
|
||||
ConfigHandler.uuidCache.put(user.toLowerCase(Locale.ROOT), uuid);
|
||||
ConfigHandler.uuidCacheReversed.put(uuid, user);
|
||||
}
|
||||
|
||||
ConfigHandler.playerIdCache.put(user.toLowerCase(Locale.ROOT), id);
|
||||
ConfigHandler.playerIdCacheReversed.put(id, user);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
package net.coreprotect.database.lookup;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.UserStatement;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class SignMessageLookup {
|
||||
|
||||
public static List<String> performLookup(String command, Statement statement, Location l, CommandSender commandSender, int page, int limit) {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
try {
|
||||
if (l == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (command == null) {
|
||||
if (commandSender.hasPermission("coreprotect.co")) {
|
||||
command = "co";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.core")) {
|
||||
command = "core";
|
||||
}
|
||||
else if (commandSender.hasPermission("coreprotect.coreprotect")) {
|
||||
command = "coreprotect";
|
||||
}
|
||||
else {
|
||||
command = "co";
|
||||
}
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
int x = l.getBlockX();
|
||||
int y = l.getBlockY();
|
||||
int z = l.getBlockZ();
|
||||
int time = (int) (System.currentTimeMillis() / 1000L);
|
||||
int worldId = Util.getWorldId(l.getWorld().getName());
|
||||
int count = 0;
|
||||
int rowMax = page * limit;
|
||||
int pageStart = rowMax - limit;
|
||||
|
||||
String query = "SELECT COUNT(*) as count from " + ConfigHandler.prefix + "sign WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) LIMIT 0, 1";
|
||||
ResultSet results = statement.executeQuery(query);
|
||||
|
||||
while (results.next()) {
|
||||
count = results.getInt("count");
|
||||
}
|
||||
results.close();
|
||||
|
||||
int totalPages = (int) Math.ceil(count / (limit + 0.0));
|
||||
|
||||
query = "SELECT time,user,line_1,line_2,line_3,line_4 FROM " + ConfigHandler.prefix + "sign WHERE wid = '" + worldId + "' AND x = '" + x + "' AND z = '" + z + "' AND y = '" + y + "' AND action = '1' AND (LENGTH(line_1) > 0 OR LENGTH(line_2) > 0 OR LENGTH(line_3) > 0 OR LENGTH(line_4) > 0) ORDER BY rowid DESC LIMIT " + pageStart + ", " + limit + "";
|
||||
results = statement.executeQuery(query);
|
||||
|
||||
while (results.next()) {
|
||||
int resultTime = results.getInt("time");
|
||||
int resultUserId = results.getInt("user");
|
||||
String line1 = results.getString("line_1");
|
||||
String line2 = results.getString("line_2");
|
||||
String line3 = results.getString("line_3");
|
||||
String line4 = results.getString("line_4");
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
if (line1 != null && line1.length() > 0) {
|
||||
message.append(line1);
|
||||
if (!line1.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
if (line2 != null && line2.length() > 0) {
|
||||
message.append(line2);
|
||||
if (!line2.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
if (line3 != null && line3.length() > 0) {
|
||||
message.append(line3);
|
||||
if (!line3.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
if (line4 != null && line4.length() > 0) {
|
||||
message.append(line4);
|
||||
if (!line4.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigHandler.playerIdCacheReversed.get(resultUserId) == null) {
|
||||
UserStatement.loadName(statement.getConnection(), resultUserId);
|
||||
}
|
||||
|
||||
String resultUser = ConfigHandler.playerIdCacheReversed.get(resultUserId);
|
||||
String timeAgo = Util.getTimeSince(resultTime, time, true);
|
||||
|
||||
if (!found) {
|
||||
result.add(new StringBuilder(Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.SIGN_HEADER) + Color.WHITE + " ----- " + Util.getCoordinates(command, worldId, x, y, z, false, false) + "").toString());
|
||||
}
|
||||
found = true;
|
||||
result.add(timeAgo + Color.WHITE + " - " + Color.DARK_AQUA + resultUser + ": " + Color.WHITE + "\n" + message.toString() + Color.WHITE);
|
||||
}
|
||||
results.close();
|
||||
|
||||
if (found) {
|
||||
if (count > limit) {
|
||||
result.add(Color.WHITE + "-----");
|
||||
result.add(Util.getPageNavigation(command, page, totalPages) + "| " + Phrase.build(Phrase.LOOKUP_VIEW_PAGE, Color.WHITE, "/co l <page>"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (rowMax > count && count > 0) {
|
||||
result.add(Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_RESULTS_PAGE, Selector.SECOND));
|
||||
}
|
||||
else {
|
||||
result.add(Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_DATA_LOCATION, Selector.FOURTH));
|
||||
}
|
||||
}
|
||||
|
||||
ConfigHandler.lookupType.put(commandSender.getName(), 8);
|
||||
ConfigHandler.lookupPage.put(commandSender.getName(), page);
|
||||
ConfigHandler.lookupCommand.put(commandSender.getName(), x + "." + y + "." + z + "." + worldId + ".8." + limit);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class BlockStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int type, int data, List<Object> meta, String blockData, int action, int rolledBack) {
|
||||
try {
|
||||
byte[] bBlockData = Util.stringToByteData(blockData, type);
|
||||
byte[] byteData = null;
|
||||
|
||||
if (meta != null) {
|
||||
byteData = Util.convertByteData(meta);
|
||||
}
|
||||
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setInt(2, id);
|
||||
preparedStmt.setInt(3, wid);
|
||||
preparedStmt.setInt(4, x);
|
||||
preparedStmt.setInt(5, y);
|
||||
preparedStmt.setInt(6, z);
|
||||
preparedStmt.setInt(7, type);
|
||||
preparedStmt.setInt(8, data);
|
||||
preparedStmt.setObject(9, byteData);
|
||||
preparedStmt.setObject(10, bBlockData);
|
||||
preparedStmt.setInt(11, action);
|
||||
preparedStmt.setInt(12, rolledBack);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class ChatStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int user, int wid, int x, int y, int z, String message) {
|
||||
try {
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setInt(2, user);
|
||||
preparedStmt.setInt(3, wid);
|
||||
preparedStmt.setInt(4, x);
|
||||
preparedStmt.setInt(5, y);
|
||||
preparedStmt.setInt(6, z);
|
||||
preparedStmt.setString(7, message);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class CommandStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int user, int wid, int x, int y, int z, String message) {
|
||||
try {
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setInt(2, user);
|
||||
preparedStmt.setInt(3, wid);
|
||||
preparedStmt.setInt(4, x);
|
||||
preparedStmt.setInt(5, y);
|
||||
preparedStmt.setInt(6, z);
|
||||
preparedStmt.setString(7, message);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class ContainerStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int type, int data, int amount, Object metadata, int action, int rolledBack) {
|
||||
try {
|
||||
byte[] byteData = Util.convertByteData(metadata);
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setInt(2, id);
|
||||
preparedStmt.setInt(3, wid);
|
||||
preparedStmt.setInt(4, x);
|
||||
preparedStmt.setInt(5, y);
|
||||
preparedStmt.setInt(6, z);
|
||||
preparedStmt.setInt(7, type);
|
||||
preparedStmt.setInt(8, data);
|
||||
preparedStmt.setInt(9, amount);
|
||||
preparedStmt.setObject(10, byteData);
|
||||
preparedStmt.setInt(11, action);
|
||||
preparedStmt.setInt(12, rolledBack);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
|
||||
public class EntityStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int time, List<Object> data) {
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream oos = new BukkitObjectOutputStream(bos);
|
||||
oos.writeObject(data);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
bos.close();
|
||||
|
||||
byte[] byte_data = bos.toByteArray();
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setObject(2, byte_data);
|
||||
preparedStmt.executeUpdate();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Object> getData(Statement statement, BlockState block, String query) {
|
||||
List<Object> result = new ArrayList<>();
|
||||
|
||||
try {
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
while (resultSet.next()) {
|
||||
byte[] data = resultSet.getBytes("data");
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||
BukkitObjectInputStream ins = new BukkitObjectInputStream(bais);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> input = (List<Object>) ins.readObject();
|
||||
ins.close();
|
||||
bais.close();
|
||||
result = input;
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class ItemStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int type, Object data, int amount, int action) {
|
||||
try {
|
||||
byte[] byteData = Util.convertByteData(data);
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setInt(2, id);
|
||||
preparedStmt.setInt(3, wid);
|
||||
preparedStmt.setInt(4, x);
|
||||
preparedStmt.setInt(5, y);
|
||||
preparedStmt.setInt(6, z);
|
||||
preparedStmt.setInt(7, type);
|
||||
preparedStmt.setObject(8, byteData);
|
||||
preparedStmt.setInt(9, amount);
|
||||
preparedStmt.setInt(10, action);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class MaterialStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int id, String name) {
|
||||
try {
|
||||
preparedStmt.setInt(1, id);
|
||||
preparedStmt.setString(2, name);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasMaterial(Statement statement, String query) {
|
||||
boolean result = false;
|
||||
|
||||
try {
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
if (resultSet.next()) {
|
||||
result = true;
|
||||
}
|
||||
resultSet.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class SessionStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int user, int wid, int x, int y, int z, int action) {
|
||||
try {
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setInt(2, user);
|
||||
preparedStmt.setInt(3, wid);
|
||||
preparedStmt.setInt(4, x);
|
||||
preparedStmt.setInt(5, y);
|
||||
preparedStmt.setInt(6, z);
|
||||
preparedStmt.setInt(7, action);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
|
||||
public class SignStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int time, int id, int wid, int x, int y, int z, int action, int color, int data, String line1, String line2, String line3, String line4) {
|
||||
try {
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setInt(2, id);
|
||||
preparedStmt.setInt(3, wid);
|
||||
preparedStmt.setInt(4, x);
|
||||
preparedStmt.setInt(5, y);
|
||||
preparedStmt.setInt(6, z);
|
||||
preparedStmt.setInt(7, action);
|
||||
preparedStmt.setInt(8, color);
|
||||
preparedStmt.setInt(9, data);
|
||||
preparedStmt.setString(10, line1);
|
||||
preparedStmt.setString(11, line2);
|
||||
preparedStmt.setString(12, line3);
|
||||
preparedStmt.setString(13, line4);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void getData(Statement statement, BlockState block, String query) {
|
||||
try {
|
||||
if (!(block instanceof Sign)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sign sign = (Sign) block;
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
|
||||
while (resultSet.next()) {
|
||||
int color = resultSet.getInt("color");
|
||||
int data = resultSet.getInt("data");
|
||||
String line1 = resultSet.getString("line_1");
|
||||
String line2 = resultSet.getString("line_2");
|
||||
String line3 = resultSet.getString("line_3");
|
||||
String line4 = resultSet.getString("line_4");
|
||||
|
||||
if (color > 0) {
|
||||
sign.setColor(DyeColor.getByColor(Color.fromRGB(color)));
|
||||
}
|
||||
|
||||
if (data > 0) {
|
||||
BukkitAdapter.ADAPTER.setGlowing(sign, (data == 1 ? true : false));
|
||||
}
|
||||
|
||||
sign.setLine(0, line1);
|
||||
sign.setLine(1, line2);
|
||||
sign.setLine(2, line3);
|
||||
sign.setLine(3, line4);
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Skull;
|
||||
|
||||
public class SkullStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int time, String owner) {
|
||||
try {
|
||||
preparedStmt.setInt(1, time);
|
||||
preparedStmt.setString(2, owner);
|
||||
preparedStmt.executeUpdate();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void getData(Statement statement, BlockState block, String query) {
|
||||
try {
|
||||
if (!(block instanceof Skull)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Skull skull = (Skull) block;
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
|
||||
while (resultSet.next()) {
|
||||
String owner = resultSet.getString("owner");
|
||||
if (owner != null && owner.length() >= 32) {
|
||||
skull.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(owner)));
|
||||
}
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
|
||||
public class UserStatement {
|
||||
|
||||
public static int insert(Connection connection, String user) {
|
||||
int id = -1;
|
||||
|
||||
try {
|
||||
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
PreparedStatement preparedStmt = connection.prepareStatement("INSERT INTO " + ConfigHandler.prefix + "user (time, user) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
|
||||
preparedStmt.setInt(1, unixtimestamp);
|
||||
preparedStmt.setString(2, user);
|
||||
preparedStmt.executeUpdate();
|
||||
ResultSet keys = preparedStmt.getGeneratedKeys();
|
||||
keys.next();
|
||||
id = keys.getInt(1);
|
||||
keys.close();
|
||||
preparedStmt.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public static int loadId(Connection connection, String user, String uuid) {
|
||||
// generate if doesn't exist
|
||||
int id = -1;
|
||||
|
||||
try {
|
||||
String collate = "";
|
||||
if (!Config.getGlobal().MYSQL) {
|
||||
collate = " COLLATE NOCASE";
|
||||
}
|
||||
|
||||
String where = "user = ?" + collate;
|
||||
if (uuid != null) {
|
||||
where = where + " OR uuid = ?";
|
||||
}
|
||||
|
||||
String query = "SELECT rowid as id, uuid FROM " + ConfigHandler.prefix + "user WHERE " + where + " ORDER BY rowid ASC LIMIT 0, 1";
|
||||
PreparedStatement preparedStmt = connection.prepareStatement(query);
|
||||
preparedStmt.setString(1, user);
|
||||
|
||||
if (uuid != null) {
|
||||
preparedStmt.setString(2, uuid);
|
||||
}
|
||||
|
||||
ResultSet resultSet = preparedStmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
id = resultSet.getInt("id");
|
||||
uuid = resultSet.getString("uuid");
|
||||
}
|
||||
resultSet.close();
|
||||
preparedStmt.close();
|
||||
|
||||
if (id == -1) {
|
||||
id = insert(connection, user);
|
||||
}
|
||||
|
||||
ConfigHandler.playerIdCache.put(user.toLowerCase(Locale.ROOT), id);
|
||||
ConfigHandler.playerIdCacheReversed.put(id, user);
|
||||
if (uuid != null) {
|
||||
ConfigHandler.uuidCache.put(user.toLowerCase(Locale.ROOT), uuid);
|
||||
ConfigHandler.uuidCacheReversed.put(uuid, user);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public static String loadName(Connection connection, int id) {
|
||||
// generate if doesn't exist
|
||||
String user = "";
|
||||
String uuid = null;
|
||||
|
||||
try {
|
||||
Statement statement = connection.createStatement();
|
||||
String query = "SELECT user, uuid FROM " + ConfigHandler.prefix + "user WHERE rowid='" + id + "' LIMIT 0, 1";
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(query);
|
||||
while (resultSet.next()) {
|
||||
user = resultSet.getString("user");
|
||||
uuid = resultSet.getString("uuid");
|
||||
}
|
||||
|
||||
if (user.length() == 0) {
|
||||
return user;
|
||||
}
|
||||
|
||||
ConfigHandler.playerIdCache.put(user.toLowerCase(Locale.ROOT), id);
|
||||
ConfigHandler.playerIdCacheReversed.put(id, user);
|
||||
if (uuid != null) {
|
||||
ConfigHandler.uuidCache.put(user.toLowerCase(Locale.ROOT), uuid);
|
||||
ConfigHandler.uuidCacheReversed.put(uuid, user);
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
statement.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package net.coreprotect.database.statement;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class WorldStatement {
|
||||
|
||||
public static void insert(PreparedStatement preparedStmt, int batchCount, int id, String world) {
|
||||
try {
|
||||
preparedStmt.setInt(1, id);
|
||||
preparedStmt.setString(2, world);
|
||||
preparedStmt.addBatch();
|
||||
|
||||
if (batchCount > 0 && batchCount % 1000 == 0) {
|
||||
preparedStmt.executeBatch();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue