From b6490dada59fa2f7777448c09f591384faa8333e Mon Sep 17 00:00:00 2001 From: Senmori Date: Fri, 21 Oct 2016 16:35:55 +1100 Subject: [PATCH] SPIGOT-2706: Implement support for Lock NBT Tag Containers may now implement the Lockable interface. --- .../bukkit/craftbukkit/block/CraftBeacon.java | 5 +-- .../craftbukkit/block/CraftBrewingStand.java | 4 +- .../bukkit/craftbukkit/block/CraftChest.java | 4 +- .../craftbukkit/block/CraftContainer.java | 41 +++++++++++++++++++ .../craftbukkit/block/CraftDispenser.java | 4 +- .../craftbukkit/block/CraftDropper.java | 4 +- .../craftbukkit/block/CraftFurnace.java | 4 +- .../bukkit/craftbukkit/block/CraftHopper.java | 4 +- 8 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java index 1cb5e589a3..d70f26163f 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java @@ -10,13 +10,12 @@ import org.bukkit.block.Beacon; import org.bukkit.block.Block; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventoryBeacon; -import org.bukkit.craftbukkit.potion.CraftPotionUtil; import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.Inventory; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -public class CraftBeacon extends CraftBlockState implements Beacon { +public class CraftBeacon extends CraftContainer implements Beacon { private final CraftWorld world; private final TileEntityBeacon beacon; @@ -28,7 +27,7 @@ public class CraftBeacon extends CraftBlockState implements Beacon { } public CraftBeacon(final Material material, final TileEntityBeacon te) { - super(material); + super(material, te); world = null; beacon = te; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java index b3f9c64e3b..fbebeab056 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBrewingStand.java @@ -8,7 +8,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventoryBrewer; import org.bukkit.inventory.BrewerInventory; -public class CraftBrewingStand extends CraftBlockState implements BrewingStand { +public class CraftBrewingStand extends CraftContainer implements BrewingStand { private final TileEntityBrewingStand brewingStand; public CraftBrewingStand(Block block) { @@ -18,7 +18,7 @@ public class CraftBrewingStand extends CraftBlockState implements BrewingStand { } public CraftBrewingStand(final Material material, final TileEntityBrewingStand te) { - super(material); + super(material, te); brewingStand = te; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java index ce36ee4a39..f15c26bc1f 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java @@ -11,7 +11,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest; import org.bukkit.inventory.Inventory; -public class CraftChest extends CraftBlockState implements Chest { +public class CraftChest extends CraftContainer implements Chest { private final CraftWorld world; private final TileEntityChest chest; @@ -23,7 +23,7 @@ public class CraftChest extends CraftBlockState implements Chest { } public CraftChest(final Material material, final TileEntityChest te) { - super(material); + super(material, te); chest = te; world = null; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java new file mode 100644 index 0000000000..adf15651cd --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java @@ -0,0 +1,41 @@ +package org.bukkit.craftbukkit.block; + +import net.minecraft.server.ChestLock; +import net.minecraft.server.TileEntity; +import net.minecraft.server.TileEntityContainer; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Lockable; +import org.bukkit.craftbukkit.CraftWorld; + +public class CraftContainer extends CraftBlockState implements Lockable { + + private final TileEntityContainer container; + + public CraftContainer(Block block) { + super(block); + + container = (TileEntityContainer) ((CraftWorld) block.getWorld()).getTileEntityAt(block.getX(), block.getY(), block.getZ()); + } + + public CraftContainer(final Material material, TileEntity tileEntity) { + super(material); + + container = (TileEntityContainer) tileEntity; + } + + @Override + public boolean isLocked() { + return container.x_(); // PAIL: isLocked + } + + @Override + public String getLock() { + return container.y_().b(); // PAIL: getLock, getKey + } + + @Override + public void setLock(String key) { + container.a(key == null ? ChestLock.a : new ChestLock(key)); // PAIL: setLock + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java index a3ca3a5f2a..003381a68b 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java @@ -14,7 +14,7 @@ import org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource; import org.bukkit.inventory.Inventory; import org.bukkit.projectiles.BlockProjectileSource; -public class CraftDispenser extends CraftBlockState implements Dispenser { +public class CraftDispenser extends CraftContainer implements Dispenser { private final CraftWorld world; private final TileEntityDispenser dispenser; @@ -26,7 +26,7 @@ public class CraftDispenser extends CraftBlockState implements Dispenser { } public CraftDispenser(final Material material, final TileEntityDispenser te) { - super(material); + super(material, te); world = null; dispenser = te; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java index 3f7f536a91..a29eaf9a28 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java @@ -12,7 +12,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.inventory.Inventory; -public class CraftDropper extends CraftBlockState implements Dropper { +public class CraftDropper extends CraftContainer implements Dropper { private final CraftWorld world; private final TileEntityDropper dropper; @@ -24,7 +24,7 @@ public class CraftDropper extends CraftBlockState implements Dropper { } public CraftDropper(final Material material, TileEntityDropper te) { - super(material); + super(material, te); world = null; dropper = te; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java index f17fb6f791..eb723c80a3 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java @@ -8,7 +8,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventoryFurnace; import org.bukkit.inventory.FurnaceInventory; -public class CraftFurnace extends CraftBlockState implements Furnace { +public class CraftFurnace extends CraftContainer implements Furnace { private final TileEntityFurnace furnace; public CraftFurnace(final Block block) { @@ -18,7 +18,7 @@ public class CraftFurnace extends CraftBlockState implements Furnace { } public CraftFurnace(final Material material, final TileEntityFurnace te) { - super(material); + super(material, te); furnace = te; } diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java index db844a3ca0..f155790d1b 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java @@ -8,7 +8,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.inventory.Inventory; -public class CraftHopper extends CraftBlockState implements Hopper { +public class CraftHopper extends CraftContainer implements Hopper { private final TileEntityHopper hopper; public CraftHopper(final Block block) { @@ -18,7 +18,7 @@ public class CraftHopper extends CraftBlockState implements Hopper { } public CraftHopper(final Material material, final TileEntityHopper te) { - super(material); + super(material, te); hopper = te; }