CoreProtect v20.0 release

This commit is contained in:
Intelli 2021-07-16 12:13:54 -06:00
parent 415d7b323a
commit 48ef18e2c8
173 changed files with 25072 additions and 1 deletions

View file

@ -0,0 +1,166 @@
package net.coreprotect.consumer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.inventory.ItemStack;
import net.coreprotect.CoreProtect;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.process.Process;
public class Consumer extends Process implements Runnable, Thread.UncaughtExceptionHandler {
public static volatile boolean resetConnection = false;
public static volatile int currentConsumer = 0;
public static volatile boolean isPaused = false;
public static volatile boolean transacting = false;
public static volatile boolean interrupt = false;
private static volatile boolean running = false;
protected static volatile boolean pausedSuccess = false;
public static ConcurrentHashMap<Integer, ArrayList<Object[]>> consumer = new ConcurrentHashMap<>(4, 0.75f, 2);
// public static ConcurrentHashMap<Integer, Integer[]> consumer_id = new ConcurrentHashMap<>();
public static Map<Integer, Integer[]> consumer_id = Collections.synchronizedMap(new HashMap<>());
public static ConcurrentHashMap<Integer, Map<Integer, String[]>> consumerUsers = new ConcurrentHashMap<>(4, 0.75f, 2);
@Deprecated
public static ConcurrentHashMap<Integer, Map<Integer, String>> consumerStrings = new ConcurrentHashMap<>(4, 0.75f, 2);
@Deprecated
public static ConcurrentHashMap<Integer, Map<Integer, Object[]>> consumerSigns = new ConcurrentHashMap<>(4, 0.75f, 2);
@Deprecated
public static ConcurrentHashMap<Integer, Map<Integer, ItemStack[]>> consumerContainers = new ConcurrentHashMap<>(4, 0.75f, 2);
@Deprecated
public static ConcurrentHashMap<Integer, Map<Integer, Object>> consumerInventories = new ConcurrentHashMap<>(4, 0.75f, 2);
@Deprecated
public static ConcurrentHashMap<Integer, Map<Integer, List<BlockState>>> consumerBlockList = new ConcurrentHashMap<>(4, 0.75f, 2);
@Deprecated
public static ConcurrentHashMap<Integer, Map<Integer, List<Object[]>>> consumerObjectArrayList = new ConcurrentHashMap<>(4, 0.75f, 2);
@Deprecated
public static ConcurrentHashMap<Integer, Map<Integer, List<Object>>> consumerObjectList = new ConcurrentHashMap<>(4, 0.75f, 2);
public static ConcurrentHashMap<Integer, Map<Integer, Object>> consumerObjects = new ConcurrentHashMap<>(4, 0.75f, 2);
// ^merge maps into single object based map
private static void errorDelay() {
try {
Thread.sleep(30000); // 30 seconds
}
catch (Exception e) {
e.printStackTrace();
}
}
protected static int newConsumerId(int consumer) {
int id = Consumer.consumer_id.get(consumer)[0];
Consumer.consumer_id.put(consumer, new Integer[] { id + 1, 1 });
return id;
}
public static int getConsumerSize(int id) {
if (id == 0 || id == 1) {
return Consumer.consumer.get(id).size();
}
return 0;
}
public static void initialize() {
Consumer.consumer.put(0, new ArrayList<>());
Consumer.consumer.put(1, new ArrayList<>());
Consumer.consumer_id.put(0, new Integer[] { 0, 0 });
Consumer.consumer_id.put(1, new Integer[] { 0, 0 });
Consumer.consumerUsers.put(0, new HashMap<>());
Consumer.consumerUsers.put(1, new HashMap<>());
Consumer.consumerObjects.put(0, new HashMap<>());
Consumer.consumerObjects.put(1, new HashMap<>());
Consumer.consumerStrings.put(0, new HashMap<>());
Consumer.consumerStrings.put(1, new HashMap<>());
Consumer.consumerSigns.put(0, new HashMap<>());
Consumer.consumerSigns.put(1, new HashMap<>());
Consumer.consumerInventories.put(0, new HashMap<>());
Consumer.consumerInventories.put(1, new HashMap<>());
Consumer.consumerBlockList.put(0, new HashMap<>());
Consumer.consumerBlockList.put(1, new HashMap<>());
Consumer.consumerObjectArrayList.put(0, new HashMap<>());
Consumer.consumerObjectArrayList.put(1, new HashMap<>());
Consumer.consumerObjectList.put(0, new HashMap<>());
Consumer.consumerObjectList.put(1, new HashMap<>());
Consumer.consumerContainers.put(0, new HashMap<>());
Consumer.consumerContainers.put(1, new HashMap<>());
}
public static boolean isRunning() {
return running;
}
private static void pauseConsumer(int process_id) {
try {
while ((ConfigHandler.serverRunning || ConfigHandler.converterRunning) && (Consumer.isPaused || ConfigHandler.purgeRunning || Consumer.consumer_id.get(process_id)[1] == 1)) {
pausedSuccess = true;
if (Consumer.isPaused || ConfigHandler.purgeRunning) {
if (connection != null) {
connection.close();
connection = null;
}
}
Thread.sleep(100);
}
}
catch (Exception e) {
e.printStackTrace();
}
pausedSuccess = false;
}
@Override
public void run() {
running = true;
boolean lastRun = false;
while (ConfigHandler.serverRunning || ConfigHandler.converterRunning || !lastRun) {
if (!ConfigHandler.serverRunning && !ConfigHandler.converterRunning) {
lastRun = true;
}
try {
int process_id = 0;
if (currentConsumer == 0) {
currentConsumer = 1;
}
else {
process_id = 1;
currentConsumer = 0;
}
Thread.sleep(500);
pauseConsumer(process_id);
Process.processConsumer(process_id, lastRun);
}
catch (Exception e) {
e.printStackTrace();
errorDelay();
}
}
running = false;
}
@Override
public void uncaughtException(Thread thread, Throwable e) {
running = false;
e.printStackTrace();
Bukkit.getPluginManager().disablePlugin(CoreProtect.getInstance());
}
public static void startConsumer() {
if (running == false) {
Thread consumerThread = new Thread(new Consumer());
consumerThread.setUncaughtExceptionHandler(new Consumer());
consumerThread.start();
}
}
}

View file

