Merge pull request #516 from frymaster/worldeditor-changes

Improvements to checks for inventory blocks and double inventory blocks
This commit is contained in:
frymaster
2014-01-14 02:56:12 -08:00
4 changed files with 25 additions and 17 deletions

View File

@@ -10,6 +10,7 @@ import org.bukkit.block.Sign;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.Material;
import org.bukkit.material.Bed; import org.bukkit.material.Bed;
import org.bukkit.material.PistonBaseMaterial; import org.bukkit.material.PistonBaseMaterial;
import org.bukkit.material.PistonExtensionMaterial; import org.bukkit.material.PistonExtensionMaterial;
@@ -26,6 +27,7 @@ import java.util.logging.Level;
import static de.diddiz.LogBlock.config.Config.dontRollback; import static de.diddiz.LogBlock.config.Config.dontRollback;
import static de.diddiz.LogBlock.config.Config.replaceAnyway; import static de.diddiz.LogBlock.config.Config.replaceAnyway;
import static de.diddiz.util.BukkitUtils.equalTypes; import static de.diddiz.util.BukkitUtils.equalTypes;
import static de.diddiz.util.BukkitUtils.getContainerBlocks;
import static de.diddiz.util.BukkitUtils.modifyContainer; import static de.diddiz.util.BukkitUtils.modifyContainer;
import static de.diddiz.util.MaterialName.materialName; import static de.diddiz.util.MaterialName.materialName;
import static org.bukkit.Bukkit.getLogger; import static org.bukkit.Bukkit.getLogger;
@@ -162,13 +164,15 @@ 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 (ca != null && (type == 23 || type == 54 || type == 61 || type == 62)) { } else if (ca != null) {
if (getContainerBlocks().contains(Material.getMaterial(type))) {
int leftover; int leftover;
try { try {
leftover = modifyContainer(state, new ItemStack(ca.itemType, -ca.itemAmount, ca.itemData)); leftover = modifyContainer(state, new ItemStack(ca.itemType, -ca.itemAmount, ca.itemData));
if (leftover > 0) // Special-case blocks which might be double chests
if (leftover > 0 && (type == 54 || type == 146))
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST})
if (block.getRelative(face).getTypeId() == 54) if (block.getRelative(face).getTypeId() == type)
leftover = modifyContainer(block.getRelative(face).getState(), new ItemStack(ca.itemType, ca.itemAmount < 0 ? leftover : -leftover, ca.itemData)); leftover = modifyContainer(block.getRelative(face).getState(), new ItemStack(ca.itemType, ca.itemAmount < 0 ? leftover : -leftover, ca.itemData));
} catch (final Exception ex) { } catch (final Exception ex) {
throw new WorldEditorException(ex.getMessage(), block.getLocation()); throw new WorldEditorException(ex.getMessage(), block.getLocation());
@@ -177,6 +181,7 @@ public class WorldEditor implements Runnable
throw new WorldEditorException("Failed to update inventory of " + materialName(block.getTypeId()), block.getLocation()); throw new WorldEditorException("Failed to update inventory of " + materialName(block.getTypeId()), block.getLocation());
if (leftover > 0 && ca.itemAmount < 0) if (leftover > 0 && ca.itemAmount < 0)
throw new WorldEditorException("Not enough space left in " + materialName(block.getTypeId()), block.getLocation()); 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;

View File

@@ -18,9 +18,11 @@ import org.bukkit.entity.WitherSkull;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.Material;
import static de.diddiz.LogBlock.config.Config.getWorldConfig; import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.logCreeperExplosionsAsPlayerWhoTriggeredThese; import static de.diddiz.LogBlock.config.Config.logCreeperExplosionsAsPlayerWhoTriggeredThese;
import static de.diddiz.util.BukkitUtils.getContainerBlocks;
public class ExplosionLogging extends LoggingListener public class ExplosionLogging extends LoggingListener
{ {
@@ -90,7 +92,7 @@ public class ExplosionLogging extends LoggingListener
final int type = block.getTypeId(); final int type = block.getTypeId();
if (wcfg.isLogging(Logging.SIGNTEXT) & (type == 63 || type == 68)) if (wcfg.isLogging(Logging.SIGNTEXT) & (type == 63 || type == 68))
consumer.queueSignBreak(name, (Sign)block.getState()); consumer.queueSignBreak(name, (Sign)block.getState());
else if (wcfg.isLogging(Logging.CHESTACCESS) && (type == 23 || type == 54 || type == 61)) else if (wcfg.isLogging(Logging.CHESTACCESS) && (getContainerBlocks().contains(Material.getMaterial(type))))
consumer.queueContainerBreak(name, block.getState()); consumer.queueContainerBreak(name, block.getState());
else else
consumer.queueBlockBreak(name, block.getState()); consumer.queueBlockBreak(name, block.getState());

View File

@@ -60,12 +60,12 @@ public class ToolListener implements Listener
params.sel = null; params.sel = null;
if (behavior == ToolBehavior.BLOCK) if (behavior == ToolBehavior.BLOCK)
params.setLocation(block.getRelative(event.getBlockFace()).getLocation()); params.setLocation(block.getRelative(event.getBlockFace()).getLocation());
else if (block.getTypeId() != 54 || tool.params.radius != 0) else if ((block.getTypeId() != 54 && block.getTypeId() != 146) || tool.params.radius != 0)
params.setLocation(block.getLocation()); params.setLocation(block.getLocation());
else { else {
if (logblock.getServer().getPluginManager().isPluginEnabled("WorldEdit")) { if (logblock.getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) { for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
if (block.getRelative(face).getTypeId() == 54) { if (block.getRelative(face).getTypeId() == block.getTypeId()) {
params.setSelection(RegionContainer.fromCorners(event.getPlayer().getWorld(), params.setSelection(RegionContainer.fromCorners(event.getPlayer().getWorld(),
block.getLocation(), block.getRelative(face).getLocation())); block.getLocation(), block.getRelative(face).getLocation()));
} }

View File

@@ -153,6 +153,7 @@ public class BukkitUtils
containerBlocks.add(Material.HOPPER); containerBlocks.add(Material.HOPPER);
containerBlocks.add(Material.BREWING_STAND); containerBlocks.add(Material.BREWING_STAND);
containerBlocks.add(Material.FURNACE); containerBlocks.add(Material.FURNACE);
containerBlocks.add(Material.BURNING_FURNACE);
containerBlocks.add(Material.BEACON); containerBlocks.add(Material.BEACON);
// Doesn't actually have a block inventory // Doesn't actually have a block inventory
// containerBlocks.add(Material.ENDER_CHEST); // containerBlocks.add(Material.ENDER_CHEST);