diff options
author | Senmori <thesenmori@gmail.com> | 2018-08-03 19:09:57 -0400 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-08-04 09:41:04 +1000 |
commit | ec2095d9c6dc466bf9be6b515fc7cc40739f89d8 (patch) | |
tree | f50582eca30cd4ee131b87076a3f6586b4c44c21 /src | |
parent | 671581e33ff658c89c780e7adfd68ad423570d79 (diff) | |
download | craftbukkit-ec2095d9c6dc466bf9be6b515fc7cc40739f89d8.tar craftbukkit-ec2095d9c6dc466bf9be6b515fc7cc40739f89d8.tar.gz craftbukkit-ec2095d9c6dc466bf9be6b515fc7cc40739f89d8.tar.lz craftbukkit-ec2095d9c6dc466bf9be6b515fc7cc40739f89d8.tar.xz craftbukkit-ec2095d9c6dc466bf9be6b515fc7cc40739f89d8.zip |
SPIGOT-4223: Fix inventories using the same TileEntity instance.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java | 10 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java | 67 |
2 files changed, 49 insertions, 28 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java index f3ad9540..23389743 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java @@ -2,9 +2,6 @@ package org.bukkit.craftbukkit.inventory.util; import java.util.HashMap; import java.util.Map; -import net.minecraft.server.TileEntityDispenser; -import net.minecraft.server.TileEntityDropper; -import net.minecraft.server.TileEntityHopper; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; @@ -18,9 +15,8 @@ public final class CraftInventoryCreator { private CraftInventoryCreator() { converterMap.put(InventoryType.CHEST, DEFAULT_CONVERTER); - converterMap.put(InventoryType.DISPENSER, new CraftTileInventoryConverter(new TileEntityDispenser())); - converterMap.put(InventoryType.DROPPER, new CraftTileInventoryConverter(new TileEntityDropper())); - // furnace needs a world + converterMap.put(InventoryType.DISPENSER, new CraftTileInventoryConverter.Dispenser()); + converterMap.put(InventoryType.DROPPER, new CraftTileInventoryConverter.Dropper()); converterMap.put(InventoryType.FURNACE, new CraftTileInventoryConverter.Furnace()); converterMap.put(InventoryType.WORKBENCH, DEFAULT_CONVERTER); converterMap.put(InventoryType.ENCHANTING, DEFAULT_CONVERTER); @@ -30,7 +26,7 @@ public final class CraftInventoryCreator { converterMap.put(InventoryType.ENDER_CHEST, DEFAULT_CONVERTER); converterMap.put(InventoryType.ANVIL, DEFAULT_CONVERTER); converterMap.put(InventoryType.BEACON, new CraftTileInventoryConverter.Beacon()); - converterMap.put(InventoryType.HOPPER, new CraftTileInventoryConverter(new TileEntityHopper())); + converterMap.put(InventoryType.HOPPER, new CraftTileInventoryConverter.Hopper()); converterMap.put(InventoryType.SHULKER_BOX, DEFAULT_CONVERTER); } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java index ad2ca442..66c2249e 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java @@ -4,7 +4,10 @@ import net.minecraft.server.ITileInventory; import net.minecraft.server.MinecraftServer; import net.minecraft.server.TileEntityBeacon; import net.minecraft.server.TileEntityBrewingStand; +import net.minecraft.server.TileEntityDispenser; +import net.minecraft.server.TileEntityDropper; import net.minecraft.server.TileEntityFurnace; +import net.minecraft.server.TileEntityHopper; import net.minecraft.server.TileEntityLootable; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.craftbukkit.inventory.CraftInventoryBeacon; @@ -15,26 +18,23 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -public class CraftTileInventoryConverter implements CraftInventoryCreator.InventoryConverter { +public abstract class CraftTileInventoryConverter implements CraftInventoryCreator.InventoryConverter { - protected final ITileInventory tileEntity; - - public CraftTileInventoryConverter(ITileInventory tileEntity) { - this.tileEntity = tileEntity; - } + public abstract ITileInventory getTileEntity(); @Override public Inventory createInventory(InventoryHolder holder, InventoryType type) { - return getInventory(tileEntity); + return getInventory(getTileEntity()); } @Override public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) { - if (tileEntity instanceof TileEntityLootable) { - ((TileEntityLootable) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); + ITileInventory te = getTileEntity(); + if (te instanceof TileEntityLootable) { + ((TileEntityLootable) te).setCustomName(CraftChatMessage.fromStringOrNull(title)); } - return getInventory(tileEntity); + return getInventory(te); } public Inventory getInventory(ITileInventory tileEntity) { @@ -43,37 +43,37 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent public static class Furnace extends CraftTileInventoryConverter { - public Furnace() { - super(new TileEntityFurnace()); - } - @Override - public Inventory createInventory(InventoryHolder owner, InventoryType type) { - return getInventory(tileEntity); + public ITileInventory getTileEntity() { + TileEntityFurnace furnace = new TileEntityFurnace(); + furnace.setWorld(MinecraftServer.getServer().getWorldServer(0)); // TODO: customize this if required + return furnace; } @Override public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) { + ITileInventory tileEntity = getTileEntity(); ((TileEntityFurnace) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); return getInventory(tileEntity); } @Override public Inventory getInventory(ITileInventory tileEntity) { - ((TileEntityFurnace) tileEntity).setWorld(MinecraftServer.getServer().getWorldServer(0)); // TODO: customize this if required return new CraftInventoryFurnace((TileEntityFurnace) tileEntity); } } public static class BrewingStand extends CraftTileInventoryConverter { - public BrewingStand() { - super(new TileEntityBrewingStand()); + @Override + public ITileInventory getTileEntity() { + return new TileEntityBrewingStand(); } @Override public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) { // BrewingStand does not extend TileEntityLootable + ITileInventory tileEntity = getTileEntity(); if (tileEntity instanceof TileEntityBrewingStand) { ((TileEntityBrewingStand) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); } @@ -88,8 +88,9 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent public static class Beacon extends CraftTileInventoryConverter { - public Beacon() { - super(new TileEntityBeacon()); + @Override + public ITileInventory getTileEntity() { + return new TileEntityBeacon(); } @Override @@ -97,4 +98,28 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent return new CraftInventoryBeacon((TileEntityBeacon) tileInventory); } } + + public static class Dispenser extends CraftTileInventoryConverter { + + @Override + public ITileInventory getTileEntity() { + return new TileEntityDispenser(); + } + } + + public static class Dropper extends CraftTileInventoryConverter { + + @Override + public ITileInventory getTileEntity() { + return new TileEntityDropper(); + } + } + + public static class Hopper extends CraftTileInventoryConverter { + + @Override + public ITileInventory getTileEntity() { + return new TileEntityHopper(); + } + } } |