@ -0,0 +1,407 @@
package net.coreprotect.consumer;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Bisected.Half;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import net.coreprotect.CoreProtect;
import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.process.Process;
import net.coreprotect.listener.block.BlockUtil;
import net.coreprotect.utility.Util;
public class Queue {
protected static synchronized int modifyForceContainer(String id, ItemStack[] container) {
List<ItemStack[]> forceList = ConfigHandler.forceContainer.get(id);
if (forceList == null) {
return 0;
}
if (container == null) {
forceList.remove(0);
}
else {
forceList.add(container);
}
return forceList.size();
}
protected static synchronized int getChestId(String id) {
int chestId = ConfigHandler.loggingChest.getOrDefault(id, -1) + 1;
ConfigHandler.loggingChest.put(id, chestId);
return chestId;
}
protected static synchronized int getItemId(String id) {
int chestId = ConfigHandler.loggingItem.getOrDefault(id, -1) + 1;
ConfigHandler.loggingItem.put(id, chestId);
return chestId;
}
private static synchronized void addConsumer(int currentConsumer, Object[] data) {
Consumer.consumer.get(currentConsumer).add(data);
}
private static void queueStandardData(int consumerId, int currentConsumer, String[] user, Object object) {
Consumer.consumerUsers.get(currentConsumer).put(consumerId, user);
Consumer.consumerObjects.get(currentConsumer).put(consumerId, object);
Consumer.consumer_id.put(currentConsumer, new Integer[] { Consumer.consumer_id.get(currentConsumer)[0], 0 });
}
protected static void queueAdvancedBreak(String user, BlockState block, Material type, String blockData, int data, Material breakType, int blockNumber) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.BLOCK_BREAK, type, data, breakType, 0, blockNumber, blockData });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueArtInsert(int id, String name) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.ART_INSERT, null, 0, null, 0, id, null });
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, name);
}
protected static void queueBlockBreak(String user, BlockState block, Material type, String blockData, int extraData) {
queueBlockBreak(user, block, type, blockData, null, extraData, 0);
}
protected static void queueBlockBreakValidate(final String user, final Block block, final BlockState blockState, final Material type, final String blockData, final int extraData, int ticks) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
if (!block.getType().equals(type)) {
queueBlockBreak(user, blockState, type, blockData, null, extraData, 0);
}
}
catch (Exception e) {
e.printStackTrace();
}
}, ticks);
}
protected static void queueBlockBreak(String user, BlockState block, Material type, String blockData, Material breakType, int extraData, int blockNumber) {
if (type == Material.SPAWNER && block instanceof CreatureSpawner) { // Mob spawner
CreatureSpawner mobSpawner = (CreatureSpawner) block;
extraData = Util.getSpawnerType(mobSpawner.getSpawnedType());
}
else if (type.equals(Material.SUNFLOWER) || type.equals(Material.LILAC) || type.equals(Material.TALL_GRASS) || type.equals(Material.LARGE_FERN) || type.equals(Material.ROSE_BUSH) || type.equals(Material.PEONY)) { // Double plant
if (block.getBlockData() instanceof Bisected) {
if (((Bisected) block.getBlockData()).getHalf().equals(Half.TOP) && !user.startsWith("#")) {
if (blockNumber == 5) {
return;
}
if (block.getY() > BukkitAdapter.ADAPTER.getMinHeight(block.getWorld())) {
block = block.getWorld().getBlockAt(block.getX(), block.getY() - 1, block.getZ()).getState();
}
}
}
}
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.BLOCK_BREAK, type, extraData, breakType, 0, blockNumber, blockData });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueBlockPlace(String user, BlockState blockLocation, Material blockType, BlockState blockReplaced, Material forceType, int forceD, int forceData, String blockData) {
// If force_data equals "1", current block data will be used in consumer.
Material type = blockType;
int data = 0;
Material replaceType = null;
int replaceData = 0;
if (type == Material.SPAWNER && blockLocation instanceof CreatureSpawner) { // Mob spawner
CreatureSpawner mobSpawner = (CreatureSpawner) blockLocation;
data = Util.getSpawnerType(mobSpawner.getSpawnedType());
forceData = 1;
}
if (blockReplaced != null) {
replaceType = blockReplaced.getType();
replaceData = 0;
if ((replaceType.equals(Material.SUNFLOWER) || replaceType.equals(Material.LILAC) || replaceType.equals(Material.TALL_GRASS) || replaceType.equals(Material.LARGE_FERN) || replaceType.equals(Material.ROSE_BUSH) || replaceType.equals(Material.PEONY)) && replaceData >= 8) { // Double plant top half
BlockState blockBelow = blockReplaced.getWorld().getBlockAt(blockReplaced.getX(), blockReplaced.getY() - 1, blockReplaced.getZ()).getState();
Material belowType = blockBelow.getType();
Queue.queueBlockBreak(user, blockBelow, belowType, blockBelow.getBlockData().getAsString(), 0);
}
}
if (forceType != null) {
type = forceType;
forceData = 1;
}
if (forceD != -1) {
data = forceD;
forceData = 1;
}
String replacedBlockData = null;
if (blockReplaced != null) {
replacedBlockData = blockReplaced.getBlockData().getAsString();
}
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.BLOCK_PLACE, type, data, replaceType, replaceData, forceData, blockData, replacedBlockData });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, blockLocation);
}
protected static void queueBlockPlaceDelayed(final String user, final Location placed, final Material type, final String blockData, final BlockState replaced, int ticks) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
queueBlockPlace(user, placed.getBlock().getState(), type, replaced, null, -1, 0, blockData);
}
catch (Exception e) {
e.printStackTrace();
}
}, ticks);
}
protected static void queueBlockPlaceValidate(final String user, final BlockState blockLocation, final Block block, final BlockState blockReplaced, final Material forceT, final int forceD, final int forceData, final String blockData, int ticks) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
Material blockType = block.getType();
if (blockType.equals(forceT)) {
BlockState blockStateLocation = blockLocation;
if (Config.getConfig(blockLocation.getWorld()).BLOCK_MOVEMENT) {
blockStateLocation = BlockUtil.gravityScan(blockLocation.getLocation(), blockType, user).getState();
}
queueBlockPlace(user, blockStateLocation, blockType, blockReplaced, forceT, forceD, forceData, blockData);
}
}
catch (Exception e) {
e.printStackTrace();
}
}, ticks);
}
protected static void queueBlockGravityValidate(final String user, final Location location, final Block block, final Material blockType, int ticks) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
Block placementBlock = BlockUtil.gravityScan(location, blockType, user);
if (!block.equals(placementBlock)) {
queueBlockPlace(user, placementBlock.getState(), blockType, null, blockType, -1, 0, null);
}
}
catch (Exception e) {
e.printStackTrace();
}
}, ticks);
}
protected static void queueContainerBreak(String user, Location location, Material type, ItemStack[] oldInventory) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.CONTAINER_BREAK, type, 0, null, 0, 0, null });
Consumer.consumerContainers.get(currentConsumer).put(consumerId, oldInventory);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}
protected static void queueContainerRollbackUpdate(String user, Location location, List<Object[]> list, int action) {
if (location == null) {
location = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0, 0);
}
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.CONTAINER_ROLLBACK_UPDATE, null, 0, null, 0, action, null });
Consumer.consumerObjectArrayList.get(currentConsumer).put(consumerId, list);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}
protected static synchronized void queueContainerTransaction(String user, Location location, Material type, Object inventory, int chestId) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.CONTAINER_TRANSACTION, type, 0, null, 0, chestId, null });
Consumer.consumerInventories.get(currentConsumer).put(consumerId, inventory);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}
protected static void queueItemTransaction(String user, Location location, int time, int itemId) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.ITEM_TRANSACTION, null, 0, null, time, itemId, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}
protected static void queueEntityInsert(int id, String name) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.ENTITY_INSERT, null, 0, null, 0, id, null });
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, name);
}
protected static void queueEntityKill(String user, Location location, List<Object> data, EntityType type) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.ENTITY_KILL, null, 0, null, 0, 0 });
Consumer.consumerObjectList.get(currentConsumer).put(consumerId, data);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { location.getBlock().getState(), type, null });
}
protected static void queueEntitySpawn(String user, BlockState block, EntityType type, int data) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.ENTITY_SPAWN, null, 0, null, 0, data, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { block, type });
}
protected static void queueHangingRemove(String user, BlockState block, int delay) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_REMOVE, null, 0, null, 0, delay, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueHangingSpawn(String user, BlockState block, Material type, int data, int delay) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_SPAWN, type, data, null, 0, delay, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueMaterialInsert(int id, String name) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.MATERIAL_INSERT, null, 0, null, 0, id, null });
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, name);
}
protected static void queueBlockDataInsert(int id, String data) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.BLOCKDATA_INSERT, null, 0, null, 0, id, null });
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, data);
}
protected static void queueNaturalBlockBreak(String user, BlockState block, Block relative, Material type, int data) {
List<BlockState> blockStates = new ArrayList<>();
if (relative != null) {
blockStates.add(relative.getState());
}
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.NATURAL_BLOCK_BREAK, type, data, null, 0, 0, null });
Consumer.consumerBlockList.get(currentConsumer).put(consumerId, blockStates);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queuePlayerChat(Player player, String message, int time) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_CHAT, null, 0, null, 0, time, null });
Consumer.consumerStrings.get(currentConsumer).put(consumerId, message);
queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, player.getLocation().clone());
}
protected static void queuePlayerCommand(Player player, String message, int time) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_COMMAND, null, 0, null, 0, time, null });
Consumer.consumerStrings.get(currentConsumer).put(consumerId, message);
queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, player.getLocation().clone());
}
protected static void queuePlayerInteraction(String user, BlockState block) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_INTERACTION, null, 0, null, 0, 0, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queuePlayerKill(String user, Location location, String player) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_KILL, null, 0, null, 0, 0, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { location.getBlock().getState(), player });
}
protected static void queuePlayerLogin(Player player, int time, int configSessions, int configUsernames) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
String uuid = player.getUniqueId().toString();
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_LOGIN, null, configSessions, null, configUsernames, time, null });
Consumer.consumerStrings.get(currentConsumer).put(consumerId, uuid);
queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), uuid }, player.getLocation().clone());
}
protected static void queuePlayerQuit(Player player, int time) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_LOGOUT, null, 0, null, 0, time, null });
queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, player.getLocation().clone());
}
protected static void queueRollbackUpdate(String user, Location location, List<Object[]> list, int action) {
if (location == null) {
location = new Location(Bukkit.getServer().getWorlds().get(0), 0, 0, 0);
}
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.ROLLBACK_UPDATE, null, 0, null, 0, action, null });
Consumer.consumerObjectArrayList.get(currentConsumer).put(consumerId, list);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}
protected static void queueSignText(String user, Location location, int action, int color, boolean glowing, String line1, String line2, String line3, String line4, int offset) {
/*
if (line1.length() == 0 && line2.length() == 0 && line3.length() == 0 && line4.length() == 0) {
return;
}
*/
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.SIGN_TEXT, null, color, null, action, offset, null });
Consumer.consumerSigns.get(currentConsumer).put(consumerId, new Object[] { (glowing == true ? 1 : 0), line1, line2, line3, line4 });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, location);
}
protected static void queueSignUpdate(String user, BlockState block, int action, int time) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.SIGN_UPDATE, null, action, null, 0, time, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueSkullUpdate(String user, BlockState block, int rowId) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.SKULL_UPDATE, null, 0, null, 0, rowId, null });
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueStructureGrow(String user, BlockState block, List<BlockState> blockList, int replacedListSize) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.STRUCTURE_GROWTH, null, 0, null, 0, replacedListSize, null });
Consumer.consumerBlockList.get(currentConsumer).put(consumerId, blockList);
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
}
protected static void queueWorldInsert(int id, String world) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.WORLD_INSERT, null, 0, null, 0, id, null });
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, world);
}
}

