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