Archiviert
13
0

SPIGOT-4223: Fix inventories using the same TileEntity instance.

Dieser Commit ist enthalten in:
Senmori 2018-08-03 19:09:57 -04:00 committet von md_5
Ursprung 671581e33f
Commit ec2095d9c6
2 geänderte Dateien mit 49 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -2,9 +2,6 @@ package org.bukkit.craftbukkit.inventory.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; 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.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
@ -18,9 +15,8 @@ public final class CraftInventoryCreator {
private CraftInventoryCreator() { private CraftInventoryCreator() {
converterMap.put(InventoryType.CHEST, DEFAULT_CONVERTER); converterMap.put(InventoryType.CHEST, DEFAULT_CONVERTER);
converterMap.put(InventoryType.DISPENSER, new CraftTileInventoryConverter(new TileEntityDispenser())); converterMap.put(InventoryType.DISPENSER, new CraftTileInventoryConverter.Dispenser());
converterMap.put(InventoryType.DROPPER, new CraftTileInventoryConverter(new TileEntityDropper())); converterMap.put(InventoryType.DROPPER, new CraftTileInventoryConverter.Dropper());
// furnace needs a world
converterMap.put(InventoryType.FURNACE, new CraftTileInventoryConverter.Furnace()); converterMap.put(InventoryType.FURNACE, new CraftTileInventoryConverter.Furnace());
converterMap.put(InventoryType.WORKBENCH, DEFAULT_CONVERTER); converterMap.put(InventoryType.WORKBENCH, DEFAULT_CONVERTER);
converterMap.put(InventoryType.ENCHANTING, 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.ENDER_CHEST, DEFAULT_CONVERTER);
converterMap.put(InventoryType.ANVIL, DEFAULT_CONVERTER); converterMap.put(InventoryType.ANVIL, DEFAULT_CONVERTER);
converterMap.put(InventoryType.BEACON, new CraftTileInventoryConverter.Beacon()); 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); converterMap.put(InventoryType.SHULKER_BOX, DEFAULT_CONVERTER);
} }

Datei anzeigen

@ -4,7 +4,10 @@ import net.minecraft.server.ITileInventory;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.TileEntityBeacon; import net.minecraft.server.TileEntityBeacon;
import net.minecraft.server.TileEntityBrewingStand; import net.minecraft.server.TileEntityBrewingStand;
import net.minecraft.server.TileEntityDispenser;
import net.minecraft.server.TileEntityDropper;
import net.minecraft.server.TileEntityFurnace; import net.minecraft.server.TileEntityFurnace;
import net.minecraft.server.TileEntityHopper;
import net.minecraft.server.TileEntityLootable; import net.minecraft.server.TileEntityLootable;
import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.inventory.CraftInventoryBeacon; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
public class CraftTileInventoryConverter implements CraftInventoryCreator.InventoryConverter { public abstract class CraftTileInventoryConverter implements CraftInventoryCreator.InventoryConverter {
protected final ITileInventory tileEntity; public abstract ITileInventory getTileEntity();
public CraftTileInventoryConverter(ITileInventory tileEntity) {
this.tileEntity = tileEntity;
}
@Override @Override
public Inventory createInventory(InventoryHolder holder, InventoryType type) { public Inventory createInventory(InventoryHolder holder, InventoryType type) {
return getInventory(tileEntity); return getInventory(getTileEntity());
} }
@Override @Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) { public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
if (tileEntity instanceof TileEntityLootable) { ITileInventory te = getTileEntity();
((TileEntityLootable) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); if (te instanceof TileEntityLootable) {
((TileEntityLootable) te).setCustomName(CraftChatMessage.fromStringOrNull(title));
} }
return getInventory(tileEntity); return getInventory(te);
} }
public Inventory getInventory(ITileInventory tileEntity) { public Inventory getInventory(ITileInventory tileEntity) {
@ -43,37 +43,37 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent
public static class Furnace extends CraftTileInventoryConverter { public static class Furnace extends CraftTileInventoryConverter {
public Furnace() {
super(new TileEntityFurnace());
}
@Override @Override
public Inventory createInventory(InventoryHolder owner, InventoryType type) { public ITileInventory getTileEntity() {
return getInventory(tileEntity); TileEntityFurnace furnace = new TileEntityFurnace();
furnace.setWorld(MinecraftServer.getServer().getWorldServer(0)); // TODO: customize this if required
return furnace;
} }
@Override @Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) { public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
ITileInventory tileEntity = getTileEntity();
((TileEntityFurnace) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); ((TileEntityFurnace) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title));
return getInventory(tileEntity); return getInventory(tileEntity);
} }
@Override @Override
public Inventory getInventory(ITileInventory tileEntity) { public Inventory getInventory(ITileInventory tileEntity) {
((TileEntityFurnace) tileEntity).setWorld(MinecraftServer.getServer().getWorldServer(0)); // TODO: customize this if required
return new CraftInventoryFurnace((TileEntityFurnace) tileEntity); return new CraftInventoryFurnace((TileEntityFurnace) tileEntity);
} }
} }
public static class BrewingStand extends CraftTileInventoryConverter { public static class BrewingStand extends CraftTileInventoryConverter {
public BrewingStand() { @Override
super(new TileEntityBrewingStand()); public ITileInventory getTileEntity() {
return new TileEntityBrewingStand();
} }
@Override @Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) { public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
// BrewingStand does not extend TileEntityLootable // BrewingStand does not extend TileEntityLootable
ITileInventory tileEntity = getTileEntity();
if (tileEntity instanceof TileEntityBrewingStand) { if (tileEntity instanceof TileEntityBrewingStand) {
((TileEntityBrewingStand) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); ((TileEntityBrewingStand) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title));
} }
@ -88,8 +88,9 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent
public static class Beacon extends CraftTileInventoryConverter { public static class Beacon extends CraftTileInventoryConverter {
public Beacon() { @Override
super(new TileEntityBeacon()); public ITileInventory getTileEntity() {
return new TileEntityBeacon();
} }
@Override @Override
@ -97,4 +98,28 @@ public class CraftTileInventoryConverter implements CraftInventoryCreator.Invent
return new CraftInventoryBeacon((TileEntityBeacon) tileInventory); 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();
}
}
} }