View file

@ -0,0 +1,35 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.sql.Statement;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.MaterialStatement;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.utility.Chat;
class ArtInsertProcess {
static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) {
if (name instanceof String) {
String query = "SELECT id FROM " + ConfigHandler.prefix + "art_map WHERE id = '" + materialId + "' LIMIT 0, 1";
boolean hasMaterial = MaterialStatement.hasMaterial(statement, query);
if (!hasMaterial) {
MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name);
// validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing
ConfigHandler.art.put((String) name, materialId);
ConfigHandler.artReversed.put(materialId, (String) name);
if (materialId > ConfigHandler.artId) {
ConfigHandler.artId = materialId;
}
}
else {
Chat.console(Phrase.build(Phrase.CACHE_ERROR, "art"));
Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST));
ConfigHandler.loadTypes(statement);
}
}
}
}

View file

@ -0,0 +1,42 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Door;
import net.coreprotect.database.logger.BlockBreakLogger;
import net.coreprotect.database.logger.SkullBreakLogger;
import net.coreprotect.model.BlockGroup;
import net.coreprotect.utility.Util;
class BlockBreakProcess {
static void process(PreparedStatement preparedStmt, PreparedStatement preparedStmtSkulls, int batchCount, int processId, int id, Material blockType, int blockDataId, Material replaceType, int forceData, String user, Object object, String blockData) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
List<Object> meta = Util.processMeta(block);
if (block instanceof Skull) {
SkullBreakLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block);
}
else {
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockDataId, meta, block.getBlockData().getAsString());
if (forceData == 5) { // Fix for doors
if ((blockType == Material.IRON_DOOR || BlockGroup.DOORS.contains(blockType)) && (replaceType != Material.IRON_DOOR && !BlockGroup.DOORS.contains(replaceType))) {
Door door = (Door) block.getBlockData();
door.setHalf(Bisected.Half.TOP);
blockData = door.getAsString();
Location location = block.getLocation();
location.setY(location.getY() + 1);
BlockBreakLogger.log(preparedStmt, batchCount, user, location, Util.getBlockId(blockType), 0, null, blockData);
}
}
}
}
}
}

