forked from LogBlock/LogBlock
Fixed rollback for doublechests rolling back only one half under some
circumstances.
This commit is contained in:
@@ -598,7 +598,7 @@ public class CommandsHandler implements CommandExecutor
|
|||||||
final WorldEditor editor = new WorldEditor(logblock, params.world);
|
final WorldEditor editor = new WorldEditor(logblock, params.world);
|
||||||
|
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
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"));
|
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"), 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.");
|
||||||
|
@@ -2,6 +2,7 @@ package de.diddiz.LogBlock;
|
|||||||
|
|
||||||
import static de.diddiz.util.BukkitUtils.equalTypes;
|
import static de.diddiz.util.BukkitUtils.equalTypes;
|
||||||
import static de.diddiz.util.BukkitUtils.materialName;
|
import static de.diddiz.util.BukkitUtils.materialName;
|
||||||
|
import static de.diddiz.util.BukkitUtils.modifyContainer;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -18,7 +19,6 @@ import org.bukkit.block.BlockFace;
|
|||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.ContainerBlock;
|
import org.bukkit.block.ContainerBlock;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.Bed;
|
import org.bukkit.material.Bed;
|
||||||
import org.bukkit.material.PistonBaseMaterial;
|
import org.bukkit.material.PistonBaseMaterial;
|
||||||
@@ -141,17 +141,21 @@ public class WorldEditor implements Runnable
|
|||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
if (!block.setTypeId(0))
|
if (!block.setTypeId(0))
|
||||||
throw new WorldEditorException(block.getTypeId(), 0, block.getLocation());
|
throw new WorldEditorException(block.getTypeId(), 0, block.getLocation());
|
||||||
} else if (type == 23 || type == 54 || type == 61) {
|
} else if (ca != null && (type == 23 || type == 54 || type == 61 || type == 62)) {
|
||||||
if (!(state instanceof ContainerBlock))
|
int leftover = 0;
|
||||||
return PerformResult.NO_ACTION;
|
try {
|
||||||
final Inventory inv = ((ContainerBlock)block.getState()).getInventory();
|
leftover = modifyContainer(state, new ItemStack(ca.itemType, -ca.itemAmount, (short)0, ca.itemData));
|
||||||
if (ca != null)
|
if (leftover > 0)
|
||||||
if (ca.itemAmount > 0)
|
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST})
|
||||||
inv.removeItem(new ItemStack(ca.itemType, ca.itemAmount, (short)0, ca.itemData));
|
if (block.getFace(face).getTypeId() == 54)
|
||||||
else if (ca.itemAmount < 0)
|
leftover = modifyContainer(block.getFace(face).getState(), new ItemStack(ca.itemType, ca.itemAmount < 0 ? leftover : -leftover, (short)0, ca.itemData));
|
||||||
inv.addItem(new ItemStack(ca.itemType, ca.itemAmount * -1, (short)0, ca.itemData));
|
} catch (final Exception ex) {
|
||||||
|
throw new WorldEditorException(ex.getMessage(), block.getLocation());
|
||||||
|
}
|
||||||
if (!state.update())
|
if (!state.update())
|
||||||
throw new WorldEditorException("Failed to update inventory of " + materialName(block.getTypeId()));
|
throw new WorldEditorException("Failed to update inventory of " + materialName(block.getTypeId()), block.getLocation());
|
||||||
|
if (leftover > 0 && ca.itemAmount < 0)
|
||||||
|
throw new WorldEditorException("Not enough space left in " + materialName(block.getTypeId()), block.getLocation());
|
||||||
} else
|
} else
|
||||||
return PerformResult.NO_ACTION;
|
return PerformResult.NO_ACTION;
|
||||||
return PerformResult.SUCCESS;
|
return PerformResult.SUCCESS;
|
||||||
@@ -173,7 +177,7 @@ public class WorldEditor implements Runnable
|
|||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
sign.setLine(i, lines[i]);
|
sign.setLine(i, lines[i]);
|
||||||
if (!sign.update())
|
if (!sign.update())
|
||||||
throw new WorldEditorException("Failed to update signtext of " + materialName(block.getTypeId()));
|
throw new WorldEditorException("Failed to update signtext of " + materialName(block.getTypeId()), block.getLocation());
|
||||||
} else if (curtype == 26) {
|
} else if (curtype == 26) {
|
||||||
final Bed bed = (Bed)block.getState().getData();
|
final Bed bed = (Bed)block.getState().getData();
|
||||||
final Block secBlock = bed.isHeadOfBed() ? block.getFace(bed.getFacing().getOppositeFace()) : block.getFace(bed.getFacing());
|
final Block secBlock = bed.isHeadOfBed() ? block.getFace(bed.getFacing().getOppositeFace()) : block.getFace(bed.getFacing());
|
||||||
@@ -208,7 +212,11 @@ public class WorldEditor implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WorldEditorException(int typeBefore, int typeAfter, Location loc) {
|
public WorldEditorException(int typeBefore, int typeAfter, Location loc) {
|
||||||
super("Failed to replace " + materialName(typeBefore) + " with " + materialName(typeAfter) + " at " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ());
|
this("Failed to replace " + materialName(typeBefore) + " with " + materialName(typeAfter), loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorldEditorException(String msg, Location loc) {
|
||||||
|
super(msg + " at " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,8 @@ import org.bukkit.Chunk;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.ContainerBlock;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@@ -168,6 +170,21 @@ public class BukkitUtils
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int modifyContainer(BlockState b, ItemStack item) throws Exception {
|
||||||
|
if (!(b instanceof ContainerBlock))
|
||||||
|
throw new Exception("No container at " + b.getBlock().getLocation().toString());
|
||||||
|
final Inventory inv = ((ContainerBlock)b).getInventory();
|
||||||
|
if (item.getAmount() < 0) {
|
||||||
|
item.setAmount(-item.getAmount());
|
||||||
|
final ItemStack tmp = inv.removeItem(item).get(0);
|
||||||
|
return tmp != null ? tmp.getAmount() : 0;
|
||||||
|
} else if (item.getAmount() > 0) {
|
||||||
|
final ItemStack tmp = inv.addItem(item).get(0);
|
||||||
|
return tmp != null ? tmp.getAmount() : 0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static class ItemStackComparator implements Comparator<ItemStack>
|
public static class ItemStackComparator implements Comparator<ItemStack>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user