430 lines
13 KiB
Diff
430 lines
13 KiB
Diff
From 1ef159639f4e89be93c2dc0235097a587c8c5f5d Mon Sep 17 00:00:00 2001
|
|
From: Shaun Bennett <phination@me.com>
|
|
Date: Tue, 21 Apr 2015 19:56:41 -0400
|
|
Subject: [PATCH] Mineplex - Item/Inventory Changes
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
|
|
index a8028e3..5f62731 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
|
|
@@ -437,8 +437,8 @@ public class CraftInventory implements Inventory {
|
|
return InventoryType.ENCHANTING;
|
|
} else if (inventory instanceof TileEntityBrewingStand) {
|
|
return InventoryType.BREWING;
|
|
- } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
|
|
- return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
|
|
+ } else if (inventory instanceof MinecraftInventory) {
|
|
+ return ((MinecraftInventory) inventory).getType();
|
|
} else if (inventory instanceof InventoryEnderChest) {
|
|
return InventoryType.ENDER_CHEST;
|
|
} else if (inventory instanceof InventoryMerchant) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
|
|
index 947c493..eed9afa 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
|
|
@@ -31,168 +31,4 @@ public class CraftInventoryCustom extends CraftInventory {
|
|
public CraftInventoryCustom(InventoryHolder owner, int size, String title) {
|
|
super(new MinecraftInventory(owner, size, title));
|
|
}
|
|
-
|
|
- static class MinecraftInventory implements IInventory {
|
|
- private final ItemStack[] items;
|
|
- private int maxStack = MAX_STACK;
|
|
- private final List<HumanEntity> viewers;
|
|
- private final String title;
|
|
- private InventoryType type;
|
|
- private final InventoryHolder owner;
|
|
-
|
|
- public MinecraftInventory(InventoryHolder owner, InventoryType type) {
|
|
- this(owner, type.getDefaultSize(), type.getDefaultTitle());
|
|
- this.type = type;
|
|
- }
|
|
-
|
|
- public MinecraftInventory(InventoryHolder owner, InventoryType type, String title) {
|
|
- this(owner, type.getDefaultSize(), title);
|
|
- this.type = type;
|
|
- }
|
|
-
|
|
- public MinecraftInventory(InventoryHolder owner, int size) {
|
|
- this(owner, size, "Chest");
|
|
- }
|
|
-
|
|
- public MinecraftInventory(InventoryHolder owner, int size, String title) {
|
|
- Validate.notNull(title, "Title cannot be null");
|
|
- Validate.isTrue(title.length() <= 32, "Title cannot be longer than 32 characters");
|
|
- this.items = new ItemStack[size];
|
|
- this.title = title;
|
|
- this.viewers = new ArrayList<HumanEntity>();
|
|
- this.owner = owner;
|
|
- this.type = InventoryType.CHEST;
|
|
- }
|
|
-
|
|
- public int getSize() {
|
|
- return items.length;
|
|
- }
|
|
-
|
|
- public ItemStack getItem(int i) {
|
|
- return items[i];
|
|
- }
|
|
-
|
|
- public ItemStack splitStack(int i, int j) {
|
|
- ItemStack stack = this.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;
|
|
- }
|
|
-
|
|
- public ItemStack splitWithoutUpdate(int i) {
|
|
- ItemStack stack = this.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;
|
|
- }
|
|
-
|
|
- public void setItem(int i, ItemStack itemstack) {
|
|
- items[i] = itemstack;
|
|
- if (itemstack != null && this.getMaxStackSize() > 0 && itemstack.count > this.getMaxStackSize()) {
|
|
- itemstack.count = this.getMaxStackSize();
|
|
- }
|
|
- }
|
|
-
|
|
- public int getMaxStackSize() {
|
|
- return maxStack;
|
|
- }
|
|
-
|
|
- public void setMaxStackSize(int size) {
|
|
- maxStack = size;
|
|
- }
|
|
-
|
|
- public void update() {}
|
|
-
|
|
- public boolean a(EntityHuman entityhuman) {
|
|
- return true;
|
|
- }
|
|
-
|
|
- public ItemStack[] getContents() {
|
|
- return items;
|
|
- }
|
|
-
|
|
- public void onOpen(CraftHumanEntity who) {
|
|
- viewers.add(who);
|
|
- }
|
|
-
|
|
- public void onClose(CraftHumanEntity who) {
|
|
- viewers.remove(who);
|
|
- }
|
|
-
|
|
- public List<HumanEntity> getViewers() {
|
|
- return viewers;
|
|
- }
|
|
-
|
|
- public InventoryType getType() {
|
|
- return type;
|
|
- }
|
|
-
|
|
- public InventoryHolder getOwner() {
|
|
- return owner;
|
|
- }
|
|
-
|
|
- public boolean b(int i, ItemStack itemstack) {
|
|
- return true;
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void startOpen(EntityHuman entityHuman) {
|
|
-
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void closeContainer(EntityHuman entityHuman) {
|
|
-
|
|
- }
|
|
-
|
|
- @Override
|
|
- public int getProperty(int i) {
|
|
- return 0;
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void b(int i, int i1) {
|
|
-
|
|
- }
|
|
-
|
|
- @Override
|
|
- public int g() {
|
|
- return 0;
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void l() {
|
|
-
|
|
- }
|
|
-
|
|
- @Override
|
|
- public String getName() {
|
|
- return title;
|
|
- }
|
|
-
|
|
- @Override
|
|
- public boolean hasCustomName() {
|
|
- return title != null;
|
|
- }
|
|
-
|
|
- @Override
|
|
- public IChatBaseComponent getScoreboardDisplayName() {
|
|
- return new ChatComponentText(title);
|
|
- }
|
|
- }
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
index 23f05f4..fdaf026 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
@@ -26,7 +26,7 @@ import net.minecraft.server.NBTTagString;
|
|
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
|
|
|
@DelegateDeserialization(ItemStack.class)
|
|
-public final class CraftItemStack extends ItemStack {
|
|
+public class CraftItemStack extends ItemStack {
|
|
|
|
public static net.minecraft.server.ItemStack asNMSCopy(ItemStack original) {
|
|
if (original instanceof CraftItemStack) {
|
|
@@ -95,26 +95,30 @@ public final class CraftItemStack extends ItemStack {
|
|
/**
|
|
* Mirror
|
|
*/
|
|
- private CraftItemStack(net.minecraft.server.ItemStack item) {
|
|
+ protected CraftItemStack(net.minecraft.server.ItemStack item) {
|
|
this.handle = item;
|
|
}
|
|
|
|
- private CraftItemStack(ItemStack item) {
|
|
+ protected CraftItemStack(ItemStack item) {
|
|
this(item.getTypeId(), item.getAmount(), item.getDurability(), item.hasItemMeta() ? item.getItemMeta() : null);
|
|
}
|
|
|
|
- private CraftItemStack(Material type, int amount, short durability, ItemMeta itemMeta) {
|
|
+ protected CraftItemStack(Material type, int amount, short durability, ItemMeta itemMeta) {
|
|
setType(type);
|
|
setAmount(amount);
|
|
setDurability(durability);
|
|
setItemMeta(itemMeta);
|
|
}
|
|
|
|
- private CraftItemStack(int typeId, int amount, short durability, ItemMeta itemMeta) {
|
|
+ protected CraftItemStack(int typeId, int amount, short durability, ItemMeta itemMeta) {
|
|
this(Material.getMaterial(typeId), amount, durability, itemMeta);
|
|
|
|
}
|
|
|
|
+ public net.minecraft.server.ItemStack getHandle() {
|
|
+ return handle;
|
|
+ }
|
|
+
|
|
@Override
|
|
public int getTypeId() {
|
|
return handle != null ? CraftMagicNumbers.getId(handle.getItem()) : 0;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/MinecraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/MinecraftInventory.java
|
|
new file mode 100644
|
|
index 0000000..d90d218
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/MinecraftInventory.java
|
|
@@ -0,0 +1,177 @@
|
|
+package org.bukkit.craftbukkit.inventory;
|
|
+
|
|
+import net.minecraft.server.*;
|
|
+import org.apache.commons.lang.Validate;
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
+import org.bukkit.entity.HumanEntity;
|
|
+import org.bukkit.event.inventory.InventoryType;
|
|
+import org.bukkit.inventory.InventoryHolder;
|
|
+
|
|
+import java.util.ArrayList;
|
|
+import java.util.List;
|
|
+
|
|
+public class MinecraftInventory implements IInventory
|
|
+{
|
|
+ private final ItemStack[] items;
|
|
+ private int maxStack = MAX_STACK;
|
|
+ private final List<HumanEntity> viewers;
|
|
+ private final String title;
|
|
+ private InventoryType type;
|
|
+ private final InventoryHolder owner;
|
|
+
|
|
+ public MinecraftInventory(InventoryHolder owner, InventoryType type) {
|
|
+ this(owner, type.getDefaultSize(), type.getDefaultTitle());
|
|
+ this.type = type;
|
|
+ }
|
|
+
|
|
+ public MinecraftInventory(InventoryHolder owner, InventoryType type, String title) {
|
|
+ this(owner, type.getDefaultSize(), title);
|
|
+ this.type = type;
|
|
+ }
|
|
+
|
|
+ public MinecraftInventory(InventoryHolder owner, int size) {
|
|
+ this(owner, size, "Chest");
|
|
+ }
|
|
+
|
|
+ public MinecraftInventory(InventoryHolder owner, int size, String title) {
|
|
+ Validate.notNull(title, "Title cannot be null");
|
|
+ Validate.isTrue(title.length() <= 32, "Title cannot be longer than 32 characters");
|
|
+ this.items = new ItemStack[size];
|
|
+ this.title = title;
|
|
+ this.viewers = new ArrayList<HumanEntity>();
|
|
+ this.owner = owner;
|
|
+ this.type = InventoryType.CHEST;
|
|
+ }
|
|
+
|
|
+ public int getSize() {
|
|
+ return items.length;
|
|
+ }
|
|
+
|
|
+ public ItemStack getItem(int i) {
|
|
+ return items[i];
|
|
+ }
|
|
+
|
|
+ public ItemStack splitStack(int i, int j) {
|
|
+ ItemStack stack = this.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;
|
|
+ }
|
|
+
|
|
+ public ItemStack splitWithoutUpdate(int i) {
|
|
+ ItemStack stack = this.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;
|
|
+ }
|
|
+
|
|
+ public void setItem(int i, ItemStack itemstack) {
|
|
+ items[i] = itemstack;
|
|
+ if (itemstack != null && this.getMaxStackSize() > 0 && itemstack.count > this.getMaxStackSize()) {
|
|
+ itemstack.count = this.getMaxStackSize();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public int getMaxStackSize() {
|
|
+ return maxStack;
|
|
+ }
|
|
+
|
|
+ public void setMaxStackSize(int size) {
|
|
+ maxStack = size;
|
|
+ }
|
|
+
|
|
+ public void update() {}
|
|
+
|
|
+ public boolean a(EntityHuman entityhuman) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ public ItemStack[] getContents() {
|
|
+ return items;
|
|
+ }
|
|
+
|
|
+ public void onOpen(CraftHumanEntity who) {
|
|
+ viewers.add(who);
|
|
+ }
|
|
+
|
|
+ public void onClose(CraftHumanEntity who) {
|
|
+ viewers.remove(who);
|
|
+ }
|
|
+
|
|
+ public List<HumanEntity> getViewers() {
|
|
+ return viewers;
|
|
+ }
|
|
+
|
|
+ public InventoryType getType() {
|
|
+ return type;
|
|
+ }
|
|
+
|
|
+ public InventoryHolder getOwner() {
|
|
+ return owner;
|
|
+ }
|
|
+
|
|
+ public boolean b(int i, ItemStack itemstack) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void startOpen(EntityHuman entityHuman) {
|
|
+
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void closeContainer(EntityHuman entityHuman) {
|
|
+
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getProperty(int i) {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void b(int i, int i1) {
|
|
+
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int g() {
|
|
+ return 0;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void l() {
|
|
+
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getName() {
|
|
+ return title;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean hasCustomName() {
|
|
+ return title != null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public IChatBaseComponent getScoreboardDisplayName() {
|
|
+ return new ChatComponentText(title);
|
|
+ }
|
|
+}
|
|
\ No newline at end of file
|
|
--
|
|
2.3.5
|
|
|