View file

@ -0,0 +1,35 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.sql.Statement;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.MaterialStatement;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.utility.Chat;
class BlockDataInsertProcess {
static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) {
if (name instanceof String) {
String query = "SELECT id FROM " + ConfigHandler.prefix + "blockdata_map WHERE id = '" + materialId + "' LIMIT 0, 1";
boolean hasMaterial = MaterialStatement.hasMaterial(statement, query);
if (!hasMaterial) {
MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name);
// validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing
ConfigHandler.blockdata.put((String) name, materialId);
ConfigHandler.blockdataReversed.put(materialId, (String) name);
if (materialId > ConfigHandler.blockdataId) {
ConfigHandler.blockdataId = materialId;
}
}
else {
Chat.console(Phrase.build(Phrase.CACHE_ERROR, "blockdata"));
Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST));
ConfigHandler.loadTypes(statement);
}
}
}
}

View file

@ -0,0 +1,30 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import net.coreprotect.database.logger.BlockPlaceLogger;
import net.coreprotect.database.logger.SkullPlaceLogger;
import net.coreprotect.utility.Util;
class BlockPlaceProcess {
static void process(PreparedStatement preparedStmt, PreparedStatement preparedStmtSkulls, int batchCount, Material blockType, int blockData, Material replaceType, int replaceData, int forceData, String user, Object object, String newBlockData, String replacedBlockData) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
List<Object> meta = Util.processMeta(block);
if (blockType.equals(Material.SKELETON_SKULL) || blockType.equals(Material.SKELETON_WALL_SKULL) || blockType.equals(Material.WITHER_SKELETON_SKULL) || blockType.equals(Material.WITHER_SKELETON_WALL_SKULL) || blockType.equals(Material.ZOMBIE_HEAD) || blockType.equals(Material.ZOMBIE_WALL_HEAD) || blockType.equals(Material.PLAYER_HEAD) || blockType.equals(Material.PLAYER_WALL_HEAD) || blockType.equals(Material.CREEPER_HEAD) || blockType.equals(Material.CREEPER_WALL_HEAD) || blockType.equals(Material.DRAGON_HEAD) || blockType.equals(Material.DRAGON_WALL_HEAD)) {
SkullPlaceLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block, Util.getBlockId(replaceType), replaceData);
}
else if (forceData == 1) {
BlockPlaceLogger.log(preparedStmt, batchCount, user, block, Util.getBlockId(replaceType), replaceData, blockType, blockData, true, meta, newBlockData, replacedBlockData);
}
else {
BlockPlaceLogger.log(preparedStmt, batchCount, user, block, Util.getBlockId(replaceType), replaceData, blockType, blockData, false, meta, newBlockData, replacedBlockData);
}
}
}
}

View file

@ -0,0 +1,26 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.logger.ContainerBreakLogger;
class ContainerBreakProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Material type, String user, Object object) {
if (object instanceof Location) {
Location location = (Location) object;
Map<Integer, ItemStack[]> containers = Consumer.consumerContainers.get(processId);
if (containers.get(id) != null) {
ItemStack[] container = containers.get(id);
ContainerBreakLogger.log(preparedStmt, batchCount, user, location, type, container);
containers.remove(id);
}
}
}
}

View file

@ -0,0 +1,49 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.logger.ContainerLogger;
class ContainerTransactionProcess {
static void process(PreparedStatement preparedStmtContainer, PreparedStatement preparedStmtItems, int batchCount, int processId, int id, Material type, int forceData, String user, Object object) {
if (object instanceof Location) {
Location location = (Location) object;
Map<Integer, Object> inventories = Consumer.consumerInventories.get(processId);
if (inventories.get(id) != null) {
Object inventory = inventories.get(id);
String transactingChestId = location.getWorld().getUID().toString() + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
String loggingChestId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
if (ConfigHandler.loggingChest.get(loggingChestId) != null) {
int current_chest = ConfigHandler.loggingChest.get(loggingChestId);
if (ConfigHandler.oldContainer.get(loggingChestId) == null) {
return;
}
int force_size = 0;
if (ConfigHandler.forceContainer.get(loggingChestId) != null) {
force_size = ConfigHandler.forceContainer.get(loggingChestId).size();
}
if (current_chest == forceData || force_size > 0) { // This prevents client side chest sorting mods from messing things up.
ContainerLogger.log(preparedStmtContainer, preparedStmtItems, batchCount, user, type, inventory, location);
List<ItemStack[]> old = ConfigHandler.oldContainer.get(loggingChestId);
if (old.size() == 0) {
ConfigHandler.oldContainer.remove(loggingChestId);
ConfigHandler.loggingChest.remove(loggingChestId);
ConfigHandler.transactingChest.remove(transactingChestId);
}
}
}
inventories.remove(id);
}
}
}
}

View file

@ -0,0 +1,35 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.sql.Statement;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.MaterialStatement;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.utility.Chat;
class EntityInsertProcess {
static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) {
if (name instanceof String) {
String query = "SELECT id FROM " + ConfigHandler.prefix + "entity_map WHERE id = '" + materialId + "' LIMIT 0, 1";
boolean hasMaterial = MaterialStatement.hasMaterial(statement, query);
if (!hasMaterial) {
MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name);
// validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing
ConfigHandler.entities.put((String) name, materialId);
ConfigHandler.entitiesReversed.put(materialId, (String) name);
if (materialId > ConfigHandler.entityId) {
ConfigHandler.entityId = materialId;
}
}
else {
Chat.console(Phrase.build(Phrase.CACHE_ERROR, "entity"));
Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST));
ConfigHandler.loadTypes(statement);
}
}
}
}

View file

@ -0,0 +1,29 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.Map;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.logger.EntityKillLogger;
import net.coreprotect.utility.Util;
class EntityKillProcess {
static void process(PreparedStatement preparedStmt, PreparedStatement preparedStmtEntities, int batchCount, int processId, int id, Object object, String user) {
if (object instanceof Object[]) {
BlockState block = (BlockState) ((Object[]) object)[0];
EntityType type = (EntityType) ((Object[]) object)[1];
Map<Integer, List<Object>> objectLists = Consumer.consumerObjectList.get(processId);
if (objectLists.get(id) != null) {
List<Object> objectList = objectLists.get(id);
int entityId = Util.getEntityId(type);
EntityKillLogger.log(preparedStmt, preparedStmtEntities, batchCount, user, block, objectList, entityId);
objectLists.remove(id);
}
}
}
}

