SPIGOT-1080: Added support for opening all inventories implementing Bukkit's Inventory class.
Dieser Commit ist enthalten in:
Ursprung
9935adc4ed
Commit
5e85956281
@ -175,24 +175,25 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
EntityPlayer player = (EntityPlayer) getHandle();
|
||||
InventoryType type = inventory.getType();
|
||||
Container formerContainer = getHandle().activeContainer;
|
||||
// TODO: Should we check that it really IS a CraftInventory first?
|
||||
CraftInventory craftinv = (CraftInventory) inventory;
|
||||
|
||||
IInventory iinventory = (inventory instanceof CraftInventory) ? ((CraftInventory) inventory).getInventory() : new org.bukkit.craftbukkit.inventory.InventoryWrapper(inventory);
|
||||
|
||||
switch (type) {
|
||||
case PLAYER:
|
||||
case CHEST:
|
||||
case ENDER_CHEST:
|
||||
getHandle().openContainer(craftinv.getInventory());
|
||||
getHandle().openContainer(iinventory);
|
||||
break;
|
||||
case DISPENSER:
|
||||
if (craftinv.getInventory() instanceof TileEntityDispenser) {
|
||||
getHandle().openContainer((TileEntityDispenser) craftinv.getInventory());
|
||||
if (iinventory instanceof TileEntityDispenser) {
|
||||
getHandle().openContainer((TileEntityDispenser) iinventory);
|
||||
} else {
|
||||
openCustomInventory(inventory, player, "minecraft:dispenser");
|
||||
}
|
||||
break;
|
||||
case FURNACE:
|
||||
if (craftinv.getInventory() instanceof TileEntityFurnace) {
|
||||
getHandle().openContainer((TileEntityFurnace) craftinv.getInventory());
|
||||
if (iinventory instanceof TileEntityFurnace) {
|
||||
getHandle().openContainer((TileEntityFurnace) iinventory);
|
||||
} else {
|
||||
openCustomInventory(inventory, player, "minecraft:furnace");
|
||||
}
|
||||
@ -201,8 +202,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
openCustomInventory(inventory, player, "minecraft:crafting_table");
|
||||
break;
|
||||
case BREWING:
|
||||
if (craftinv.getInventory() instanceof TileEntityBrewingStand) {
|
||||
getHandle().openContainer((TileEntityBrewingStand) craftinv.getInventory());
|
||||
if (iinventory instanceof TileEntityBrewingStand) {
|
||||
getHandle().openContainer((TileEntityBrewingStand) iinventory);
|
||||
} else {
|
||||
openCustomInventory(inventory, player, "minecraft:brewing_stand");
|
||||
}
|
||||
@ -211,24 +212,24 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
openCustomInventory(inventory, player, "minecraft:enchanting_table");
|
||||
break;
|
||||
case HOPPER:
|
||||
if (craftinv.getInventory() instanceof TileEntityHopper) {
|
||||
getHandle().openContainer((TileEntityHopper) craftinv.getInventory());
|
||||
} else if (craftinv.getInventory() instanceof EntityMinecartHopper) {
|
||||
getHandle().openContainer((EntityMinecartHopper) craftinv.getInventory());
|
||||
if (iinventory instanceof TileEntityHopper) {
|
||||
getHandle().openContainer((TileEntityHopper) iinventory);
|
||||
} else if (iinventory instanceof EntityMinecartHopper) {
|
||||
getHandle().openContainer((EntityMinecartHopper) iinventory);
|
||||
} else {
|
||||
openCustomInventory(inventory, player, "minecraft:hopper");
|
||||
}
|
||||
break;
|
||||
case BEACON:
|
||||
if (craftinv.getInventory() instanceof TileEntityBeacon) {
|
||||
getHandle().openContainer((TileEntityBeacon) craftinv.getInventory());
|
||||
if (iinventory instanceof TileEntityBeacon) {
|
||||
getHandle().openContainer((TileEntityBeacon) iinventory);
|
||||
} else {
|
||||
openCustomInventory(inventory, player, "minecraft:beacon");
|
||||
}
|
||||
break;
|
||||
case ANVIL:
|
||||
if (craftinv.getInventory() instanceof BlockAnvil.TileEntityContainerAnvil) {
|
||||
getHandle().openTileEntity((BlockAnvil.TileEntityContainerAnvil) craftinv.getInventory());
|
||||
if (iinventory instanceof BlockAnvil.TileEntityContainerAnvil) {
|
||||
getHandle().openTileEntity((BlockAnvil.TileEntityContainerAnvil) iinventory);
|
||||
} else {
|
||||
openCustomInventory(inventory, player, "minecraft:anvil");
|
||||
}
|
||||
|
173
src/main/java/org/bukkit/craftbukkit/inventory/InventoryWrapper.java
Normale Datei
173
src/main/java/org/bukkit/craftbukkit/inventory/InventoryWrapper.java
Normale Datei
@ -0,0 +1,173 @@
|
||||
package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.IChatBaseComponent;
|
||||
import net.minecraft.server.IInventory;
|
||||
import net.minecraft.server.ItemStack;
|
||||
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
public class InventoryWrapper implements IInventory {
|
||||
|
||||
private final Inventory inventory;
|
||||
private final List<HumanEntity> viewers = new ArrayList<HumanEntity>();
|
||||
|
||||
public InventoryWrapper(Inventory inventory) {
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return inventory.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
return CraftItemStack.asNMSCopy(inventory.getItem(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
// Copied from CraftItemStack
|
||||
ItemStack stack = getItem(i);
|
||||
ItemStack result;
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
if (stack.count <= j) {
|
||||
this.setItem(i, null);
|
||||
result = stack;
|
||||
} else {
|
||||
result = CraftItemStack.copyNMSStack(stack, j);
|
||||
stack.count -= j;
|
||||
}
|
||||
this.update();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
// Copied from CraftItemStack
|
||||
ItemStack stack = getItem(i);
|
||||
ItemStack result;
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
if (stack.count <= 1) {
|
||||
this.setItem(i, null);
|
||||
result = stack;
|
||||
} else {
|
||||
result = CraftItemStack.copyNMSStack(stack, 1);
|
||||
stack.count -= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
inventory.setItem(i, CraftItemStack.asBukkitCopy(itemstack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return inventory.getMaxStackSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startOpen(EntityHuman entityhuman) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeContainer(EntityHuman entityhuman) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean b(int i, ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProperty(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void b(int i, int j) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int g() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void l() {
|
||||
inventory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
int size = getSize();
|
||||
ItemStack[] items = new ItemStack[size];
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
items[i] = getItem(i);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
viewers.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
viewers.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return viewers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return inventory.getHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
inventory.setMaxStackSize(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return inventory.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return getName() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatBaseComponent getScoreboardDisplayName() {
|
||||
return CraftChatMessage.fromString(getName())[0];
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren