forked from LogBlock/LogBlock
Merged block change classes
This commit is contained in:
23
src/de/diddiz/LogBlock/BlockChange.java
Normal file
23
src/de/diddiz/LogBlock/BlockChange.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class BlockChange
|
||||
{
|
||||
public final Location loc;
|
||||
public final String playerName;
|
||||
public final int replaced, type;
|
||||
public final byte data;
|
||||
public final String signtext;
|
||||
public final ChestAccess ca;
|
||||
|
||||
public BlockChange(Location loc, String playerName, int replaced, int type, byte data, String signtext, ChestAccess ca) {
|
||||
this.loc = loc;
|
||||
this.playerName = playerName;
|
||||
this.replaced = replaced;
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
this.signtext = signtext;
|
||||
this.ca = ca;
|
||||
}
|
||||
}
|
13
src/de/diddiz/LogBlock/ChestAccess.java
Normal file
13
src/de/diddiz/LogBlock/ChestAccess.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public class ChestAccess
|
||||
{
|
||||
final short itemType, itemAmount;
|
||||
final byte itemData;
|
||||
|
||||
public ChestAccess(short itemType, short itemAmount, byte itemData) {
|
||||
this.itemType = itemType;
|
||||
this.itemAmount = itemAmount;
|
||||
this.itemData = itemData;
|
||||
}
|
||||
}
|
@@ -484,7 +484,7 @@ public class CommandsHandler implements CommandExecutor
|
||||
rs = state.executeQuery(params.getRollbackQuery());
|
||||
final WorldEditor editor = new WorldEditor(logblock, params.world);
|
||||
while (rs.next())
|
||||
editor.queueBlockChange(rs.getInt("type"), rs.getInt("replaced"), rs.getByte("data"), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), rs.getString("signtext"), rs.getShort("itemtype"), rs.getShort("itemamount"), rs.getByte("itemdata"));
|
||||
editor.queueEdit(rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), rs.getInt("replaced"), rs.getInt("type"), rs.getByte("data"), rs.getString("signtext"), rs.getShort("itemtype"), rs.getShort("itemamount"), rs.getByte("itemdata"));
|
||||
final int changes = editor.getSize();
|
||||
if (!params.silent)
|
||||
sender.sendMessage(ChatColor.GREEN.toString() + changes + " blocks found.");
|
||||
@@ -521,8 +521,9 @@ public class CommandsHandler implements CommandExecutor
|
||||
if (!params.silent)
|
||||
sender.sendMessage(ChatColor.DARK_AQUA + "Searching " + params.getTitle() + ":");
|
||||
final WorldEditor editor = new WorldEditor(logblock, params.world);
|
||||
|
||||
while (rs.next())
|
||||
editor.queueBlockChange(rs.getInt("replaced"), rs.getInt("type"), rs.getByte("data"), rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), rs.getString("signtext"), rs.getShort("itemtype"), (short)(rs.getShort("itemamount") * 1), rs.getByte("itemdata"));
|
||||
editor.queueEdit(rs.getInt("x"), rs.getInt("y"), rs.getInt("z"), rs.getInt("type"), rs.getInt("replaced"), rs.getByte("data"), rs.getString("signtext"), rs.getShort("itemtype"), (short)(rs.getShort("itemamount") * -1), rs.getByte("itemdata"));
|
||||
final int changes = editor.getSize();
|
||||
if (!params.silent)
|
||||
sender.sendMessage(ChatColor.GREEN.toString() + changes + " blocks found.");
|
||||
|
@@ -27,7 +27,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Consumer extends TimerTask
|
||||
{
|
||||
private final Queue<BlockRow> bqueue = new LinkedBlockingQueue<BlockRow>();
|
||||
private final Queue<BlockChange> bqueue = new LinkedBlockingQueue<BlockChange>();
|
||||
private final Config config;
|
||||
private final Set<Integer> hiddenPlayers, hiddenBlocks;
|
||||
private final Queue<KillRow> kqueue = new LinkedBlockingQueue<KillRow>();
|
||||
@@ -234,7 +234,7 @@ public class Consumer extends TimerTask
|
||||
if (conn == null)
|
||||
return;
|
||||
Statement state = null;
|
||||
BlockRow b;
|
||||
BlockChange b;
|
||||
KillRow k;
|
||||
String table;
|
||||
if (getQueueSize() > 1000)
|
||||
@@ -249,14 +249,14 @@ public class Consumer extends TimerTask
|
||||
b = bqueue.poll();
|
||||
if (b == null)
|
||||
continue;
|
||||
final int playerHash = b.name.hashCode();
|
||||
final int playerHash = b.playerName.hashCode();
|
||||
if (!players.containsKey(playerHash))
|
||||
if (!addPlayer(conn, state, b.name)) {
|
||||
log.warning("[LogBlock Consumer] Failed to add player " + b.name);
|
||||
if (!addPlayer(conn, state, b.playerName)) {
|
||||
log.warning("[LogBlock Consumer] Failed to add player " + b.playerName);
|
||||
continue;
|
||||
}
|
||||
table = config.tables.get(b.worldHash);
|
||||
state.execute("INSERT INTO `" + table + "` (date, playerid, replaced, type, data, x, y, z) VALUES (now(), " + players.get(playerHash) + ", " + b.replaced + ", " + b.type + ", " + b.data + ", '" + b.x + "', " + b.y + ", '" + b.z + "')", Statement.RETURN_GENERATED_KEYS);
|
||||
table = config.tables.get(b.loc.getWorld().getName().hashCode());
|
||||
state.execute("INSERT INTO `" + table + "` (date, playerid, replaced, type, data, x, y, z) VALUES (now(), " + players.get(playerHash) + ", " + b.replaced + ", " + b.type + ", " + b.data + ", '" + b.loc.getBlockX() + "', " + b.loc.getBlockY() + ", '" + b.loc.getBlockZ() + "')", Statement.RETURN_GENERATED_KEYS);
|
||||
if (b.signtext != null) {
|
||||
final ResultSet keys = state.getGeneratedKeys();
|
||||
if (keys.next())
|
||||
@@ -337,46 +337,7 @@ public class Consumer extends TimerTask
|
||||
playerName = playerName.replaceAll("[^a-zA-Z0-9_]", "");
|
||||
if (signtext != null)
|
||||
signtext = signtext.replace("\\", "\\\\").replace("'", "\\'");
|
||||
bqueue.add(new BlockRow(loc.getWorld().getName().hashCode(), playerName, typeBefore, typeAfter, data, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), signtext, ca));
|
||||
}
|
||||
|
||||
private static class BlockRow
|
||||
{
|
||||
final ChestAccess ca;
|
||||
final byte data;
|
||||
final String name;
|
||||
final int replaced, type;
|
||||
final String signtext;
|
||||
final int worldHash;
|
||||
final int x, y, z;
|
||||
|
||||
BlockRow(int worldHash, String name, int replaced, int type, byte data, int x, int y, int z, String signtext, ChestAccess ca) {
|
||||
this.worldHash = worldHash;
|
||||
this.name = name;
|
||||
this.replaced = replaced;
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.signtext = signtext;
|
||||
this.ca = ca;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChestAccess
|
||||
{
|
||||
final byte itemData;
|
||||
final short itemType, itemAmount;
|
||||
|
||||
ChestAccess(short itemType, short itemAmount, byte itemData) {
|
||||
this.itemType = itemType;
|
||||
this.itemAmount = itemAmount;
|
||||
if (itemData < 0)
|
||||
this.itemData = 0;
|
||||
else
|
||||
this.itemData = itemData;
|
||||
}
|
||||
bqueue.add(new BlockChange(loc, playerName, typeBefore, typeAfter, data, signtext, ca));
|
||||
}
|
||||
|
||||
private static class KillRow
|
||||
|
@@ -4,6 +4,7 @@ import static de.diddiz.util.BukkitUtils.equalTypes;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -48,8 +49,8 @@ public class WorldEditor implements Runnable
|
||||
return blacklistCollisions;
|
||||
}
|
||||
|
||||
public void queueBlockChange(int type, int replaced, byte data, int x, int y, int z, String signtext, short itemType, short itemAmount, byte itemData) {
|
||||
edits.add(new Edit(type, replaced, data, x, y, z, signtext, itemType, itemAmount, itemData));
|
||||
public void queueEdit(int x, int y, int z, int replaced, int type, byte data, String signtext, short itemType, short itemAmount, byte itemData) {
|
||||
edits.add(new Edit(new Location(world, x, y, z), null, replaced, type, data, signtext, new ChestAccess(itemType, itemAmount, itemData)));
|
||||
}
|
||||
|
||||
public long getElapsedTime() {
|
||||
@@ -96,55 +97,39 @@ public class WorldEditor implements Runnable
|
||||
ERROR, SUCCESS, BLACKLISTED, NO_ACTION
|
||||
}
|
||||
|
||||
private class Edit
|
||||
private class Edit extends BlockChange
|
||||
{
|
||||
private final int type, replaced;
|
||||
private final int x, y, z;
|
||||
private final byte data;
|
||||
private final String signtext;
|
||||
public final short itemType, itemAmount;
|
||||
public final byte itemData;
|
||||
|
||||
Edit(int type, int replaced, byte data, int x, int y, int z, String signtext, short itemType, short itemAmount, byte itemData) {
|
||||
this.type = type;
|
||||
this.replaced = replaced;
|
||||
this.data = data;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.signtext = signtext;
|
||||
this.itemType = itemType;
|
||||
this.itemAmount = itemAmount;
|
||||
this.itemData = itemData;
|
||||
public Edit(Location loc, String playerName, int replaced, int type, byte data, String signtext, ChestAccess ca) {
|
||||
super(loc, playerName, replaced, type, data, signtext, ca);
|
||||
}
|
||||
|
||||
PerformResult perform() {
|
||||
if (config.dontRollback.contains(replaced))
|
||||
return PerformResult.BLACKLISTED;
|
||||
try {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
final Block block = loc.getBlock();
|
||||
final BlockState state = block.getState();
|
||||
if (!world.isChunkLoaded(block.getChunk()))
|
||||
world.loadChunk(block.getChunk());
|
||||
if (type == replaced)
|
||||
if (type == replaced) {
|
||||
if (type == 0) {
|
||||
if (block.setTypeId(0))
|
||||
return PerformResult.SUCCESS;
|
||||
return PerformResult.ERROR;
|
||||
if (!block.setTypeId(0))
|
||||
return PerformResult.ERROR;
|
||||
} else if (type == 23 || type == 54 || type == 61) {
|
||||
if (!(state instanceof ContainerBlock))
|
||||
return PerformResult.NO_ACTION;
|
||||
final Inventory inv = ((ContainerBlock)block.getState()).getInventory();
|
||||
if (itemType != 0)
|
||||
if (itemAmount > 0)
|
||||
inv.removeItem(new ItemStack(itemType, itemAmount, (short)0, itemData));
|
||||
else if (itemAmount < 0)
|
||||
inv.addItem(new ItemStack(itemType, itemAmount * -1, (short)0, itemData));
|
||||
if (ca != null)
|
||||
if (ca.itemAmount > 0)
|
||||
inv.removeItem(new ItemStack(ca.itemType, ca.itemAmount, (short)0, ca.itemData));
|
||||
else if (ca.itemAmount < 0)
|
||||
inv.addItem(new ItemStack(ca.itemType, ca.itemAmount * -1, (short)0, ca.itemData));
|
||||
if (!state.update())
|
||||
return PerformResult.ERROR;
|
||||
return PerformResult.SUCCESS;
|
||||
} else
|
||||
return PerformResult.NO_ACTION;
|
||||
return PerformResult.SUCCESS;
|
||||
}
|
||||
if (!(equalTypes(block.getTypeId(), type) || config.replaceAnyway.contains(block.getTypeId())))
|
||||
return PerformResult.NO_ACTION;
|
||||
if (state instanceof ContainerBlock) {
|
||||
|
Reference in New Issue
Block a user