View file

@ -0,0 +1,24 @@
package net.coreprotect.consumer.process;
import java.sql.Statement;
import java.util.List;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.EntityStatement;
import net.coreprotect.utility.Util;
class EntitySpawnProcess {
static void process(Statement statement, Object object, int rowId) {
if (object instanceof Object[]) {
BlockState block = (BlockState) ((Object[]) object)[0];
EntityType type = (EntityType) ((Object[]) object)[1];
String query = "SELECT data FROM " + ConfigHandler.prefix + "entity WHERE rowid='" + rowId + "' LIMIT 0, 1";
List<Object> data = EntityStatement.getData(statement, block, query);
Util.spawnEntity(block, type, data);
}
}
}

View file

@ -0,0 +1,15 @@
package net.coreprotect.consumer.process;
import org.bukkit.block.BlockState;
import net.coreprotect.utility.Util;
class HangingRemoveProcess {
static void process(Object object, int delay) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
Util.removeHanging(block, delay);
}
}
}

View file

@ -0,0 +1,16 @@
package net.coreprotect.consumer.process;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import net.coreprotect.utility.Util;
class HangingSpawnProcess {
static void process(Object object, Material type, int data, int delay) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
Util.spawnHanging(block, type, data, delay);
}
}
}

View file

@ -0,0 +1,39 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.Locale;
import org.bukkit.Location;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.Queue;
import net.coreprotect.database.logger.ItemLogger;
class ItemTransactionProcess extends Queue {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, int forceData, int time, String user, Object object) {
if (object instanceof Location) {
Location location = (Location) object;
String loggingItemId = user.toLowerCase(Locale.ROOT) + "." + location.getBlockX() + "." + location.getBlockY() + "." + location.getBlockZ();
if (ConfigHandler.loggingItem.get(loggingItemId) != null) {
int current_chest = ConfigHandler.loggingItem.get(loggingItemId);
if (ConfigHandler.itemsDrop.get(loggingItemId) == null && ConfigHandler.itemsPickup.get(loggingItemId) == null) {
return;
}
if (current_chest == forceData) {
int currentTime = (int) (System.currentTimeMillis() / 1000L);
if (currentTime > time) {
ItemLogger.log(preparedStmt, batchCount, location, user);
ConfigHandler.itemsDrop.remove(loggingItemId);
ConfigHandler.itemsPickup.remove(loggingItemId);
ConfigHandler.loggingItem.remove(loggingItemId);
}
else {
Queue.queueItemTransaction(user, location, time, forceData);
}
}
}
}
}
}

View file

@ -0,0 +1,35 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.sql.Statement;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.MaterialStatement;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.utility.Chat;
class MaterialInsertProcess {
static void process(PreparedStatement preparedStmt, Statement statement, int batchCount, Object name, int materialId) {
if (name instanceof String) {
String query = "SELECT id FROM " + ConfigHandler.prefix + "material_map WHERE id = '" + materialId + "' LIMIT 0, 1";
boolean hasMaterial = MaterialStatement.hasMaterial(statement, query);
if (!hasMaterial) {
MaterialStatement.insert(preparedStmt, batchCount, materialId, (String) name);
// validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing
ConfigHandler.materials.put((String) name, materialId);
ConfigHandler.materialsReversed.put(materialId, (String) name);
if (materialId > ConfigHandler.materialId) {
ConfigHandler.materialId = materialId;
}
}
else {
Chat.console(Phrase.build(Phrase.CACHE_ERROR, "material"));
Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.FIRST));
ConfigHandler.loadTypes(statement);
}
}
}
}

View file

@ -0,0 +1,35 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.Lookup;
import net.coreprotect.database.logger.BlockBreakLogger;
import net.coreprotect.utility.Util;
class NaturalBlockBreakProcess {
static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, Material blockType, int blockData) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
Map<Integer, List<BlockState>> blockLists = Consumer.consumerBlockList.get(processId);
if (blockLists.get(id) != null) {
List<BlockState> blockStateList = blockLists.get(id);
for (BlockState blockState : blockStateList) {
String removed = Lookup.whoRemovedCache(blockState);
if (removed.length() > 0) {
user = removed;
}
}
blockLists.remove(id);
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockData, null, block.getBlockData().getAsString());
}
}
}
}

View file

@ -0,0 +1,24 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.Map;
import org.bukkit.Location;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.logger.ChatLogger;
class PlayerChatProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, int time, String user) {
if (object instanceof Location) {
Map<Integer, String> strings = Consumer.consumerStrings.get(processId);
if (strings.get(id) != null) {
String message = strings.get(id);
Location location = (Location) object;
ChatLogger.log(preparedStmt, batchCount, time, location, user, message);
strings.remove(id);
}
}
}
}

View file

@ -0,0 +1,24 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.Map;
import org.bukkit.Location;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.logger.CommandLogger;
class PlayerCommandProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, int time, String user) {
if (object instanceof Location) {
Map<Integer, String> strings = Consumer.consumerStrings.get(processId);
if (strings.get(id) != null) {
String message = strings.get(id);
Location location = (Location) object;
CommandLogger.log(preparedStmt, batchCount, time, location, user, message);
strings.remove(id);
}
}
}
}

View file

@ -0,0 +1,17 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import org.bukkit.block.BlockState;
import net.coreprotect.database.logger.PlayerInteractLogger;
class PlayerInteractionProcess {
static void process(PreparedStatement preparedStmt, int batchCount, String user, Object object) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
PlayerInteractLogger.log(preparedStmt, batchCount, user, block);
}
}
}

View file

@ -0,0 +1,18 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import org.bukkit.block.BlockState;
import net.coreprotect.database.logger.PlayerKillLogger;
class PlayerKillProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int id, Object object, String user) {
if (object instanceof Object[]) {
BlockState block = (BlockState) ((Object[]) object)[0];
String player = (String) ((Object[]) object)[1];
PlayerKillLogger.log(preparedStmt, batchCount, user, block, player);
}
}
}

View file

@ -0,0 +1,29 @@
package net.coreprotect.consumer.process;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Map;
import org.bukkit.Location;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.logger.PlayerSessionLogger;
import net.coreprotect.database.logger.UsernameLogger;
class PlayerLoginProcess {
static void process(Connection connection, PreparedStatement preparedStmt, int batchCount, int processId, int id, Object object, int configSessions, int configUsernames, int time, String user) {
if (object instanceof Location) {
Map<Integer, String> strings = Consumer.consumerStrings.get(processId);
if (strings.get(id) != null) {
String uuid = strings.get(id);
Location location = (Location) object;
UsernameLogger.log(connection, user, uuid, configUsernames, time);
if (configSessions == 1) {
PlayerSessionLogger.log(preparedStmt, batchCount, user, location, time, 1);
}
strings.remove(id);
}
}
}
}

View file

@ -0,0 +1,17 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import org.bukkit.Location;
import net.coreprotect.database.logger.PlayerSessionLogger;
class PlayerLogoutProcess {
static void process(PreparedStatement preparedStmt, int batchCount, Object object, int time, String user) {
if (object instanceof Location) {
Location location = (Location) object;
PlayerSessionLogger.log(preparedStmt, batchCount, user, location, time, 0);
}
}
}

View file

@ -0,0 +1,327 @@
package net.coreprotect.consumer.process;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Material;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.Database;
import net.coreprotect.database.statement.UserStatement;
public class Process {
public static final int BLOCK_BREAK = 0;
public static final int BLOCK_PLACE = 1;
public static final int SIGN_TEXT = 2;
public static final int CONTAINER_BREAK = 3;
public static final int PLAYER_INTERACTION = 4;
public static final int CONTAINER_TRANSACTION = 5;
public static final int STRUCTURE_GROWTH = 6;
public static final int ROLLBACK_UPDATE = 7;
public static final int CONTAINER_ROLLBACK_UPDATE = 8;
public static final int WORLD_INSERT = 9;
public static final int SIGN_UPDATE = 10;
public static final int SKULL_UPDATE = 11;
public static final int PLAYER_CHAT = 12;
public static final int PLAYER_COMMAND = 13;
public static final int PLAYER_LOGIN = 14;
public static final int PLAYER_LOGOUT = 15;
public static final int ENTITY_KILL = 16;
public static final int ENTITY_SPAWN = 17;
public static final int HANGING_REMOVE = 18;
public static final int HANGING_SPAWN = 19;
public static final int NATURAL_BLOCK_BREAK = 20;
public static final int MATERIAL_INSERT = 21;
public static final int ART_INSERT = 22;
public static final int ENTITY_INSERT = 23;
public static final int PLAYER_KILL = 24;
public static final int BLOCKDATA_INSERT = 25;
public static final int ITEM_TRANSACTION = 26;
protected static Connection connection = null;
public static int lastLockUpdate = 0;
private static int lastConnection = 0;
private static volatile int currentConsumerSize = 0;
public static int getCurrentConsumerSize() {
return currentConsumerSize;
}
private static void validateConnection(boolean lastRun) {
try {
if (connection != null) {
int timeSinceLastConnection = ((int) (System.currentTimeMillis() / 1000L)) - lastConnection;
if ((!lastRun && timeSinceLastConnection > 900) || !connection.isValid(5) || Consumer.resetConnection) {
connection.close();
connection = null;
Consumer.resetConnection = false;
}
}
if (connection == null && ConfigHandler.serverRunning) {
connection = Database.getConnection(false, 500);
lastConnection = (int) (System.currentTimeMillis() / 1000L);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
protected static void updateLockTable(Statement statement, int locked) {
try {
int unixTimestamp = (int) (System.currentTimeMillis() / 1000L);
int timeSinceLastUpdate = unixTimestamp - lastLockUpdate;
if (timeSinceLastUpdate >= 15 || locked == 0) {
statement.executeUpdate("UPDATE " + ConfigHandler.prefix + "database_lock SET status = '" + locked + "', time = '" + unixTimestamp + "' WHERE rowid = '1'");
lastLockUpdate = unixTimestamp;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
protected static void processConsumer(int processId, boolean lastRun) {
try {
// Connection
validateConnection(lastRun);
if (connection == null) {
return;
}
Consumer.isPaused = true;
Statement statement = connection.createStatement();
ArrayList<Object[]> consumerData = Consumer.consumer.get(processId);
Map<Integer, String[]> users = Consumer.consumerUsers.get(processId);
Map<Integer, Object> consumerObject = Consumer.consumerObjects.get(processId);
int consumerDataSize = consumerData.size();
currentConsumerSize = consumerDataSize;
Database.beginTransaction(statement);
// Scan through usernames, ensure everything is loaded in memory.
for (Entry<Integer, String[]> entry : users.entrySet()) {
String[] data = entry.getValue();
if (data != null) {
String user = data[0];
String uuid = data[1];
if (user != null && ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT)) == null) {
UserStatement.loadId(connection, user, uuid);
}
}
}
updateLockTable(statement, (lastRun ? 0 : 1));
Database.commitTransaction(statement);
// Create prepared statements
PreparedStatement preparedStmtSigns = Database.prepareStatement(connection, Database.SIGN, false);
PreparedStatement preparedStmtBlocks = Database.prepareStatement(connection, Database.BLOCK, false);
PreparedStatement preparedStmtSkulls = Database.prepareStatement(connection, Database.SKULL, true);
PreparedStatement preparedStmtContainers = Database.prepareStatement(connection, Database.CONTAINER, false);
PreparedStatement preparedStmtItems = Database.prepareStatement(connection, Database.ITEM, false);
PreparedStatement preparedStmtWorlds = Database.prepareStatement(connection, Database.WORLD, false);
PreparedStatement preparedStmtChat = Database.prepareStatement(connection, Database.CHAT, false);
PreparedStatement preparedStmtCommand = Database.prepareStatement(connection, Database.COMMAND, false);
PreparedStatement preparedStmtSession = Database.prepareStatement(connection, Database.SESSION, false);
PreparedStatement preparedStmtEntities = Database.prepareStatement(connection, Database.ENTITY, true);
PreparedStatement preparedStmtMaterials = Database.prepareStatement(connection, Database.MATERIAL, false);
PreparedStatement preparedStmtArt = Database.prepareStatement(connection, Database.ART, false);
PreparedStatement preparedStmtEntity = Database.prepareStatement(connection, Database.ENTITY_MAP, false);
PreparedStatement preparedStmtBlockdata = Database.prepareStatement(connection, Database.BLOCKDATA, false);
// Scan through consumer data
Database.beginTransaction(statement);
for (int i = 0; i < consumerDataSize; i++) {
Object[] data = consumerData.get(i);
if (data != null) {
int id = (Integer) data[0];
int action = (Integer) data[1];
Material blockType = (Material) data[2];
int blockData = (Integer) data[3];
Material replace_type = (Material) data[4];
int replaceData = (Integer) data[5];
int forceData = (Integer) data[6];
if (users.get(id) != null && consumerObject.get(id) != null) {
String user = users.get(id)[0];
Object object = consumerObject.get(id);
try {
switch (action) {
case Process.BLOCK_BREAK:
BlockBreakProcess.process(preparedStmtBlocks, preparedStmtSkulls, i, processId, id, blockType, blockData, replace_type, forceData, user, object, (String) data[7]);
break;
case Process.BLOCK_PLACE:
BlockPlaceProcess.process(preparedStmtBlocks, preparedStmtSkulls, i, blockType, blockData, replace_type, replaceData, forceData, user, object, (String) data[7], (String) data[8]);
break;
case Process.SIGN_TEXT:
SignTextProcess.process(preparedStmtSigns, i, processId, id, forceData, user, object, replaceData, blockData);
break;
case Process.CONTAINER_BREAK:
ContainerBreakProcess.process(preparedStmtContainers, i, processId, id, blockType, user, object);
break;
case Process.PLAYER_INTERACTION:
PlayerInteractionProcess.process(preparedStmtBlocks, i, user, object);
break;
case Process.CONTAINER_TRANSACTION:
ContainerTransactionProcess.process(preparedStmtContainers, preparedStmtItems, i, processId, id, blockType, forceData, user, object);
break;
case Process.ITEM_TRANSACTION:
ItemTransactionProcess.process(preparedStmtItems, i, processId, id, forceData, replaceData, user, object);
break;
case Process.STRUCTURE_GROWTH:
StructureGrowthProcess.process(statement, preparedStmtBlocks, i, processId, id, user, object, forceData);
break;
case Process.ROLLBACK_UPDATE:
RollbackUpdateProcess.process(statement, processId, id, forceData, 0);
break;
case Process.CONTAINER_ROLLBACK_UPDATE:
RollbackUpdateProcess.process(statement, processId, id, forceData, 1);
break;
case Process.WORLD_INSERT:
WorldInsertProcess.process(preparedStmtWorlds, i, statement, object, forceData);
break;
case Process.SIGN_UPDATE:
SignUpdateProcess.process(statement, object, user, blockData, forceData);
break;
case Process.SKULL_UPDATE:
SkullUpdateProcess.process(statement, object, forceData);
break;
case Process.PLAYER_CHAT:
PlayerChatProcess.process(preparedStmtChat, i, processId, id, object, forceData, user);
break;
case Process.PLAYER_COMMAND:
PlayerCommandProcess.process(preparedStmtCommand, i, processId, id, object, forceData, user);
break;
case Process.PLAYER_LOGIN:
PlayerLoginProcess.process(connection, preparedStmtSession, i, processId, id, object, blockData, replaceData, forceData, user);
break;
case Process.PLAYER_LOGOUT:
PlayerLogoutProcess.process(preparedStmtSession, i, object, forceData, user);
break;
case Process.ENTITY_KILL:
EntityKillProcess.process(preparedStmtBlocks, preparedStmtEntities, i, processId, id, object, user);
break;
case Process.ENTITY_SPAWN:
EntitySpawnProcess.process(statement, object, forceData);
break;
case Process.HANGING_REMOVE:
HangingRemoveProcess.process(object, forceData);
break;
case Process.HANGING_SPAWN:
HangingSpawnProcess.process(object, blockType, blockData, forceData);
break;
case Process.NATURAL_BLOCK_BREAK:
NaturalBlockBreakProcess.process(statement, preparedStmtBlocks, i, processId, id, user, object, blockType, blockData);
break;
case Process.MATERIAL_INSERT:
MaterialInsertProcess.process(preparedStmtMaterials, statement, i, object, forceData);
break;
case Process.ART_INSERT:
ArtInsertProcess.process(preparedStmtArt, statement, i, object, forceData);
break;
case Process.ENTITY_INSERT:
EntityInsertProcess.process(preparedStmtEntity, statement, i, object, forceData);
break;
case Process.PLAYER_KILL:
PlayerKillProcess.process(preparedStmtBlocks, i, id, object, user);
break;
case Process.BLOCKDATA_INSERT:
BlockDataInsertProcess.process(preparedStmtBlockdata, statement, i, object, forceData);
break;
}
// If database connection goes missing, remove processed data from consumer and abort
if (statement.isClosed()) {
for (int index = (i - 1); index >= 0; index--) {
consumerData.remove(index);
}
connection = null;
currentConsumerSize = 0;
Consumer.isPaused = false;
return;
}
// If interrupt requested, commit data, sleep, and resume processing
if (Consumer.interrupt) {
commit(statement, preparedStmtSigns, preparedStmtBlocks, preparedStmtSkulls, preparedStmtContainers, preparedStmtItems, preparedStmtWorlds, preparedStmtChat, preparedStmtCommand, preparedStmtSession, preparedStmtEntities, preparedStmtMaterials, preparedStmtArt, preparedStmtEntity, preparedStmtBlockdata);
Thread.sleep(500);
Database.beginTransaction(statement);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
currentConsumerSize--;
}
// commit data to database
commit(statement, preparedStmtSigns, preparedStmtBlocks, preparedStmtSkulls, preparedStmtContainers, preparedStmtItems, preparedStmtWorlds, preparedStmtChat, preparedStmtCommand, preparedStmtSession, preparedStmtEntities, preparedStmtMaterials, preparedStmtArt, preparedStmtEntity, preparedStmtBlockdata);
// close connections/statements
preparedStmtSigns.close();
preparedStmtBlocks.close();
preparedStmtSkulls.close();
preparedStmtContainers.close();
preparedStmtItems.close();
preparedStmtWorlds.close();
preparedStmtChat.close();
preparedStmtCommand.close();
preparedStmtSession.close();
preparedStmtEntities.close();
preparedStmtMaterials.close();
preparedStmtArt.close();
preparedStmtEntity.close();
preparedStmtBlockdata.close();
statement.close();
// clear maps
users.clear();
consumerObject.clear();
consumerData.clear();
if (lastRun) {
connection.close();
connection = null;
}
}
catch (Exception e) {
e.printStackTrace();
}
Consumer.consumer_id.put(processId, new Integer[] { 0, 0 });
Consumer.isPaused = false;
}
private static void commit(Statement statement, PreparedStatement preparedStmtSigns, PreparedStatement preparedStmtBlocks, PreparedStatement preparedStmtSkulls, PreparedStatement preparedStmtContainers, PreparedStatement preparedStmtItems, PreparedStatement preparedStmtWorlds, PreparedStatement preparedStmtChat, PreparedStatement preparedStmtCommand, PreparedStatement preparedStmtSession, PreparedStatement preparedStmtEntities, PreparedStatement preparedStmtMaterials, PreparedStatement preparedStmtArt, PreparedStatement preparedStmtEntity, PreparedStatement preparedStmtBlockdata) {
try {
preparedStmtSigns.executeBatch();
preparedStmtBlocks.executeBatch();
preparedStmtSkulls.executeBatch();
preparedStmtContainers.executeBatch();
preparedStmtItems.executeBatch();
preparedStmtWorlds.executeBatch();
preparedStmtChat.executeBatch();
preparedStmtCommand.executeBatch();
preparedStmtSession.executeBatch();
preparedStmtEntities.executeBatch();
preparedStmtMaterials.executeBatch();
preparedStmtArt.executeBatch();
preparedStmtEntity.executeBatch();
preparedStmtBlockdata.executeBatch();
Database.commitTransaction(statement);
}
catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,26 @@
package net.coreprotect.consumer.process;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.Database;
class RollbackUpdateProcess {
static void process(Statement statement, int processId, int id, int action, int table) {
Map<Integer, List<Object[]>> updateLists = Consumer.consumerObjectArrayList.get(processId);
if (updateLists.get(id) != null) {
List<Object[]> list = updateLists.get(id);
for (Object[] listRow : list) {
long rowid = (Long) listRow[0];
int rolledBack = (Integer) listRow[9];
if (rolledBack == action) {
Database.performUpdate(statement, rowid, action, table);
}
}
updateLists.remove(id);
}
}
}

View file

@ -0,0 +1,24 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.util.Map;
import org.bukkit.Location;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.logger.SignTextLogger;
class SignTextProcess {
static void process(PreparedStatement preparedStmt, int batchCount, int processId, int id, int forceData, String user, Object object, int action, int color) {
if (object instanceof Location) {
Location location = (Location) object;
Map<Integer, Object[]> signs = Consumer.consumerSigns.get(processId);
if (signs.get(id) != null) {
Object[] SIGN_DATA = signs.get(id);
SignTextLogger.log(preparedStmt, batchCount, user, location, action, color, (Integer) SIGN_DATA[0], (String) SIGN_DATA[1], (String) SIGN_DATA[2], (String) SIGN_DATA[3], (String) SIGN_DATA[4], forceData);
signs.remove(id);
}
}
}
}

View file

@ -0,0 +1,38 @@
package net.coreprotect.consumer.process;
import java.sql.Statement;
import java.util.Locale;
import org.bukkit.block.BlockState;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.SignStatement;
import net.coreprotect.utility.Util;
class SignUpdateProcess {
static void process(Statement statement, Object object, String user, int action, int time) {
/*
* We're switching blocks around quickly.
* This block could already be removed again by the time the server tries to modify it.
* Ignore any errors.
*/
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
int x = block.getX();
int y = block.getY();
int z = block.getZ();
int wid = Util.getWorldId(block.getWorld().getName());
int userid = ConfigHandler.playerIdCache.get(user.toLowerCase(Locale.ROOT));
String query = "";
if (action == 0) {
query = "SELECT color, data, line_1, line_2, line_3, line_4 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time < '" + time + "' ORDER BY rowid DESC LIMIT 0, 1";
}
else {
query = "SELECT color, data, line_1, line_2, line_3, line_4 FROM " + ConfigHandler.prefix + "sign WHERE user='" + userid + "' AND wid='" + wid + "' AND x='" + x + "' AND z='" + z + "' AND y='" + y + "' AND time >= '" + time + "' ORDER BY rowid ASC LIMIT 0, 1";
}
SignStatement.getData(statement, block, query);
Util.updateBlock(block);
}
}
}

View file

@ -0,0 +1,26 @@
package net.coreprotect.consumer.process;
import java.sql.Statement;
import org.bukkit.block.BlockState;
import net.coreprotect.database.statement.SkullStatement;
import net.coreprotect.utility.Util;
import net.coreprotect.config.ConfigHandler;
class SkullUpdateProcess {
static void process(Statement statement, Object object, int rowId) {
/*
* We're switching blocks around quickly.
* This block could already be removed again by the time the server tries to modify it.
* Ignore any errors.
*/
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
String query = "SELECT owner FROM " + ConfigHandler.prefix + "skull WHERE rowid='" + rowId + "' LIMIT 0, 1";
SkullStatement.getData(statement, block, query);
Util.updateBlock(block);
}
}
}

View file

@ -0,0 +1,42 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import org.bukkit.block.BlockState;
import net.coreprotect.consumer.Consumer;
import net.coreprotect.database.Lookup;
import net.coreprotect.database.logger.BlockBreakLogger;
import net.coreprotect.database.logger.BlockPlaceLogger;
import net.coreprotect.utility.Util;
class StructureGrowthProcess {
static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, int replaceBlockCount) {
if (object instanceof BlockState) {
BlockState block = (BlockState) object;
Map<Integer, List<BlockState>> blockLists = Consumer.consumerBlockList.get(processId);
if (blockLists.get(id) != null) {
List<BlockState> blockStates = blockLists.get(id);
String resultData = Lookup.whoPlaced(statement, block);
if (resultData.length() > 0) {
user = resultData;
}
int count = 0;
for (BlockState blockState : blockStates) {
if (count < replaceBlockCount) {
BlockBreakLogger.log(preparedStmt, batchCount, user, blockState.getLocation(), Util.getBlockId(blockState.getType()), 0, null, blockState.getBlockData().getAsString());
}
else {
BlockPlaceLogger.log(preparedStmt, batchCount, user, blockState, 0, 0, null, -1, false, null, null, null);
}
count++;
}
blockLists.remove(id);
}
}
}
}

View file

@ -0,0 +1,36 @@
package net.coreprotect.consumer.process;
import java.sql.PreparedStatement;
import java.sql.Statement;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.statement.MaterialStatement;
import net.coreprotect.database.statement.WorldStatement;
import net.coreprotect.language.Phrase;
import net.coreprotect.language.Selector;
import net.coreprotect.utility.Chat;
class WorldInsertProcess {
static void process(PreparedStatement preparedStmt, int batchCount, Statement statement, Object world, int worldId) {
if (world instanceof String) {
String query = "SELECT id FROM " + ConfigHandler.prefix + "world WHERE id = '" + worldId + "' LIMIT 0, 1";
boolean hasMaterial = MaterialStatement.hasMaterial(statement, query);
if (!hasMaterial) {
WorldStatement.insert(preparedStmt, batchCount, worldId, (String) world);
// validate ID maps to ensure mapping wasn't reloaded from database prior to this insertion completing
ConfigHandler.worlds.put((String) world, worldId);
ConfigHandler.worldsReversed.put(worldId, (String) world);
if (worldId > ConfigHandler.worldId) {
ConfigHandler.worldId = worldId;
}
}
else {
Chat.console(Phrase.build(Phrase.CACHE_ERROR, "world"));
Chat.console(Phrase.build(Phrase.CACHE_RELOAD, Selector.SECOND));
ConfigHandler.loadWorlds(statement);
}
}
}
}