summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/minecraft')
-rw-r--r--src/main/java/net/minecraft/server/Container.java19
-rw-r--r--src/main/java/net/minecraft/server/ContainerBrewingStand.java22
-rw-r--r--src/main/java/net/minecraft/server/ContainerChest.java36
-rw-r--r--src/main/java/net/minecraft/server/ContainerDispenser.java27
-rw-r--r--src/main/java/net/minecraft/server/ContainerEnchantTable.java29
-rw-r--r--src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java4
-rw-r--r--src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java32
-rw-r--r--src/main/java/net/minecraft/server/ContainerFurnace.java24
-rw-r--r--src/main/java/net/minecraft/server/ContainerPlayer.java29
-rw-r--r--src/main/java/net/minecraft/server/ContainerWorkbench.java32
-rw-r--r--src/main/java/net/minecraft/server/CraftingManager.java26
-rw-r--r--src/main/java/net/minecraft/server/EntityHuman.java10
-rw-r--r--src/main/java/net/minecraft/server/EntityMinecart.java25
-rw-r--r--src/main/java/net/minecraft/server/EntityPlayer.java53
-rw-r--r--src/main/java/net/minecraft/server/IInventory.java20
-rw-r--r--src/main/java/net/minecraft/server/InventoryCraftResult.java19
-rw-r--r--src/main/java/net/minecraft/server/InventoryCrafting.java34
-rw-r--r--src/main/java/net/minecraft/server/InventoryLargeChest.java35
-rw-r--r--src/main/java/net/minecraft/server/NetServerHandler.java119
-rw-r--r--src/main/java/net/minecraft/server/Packet.java2
-rw-r--r--src/main/java/net/minecraft/server/PlayerInventory.java27
-rw-r--r--src/main/java/net/minecraft/server/TileEntity.java13
-rw-r--r--src/main/java/net/minecraft/server/TileEntityBrewingStand.java30
-rw-r--r--src/main/java/net/minecraft/server/TileEntityChest.java22
-rw-r--r--src/main/java/net/minecraft/server/TileEntityDispenser.java22
-rw-r--r--src/main/java/net/minecraft/server/TileEntityFurnace.java20
26 files changed, 686 insertions, 45 deletions
diff --git a/src/main/java/net/minecraft/server/Container.java b/src/main/java/net/minecraft/server/Container.java
index 1b4c3427..248ae3a2 100644
--- a/src/main/java/net/minecraft/server/Container.java
+++ b/src/main/java/net/minecraft/server/Container.java
@@ -5,8 +5,13 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-public abstract class Container {
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.inventory.InventoryView;
+// CraftBukkit end
+public abstract class Container {
public List d = new ArrayList();
public List e = new ArrayList();
public int windowId = 0;
@@ -14,6 +19,18 @@ public abstract class Container {
protected List listeners = new ArrayList();
private Set b = new HashSet();
+ // CraftBukkit start
+ public boolean checkReachable = true;
+ public abstract InventoryView getBukkitView();
+ public void transferTo(Container other, CraftHumanEntity player) {
+ InventoryView source = this.getBukkitView(), destination = other.getBukkitView();
+ ((CraftInventory)source.getTopInventory()).getInventory().onClose(player);
+ ((CraftInventory)source.getBottomInventory()).getInventory().onClose(player);
+ ((CraftInventory)destination.getTopInventory()).getInventory().onOpen(player);
+ ((CraftInventory)destination.getBottomInventory()).getInventory().onOpen(player);
+ }
+ // CraftBukkit end
+
public Container() {}
protected void a(Slot slot) {
diff --git a/src/main/java/net/minecraft/server/ContainerBrewingStand.java b/src/main/java/net/minecraft/server/ContainerBrewingStand.java
index a0a7d950..25655e58 100644
--- a/src/main/java/net/minecraft/server/ContainerBrewingStand.java
+++ b/src/main/java/net/minecraft/server/ContainerBrewingStand.java
@@ -1,11 +1,21 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerBrewingStand extends Container {
private TileEntityBrewingStand a;
private int b = 0;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerBrewingStand(PlayerInventory playerinventory, TileEntityBrewingStand tileentitybrewingstand) {
+ player = playerinventory; // CraftBukkit
this.a = tileentitybrewingstand;
this.a(new SlotPotionBottle(this, playerinventory.d, tileentitybrewingstand, 0, 56, 46));
this.a(new SlotPotionBottle(this, playerinventory.d, tileentitybrewingstand, 1, 79, 53));
@@ -45,6 +55,7 @@ public class ContainerBrewingStand extends Container {
}
public boolean b(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.a.a(entityhuman);
}
@@ -87,4 +98,15 @@ public class ContainerBrewingStand extends Container {
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+ CraftInventory inventory = new CraftInventory(this.a);
+ bukkitEntity = new CraftInventoryView(this.player.d.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/ContainerChest.java b/src/main/java/net/minecraft/server/ContainerChest.java
index 5da010fd..c1aa3f5f 100644
--- a/src/main/java/net/minecraft/server/ContainerChest.java
+++ b/src/main/java/net/minecraft/server/ContainerChest.java
@@ -1,15 +1,30 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest;
+import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerChest extends Container {
- private IInventory a;
+ public IInventory a; // CraftBukkit - private->public
private int b;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerChest(IInventory iinventory, IInventory iinventory1) {
this.a = iinventory1;
this.b = iinventory1.getSize() / 9;
iinventory1.f();
int i = (this.b - 4) * 18;
+ // CraftBukkit start - save player
+ // TODO: Should we check to make sure it really is an InventoryPlayer?
+ this.player = (PlayerInventory)iinventory;
+ // CraftBukkit end
int j;
int k;
@@ -32,6 +47,7 @@ public class ContainerChest extends Container {
}
public boolean b(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.a.a(entityhuman);
}
@@ -61,6 +77,24 @@ public class ContainerChest extends Container {
return itemstack;
}
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+ CraftInventory inventory;
+ if (a instanceof PlayerInventory) {
+ inventory = new CraftInventoryPlayer((PlayerInventory)a);
+ } else if (a instanceof InventoryLargeChest) {
+ inventory = new CraftInventoryDoubleChest((InventoryLargeChest)a);
+ } else {
+ inventory = new CraftInventory(this.a);
+ }
+ bukkitEntity = new CraftInventoryView(this.player.d.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
+
public void a(EntityHuman entityhuman) {
super.a(entityhuman);
this.a.g();
diff --git a/src/main/java/net/minecraft/server/ContainerDispenser.java b/src/main/java/net/minecraft/server/ContainerDispenser.java
index 463a83ae..276f4362 100644
--- a/src/main/java/net/minecraft/server/ContainerDispenser.java
+++ b/src/main/java/net/minecraft/server/ContainerDispenser.java
@@ -1,11 +1,24 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerDispenser extends Container {
- private TileEntityDispenser a;
+ public TileEntityDispenser a; // CraftBukkit - Private -> Public
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerDispenser(IInventory iinventory, TileEntityDispenser tileentitydispenser) {
this.a = tileentitydispenser;
+ // CraftBukkit start - save player
+ // TODO: Should we check to make sure it really is an InventoryPlayer?
+ this.player = (PlayerInventory)iinventory;
+ // CraftBukkit end
int i;
int j;
@@ -28,6 +41,7 @@ public class ContainerDispenser extends Container {
}
public boolean b(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.a.a(entityhuman);
}
@@ -62,4 +76,15 @@ public class ContainerDispenser extends Container {
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+ CraftInventory inventory = new CraftInventory(this.a);
+ bukkitEntity = new CraftInventoryView(this.player.d.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTable.java b/src/main/java/net/minecraft/server/ContainerEnchantTable.java
index cce9a7f6..3acf5065 100644
--- a/src/main/java/net/minecraft/server/ContainerEnchantTable.java
+++ b/src/main/java/net/minecraft/server/ContainerEnchantTable.java
@@ -8,6 +8,8 @@ import java.util.Random;
import java.util.Map;
import java.util.HashMap;
+import org.bukkit.craftbukkit.inventory.CraftInventoryEnchanting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
@@ -16,7 +18,9 @@ import org.bukkit.entity.Player;
public class ContainerEnchantTable extends Container {
- public IInventory a = new ContainerEnchantTableInventory(this, "Enchant", 1);
+ // CraftBukkit start - make type specific (changed from IInventory)
+ public ContainerEnchantTableInventory a = new ContainerEnchantTableInventory(this, "Enchant", 1);
+ // CraftBukkit end
private World h;
private int i;
private int j;
@@ -24,7 +28,10 @@ public class ContainerEnchantTable extends Container {
private Random l = new Random();
public long b;
public int[] c = new int[3];
- private Player player; // CraftBukkit
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private Player player;
+ // CraftBukkit end
public ContainerEnchantTable(PlayerInventory playerinventory, World world, int i, int j, int k) {
this.h = world;
@@ -44,7 +51,7 @@ public class ContainerEnchantTable extends Container {
for (l = 0; l < 9; ++l) {
this.a(new Slot(playerinventory, l, 8 + l * 18, 142));
}
- player = (Player) playerinventory.d.bukkitEntity; // CraftBukkit
+ player = (Player) playerinventory.d.getBukkitEntity(); // CraftBukkit
}
public void a(ICrafting icrafting) {
@@ -116,7 +123,7 @@ public class ContainerEnchantTable extends Container {
// CraftBukkit start
CraftItemStack item = new CraftItemStack(itemstack);
- PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, h.getWorld().getBlockAt(this.i, this.j, this.k), item, this.c, i);
+ PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), h.getWorld().getBlockAt(this.i, this.j, this.k), item, this.c, i);
h.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
for (i = 0; i < 3; ++i) {
@@ -149,7 +156,7 @@ public class ContainerEnchantTable extends Container {
enchants.put(org.bukkit.enchantments.Enchantment.getById(e.a.id), e.b);
}
CraftItemStack item = new CraftItemStack(itemstack);
- EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.bukkitEntity, h.getWorld().getBlockAt(this.i, this.j, this.k), item, this.c[i], enchants);
+ EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.bukkitEntity, this.getBukkitView(), h.getWorld().getBlockAt(this.i, this.j, this.k), item, this.c[i], enchants, i);
h.getServer().getPluginManager().callEvent(event);
int level = event.getExpLevelCost();
@@ -189,6 +196,7 @@ public class ContainerEnchantTable extends Container {
}
public boolean b(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.h.getTypeId(this.i, this.j, this.k) != Block.ENCHANTMENT_TABLE.id ? false : entityhuman.e((double) this.i + 0.5D, (double) this.j + 0.5D, (double) this.k + 0.5D) <= 64.0D;
}
@@ -223,4 +231,15 @@ public class ContainerEnchantTable extends Container {
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+ CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.a);
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java b/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java
index 7b7bab93..c697ae15 100644
--- a/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java
+++ b/src/main/java/net/minecraft/server/ContainerEnchantTableInventory.java
@@ -1,8 +1,8 @@
package net.minecraft.server;
-class ContainerEnchantTableInventory extends ContainerEnchantTableSubcontainer {
+public class ContainerEnchantTableInventory extends ContainerEnchantTableSubcontainer { // CraftBukkit -> public
- final ContainerEnchantTable a;
+ public final ContainerEnchantTable a; // CraftBukkit -> public
ContainerEnchantTableInventory(ContainerEnchantTable containerenchanttable, String s, int i) {
super(s, i);
diff --git a/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java b/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java
index 14f943ad..17903b2c 100644
--- a/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java
+++ b/src/main/java/net/minecraft/server/ContainerEnchantTableSubcontainer.java
@@ -1,14 +1,44 @@
package net.minecraft.server;
+import java.util.ArrayList;
import java.util.List;
-public class ContainerEnchantTableSubcontainer implements IInventory {
+// CraftBukkit start
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+public class ContainerEnchantTableSubcontainer implements IInventory {
private String a;
private int b;
private ItemStack[] c;
private List d;
+ // CraftBukkit start
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
+
+ public ItemStack[] getContents() {
+ return this.c;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public InventoryHolder getOwner() {
+ return null; // TODO: Enchanting tables don't really have an owner? Maybe they should?
+ }
+ // CraftBukkit end
+
public ContainerEnchantTableSubcontainer(String s, int i) {
this.a = s;
this.b = i;
diff --git a/src/main/java/net/minecraft/server/ContainerFurnace.java b/src/main/java/net/minecraft/server/ContainerFurnace.java
index cc14e532..e2ca557c 100644
--- a/src/main/java/net/minecraft/server/ContainerFurnace.java
+++ b/src/main/java/net/minecraft/server/ContainerFurnace.java
@@ -1,17 +1,27 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryFurnace;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerFurnace extends Container {
- private TileEntityFurnace a;
+ public TileEntityFurnace a; // CraftBukkit - Private -> Public
private int b = 0;
private int c = 0;
private int h = 0;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerFurnace(PlayerInventory playerinventory, TileEntityFurnace tileentityfurnace) {
this.a = tileentityfurnace;
this.a(new Slot(tileentityfurnace, 0, 56, 17));
this.a(new Slot(tileentityfurnace, 1, 56, 53));
this.a(new SlotResult2(playerinventory.d, tileentityfurnace, 2, 116, 35));
+ this.player = playerinventory; // CraftBukkit - save player
int i;
@@ -58,6 +68,7 @@ public class ContainerFurnace extends Container {
}
public boolean b(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.a.a(entityhuman);
}
@@ -100,4 +111,15 @@ public class ContainerFurnace extends Container {
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+ CraftInventoryFurnace inventory = new CraftInventoryFurnace(this.a);
+ bukkitEntity = new CraftInventoryView(this.player.d.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/ContainerPlayer.java b/src/main/java/net/minecraft/server/ContainerPlayer.java
index f5d995e0..fd8bb495 100644
--- a/src/main/java/net/minecraft/server/ContainerPlayer.java
+++ b/src/main/java/net/minecraft/server/ContainerPlayer.java
@@ -1,18 +1,29 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerPlayer extends Container {
public InventoryCrafting craftInventory;
public IInventory resultInventory;
public boolean c;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerPlayer(PlayerInventory playerinventory) {
this(playerinventory, true);
}
public ContainerPlayer(PlayerInventory playerinventory, boolean flag) {
+ this.resultInventory = new InventoryCraftResult(); // CraftBukkit - moved to before InventoryCrafting construction
this.craftInventory = new InventoryCrafting(this, 2, 2);
- this.resultInventory = new InventoryCraftResult();
+ this.craftInventory.resultInventory = this.resultInventory; // CraftBukkit - let InventoryCrafting know about its result slot
+ this.player = playerinventory; // CraftBukkit - save player
this.c = false;
this.c = flag;
this.a((Slot) (new SlotResult(playerinventory.d, this.craftInventory, this.resultInventory, 0, 144, 36)));
@@ -40,11 +51,12 @@ public class ContainerPlayer extends Container {
this.a(new Slot(playerinventory, i, 8 + i * 18, 142));
}
- this.a((IInventory) this.craftInventory);
+ // this.a((IInventory) this.craftInventory); // CraftBukkit - unneeded since it just sets result slot to empty
}
public void a(IInventory iinventory) {
- // CraftBukkit start
+ // CraftBukkit start (Note: the following line would cause an error if called during construction)
+ CraftingManager.getInstance().lastCraftView = getBukkitView();
ItemStack craftResult = CraftingManager.getInstance().craft(this.craftInventory);
this.resultInventory.setItem(0, craftResult);
if (super.listeners.size() < 1) {
@@ -112,4 +124,15 @@ public class ContainerPlayer extends Container {
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftInventory, this.resultInventory);
+ bukkitEntity = new CraftInventoryView(this.player.d.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/ContainerWorkbench.java b/src/main/java/net/minecraft/server/ContainerWorkbench.java
index 46c5c074..b007690e 100644
--- a/src/main/java/net/minecraft/server/ContainerWorkbench.java
+++ b/src/main/java/net/minecraft/server/ContainerWorkbench.java
@@ -1,15 +1,30 @@
package net.minecraft.server;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class ContainerWorkbench extends Container {
- public InventoryCrafting craftInventory = new InventoryCrafting(this, 3, 3);
- public IInventory resultInventory = new InventoryCraftResult();
+ public InventoryCrafting craftInventory; // CraftBukkit - move initialization into constructor
+ public IInventory resultInventory; // CraftBukkit - move initialization into constructor
private World c;
private int h;
private int i;
private int j;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
public ContainerWorkbench(PlayerInventory playerinventory, World world, int i, int j, int k) {
+ // CraftBukkit start - switched order of IInventory construction and stored player
+ this.resultInventory = new InventoryCraftResult();
+ this.craftInventory = new InventoryCrafting(this, 3, 3);
+ this.craftInventory.resultInventory = this.resultInventory;
+ this.player = playerinventory;
+ // CraftBukkit end
this.c = world;
this.h = i;
this.i = j;
@@ -40,6 +55,7 @@ public class ContainerWorkbench extends Container {
public void a(IInventory iinventory) {
// CraftBukkit start
+ CraftingManager.getInstance().lastCraftView = getBukkitView();
ItemStack craftResult = CraftingManager.getInstance().craft(this.craftInventory);
this.resultInventory.setItem(0, craftResult);
if (super.listeners.size() < 1) {
@@ -65,6 +81,7 @@ public class ContainerWorkbench extends Container {
}
public boolean b(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.c.getTypeId(this.h, this.i, this.j) != Block.WORKBENCH.id ? false : entityhuman.e((double) this.h + 0.5D, (double) this.i + 0.5D, (double) this.j + 0.5D) <= 64.0D;
}
@@ -107,4 +124,15 @@ public class ContainerWorkbench extends Container {
return itemstack;
}
+
+ // CraftBukkit start
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftInventory, this.resultInventory);
+ bukkitEntity = new CraftInventoryView(this.player.d.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/CraftingManager.java b/src/main/java/net/minecraft/server/CraftingManager.java
index c785425b..aff11b01 100644
--- a/src/main/java/net/minecraft/server/CraftingManager.java
+++ b/src/main/java/net/minecraft/server/CraftingManager.java
@@ -4,11 +4,19 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.inventory.InventoryView;
+// CraftBukkit end
public class CraftingManager {
private static final CraftingManager a = new CraftingManager();
public List b = new ArrayList(); // CraftBukkit - private -> public
+ // CraftBukkit start
+ public CraftingRecipe lastRecipe;
+ public InventoryView lastCraftView;
+ // CraftBukkit end
public static final CraftingManager getInstance() {
return a;
@@ -218,13 +226,27 @@ public class CraftingManager {
j1 = 0;
}
- return new ItemStack(itemstack.id, 1, j1);
+ // CraftBukkit start - construct a dummy repair recipe
+ ItemStack result = new ItemStack(itemstack.id, 1, j1);
+ List<ItemStack> ingredients = new ArrayList<ItemStack>();
+ ingredients.add(itemstack.cloneItemStack());
+ ingredients.add(itemstack1.cloneItemStack());
+ ShapelessRecipes recipe = new ShapelessRecipes(result.cloneItemStack(), ingredients);
+ inventorycrafting.currentRecipe = recipe;
+ result = CraftEventFactory.callPreCraftEvent(inventorycrafting, result, lastCraftView, true);
+ return result;
+ // CraftBukkit end
} else {
for (j = 0; j < this.b.size(); ++j) {
CraftingRecipe craftingrecipe = (CraftingRecipe) this.b.get(j);
if (craftingrecipe.a(inventorycrafting)) {
- return craftingrecipe.b(inventorycrafting);
+ // CraftBukkit start - INVENTORY_PRE_CRAFT event
+ inventorycrafting.currentRecipe = craftingrecipe;
+ ItemStack result = craftingrecipe.b(inventorycrafting);
+ result = CraftEventFactory.callPreCraftEvent(inventorycrafting, result, lastCraftView, false);
+ return result;
+ // CraftBukkit end
}
}
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 00e32df1..6bd02280 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftItem;
import org.bukkit.craftbukkit.TrigMath;
+import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
@@ -261,7 +262,8 @@ public abstract class EntityHuman extends EntityLiving {
return this.getHealth() <= 0 || this.isSleeping();
}
- protected void closeInventory() {
+ // CraftBukkit - protected -> public
+ public void closeInventory() {
this.activeContainer = this.defaultContainer;
}
@@ -1283,4 +1285,10 @@ public abstract class EntityHuman extends EntityLiving {
this.exp = entityhuman.exp;
this.q = entityhuman.q;
}
+
+ // CraftBukkit start
+ public HumanEntity getBukkitEntity() {
+ return (HumanEntity) super.getBukkitEntity();
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/EntityMinecart.java b/src/main/java/net/minecraft/server/EntityMinecart.java
index 49e1bf03..04223084 100644
--- a/src/main/java/net/minecraft/server/EntityMinecart.java
+++ b/src/main/java/net/minecraft/server/EntityMinecart.java
@@ -1,9 +1,11 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.ArrayList;
import java.util.List;
-// CraftBukkit start
import org.bukkit.Location;
+import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
@@ -13,6 +15,8 @@ import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.event.vehicle.VehicleUpdateEvent;
import org.bukkit.util.Vector;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
// CraftBukkit end
public class EntityMinecart extends Entity implements IInventory {
@@ -40,10 +44,29 @@ public class EntityMinecart extends Entity implements IInventory {
private double flyingY = 0.95;
private double flyingZ = 0.95;
public double maxSpeed = 0.4D;
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>(); // CraftBukkit
public ItemStack[] getContents() {
return this.items;
}
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public InventoryHolder getOwner() {
+ org.bukkit.entity.Entity cart = getBukkitEntity();
+ if(cart instanceof InventoryHolder) return (InventoryHolder) cart;
+ return null;
+ }
// CraftBukkit end
public EntityMinecart(World world) {
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index 5acd959c..b63deb27 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Set;
// CraftBukkit start
+import java.util.EnumSet;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.ChunkCompressionThread;
import org.bukkit.craftbukkit.CraftWorld;
@@ -13,6 +14,7 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.inventory.InventoryType;
// CraftBukkit end
public class EntityPlayer extends EntityHuman implements ICrafting {
@@ -34,6 +36,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
public boolean h;
public int ping;
public boolean viewingCredits = false;
+ public int i;
public EntityPlayer(MinecraftServer minecraftserver, World world, String s, ItemInWorldManager iteminworldmanager) {
super(world);
@@ -448,54 +451,85 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
super.a(d0, flag);
}
- private void aS() {
+ public int aS() { // CraftBukkit - private void -> public int
this.cl = this.cl % 100 + 1;
+ return this.cl; // CraftBukkit
}
public void b(int i, int j, int k) {
+ // CraftBukkit start - INVENTORY_OPEN hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerWorkbench(this.inventory, this.world, i, j, k));
+ if(container == null) return;
+ // CraftBukkit end
+
this.aS();
this.netServerHandler.sendPacket(new Packet100OpenWindow(this.cl, 1, "Crafting", 9));
- this.activeContainer = new ContainerWorkbench(this.inventory, this.world, i, j, k);
+ this.activeContainer = container; // CraftBukkit - Use container we passed to event
this.activeContainer.windowId = this.cl;
this.activeContainer.a((ICrafting) this);
}
public void c(int i, int j, int k) {
+ // CraftBukkit start - INVENTORY_OPEN hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerEnchantTable(this.inventory, this.world, i, j, k));
+ if(container == null) return;
+ // CraftBukkit end
+
this.aS();
this.netServerHandler.sendPacket(new Packet100OpenWindow(this.cl, 4, "Enchanting", 9));
- this.activeContainer = new ContainerEnchantTable(this.inventory, this.world, i, j, k);
+ this.activeContainer = container;
this.activeContainer.windowId = this.cl;
this.activeContainer.a((ICrafting) this);
}
public void a(IInventory iinventory) {
+ // CraftBukkit start - INVENTORY_OPEN hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerChest(this.inventory, iinventory));
+ if(container == null) return;
+ // CraftBukkit end
+
this.aS();
this.netServerHandler.sendPacket(new Packet100OpenWindow(this.cl, 0, iinventory.getName(), iinventory.getSize()));
- this.activeContainer = new ContainerChest(this.inventory, iinventory);
+ this.activeContainer = container; // CraftBukkit - Use container passed to event
this.activeContainer.windowId = this.cl;
this.activeContainer.a((ICrafting) this);
}
public void a(TileEntityFurnace tileentityfurnace) {
+ // CraftBukkit start - INVENTORY_OPEN hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerFurnace(this.inventory, tileentityfurnace));
+ if(container == null) return;
+ // CraftBukkit end
+
this.aS();
this.netServerHandler.sendPacket(new Packet100OpenWindow(this.cl, 2, tileentityfurnace.getName(), tileentityfurnace.getSize()));
- this.activeContainer = new ContainerFurnace(this.inventory, tileentityfurnace);
+ this.activeContainer = container; // CraftBukkit - Use container passed to event
this.activeContainer.windowId = this.cl;
this.activeContainer.a((ICrafting) this);
}
public void a(TileEntityDispenser tileentitydispenser) {
+ // CraftBukkit start - INVENTORY_OPEN hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerDispenser(this.inventory, tileentitydispenser));
+ if(container == null) return;
+ // CraftBukkit end
+
this.aS();
this.netServerHandler.sendPacket(new Packet100OpenWindow(this.cl, 3, tileentitydispenser.getName(), tileentitydispenser.getSize()));
- this.activeContainer = new ContainerDispenser(this.inventory, tileentitydispenser);
+ this.activeContainer = container; // CraftBukkit - Use container passed to event
this.activeContainer.windowId = this.cl;
this.activeContainer.a((ICrafting) this);
}
public void a(TileEntityBrewingStand tileentitybrewingstand) {
+ // CraftBukkit start - INVENTORY_OPEN hook
+ Container container = CraftEventFactory.callInventoryOpenEvent(this, new ContainerBrewingStand(this.inventory, tileentitybrewingstand));
+ if(container == null) return;
+ // CraftBukkit end
+
this.aS();
this.netServerHandler.sendPacket(new Packet100OpenWindow(this.cl, 5, tileentitybrewingstand.getName(), tileentitybrewingstand.getSize()));
- this.activeContainer = new ContainerBrewingStand(this.inventory, tileentitybrewingstand);
+ this.activeContainer = container;
this.activeContainer.windowId = this.cl;
this.activeContainer.a((ICrafting) this);
}
@@ -515,6 +549,11 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
public void a(Container container, List list) {
this.netServerHandler.sendPacket(new Packet104WindowItems(container.windowId, list));
this.netServerHandler.sendPacket(new Packet103SetSlot(-1, -1, this.inventory.l()));
+ // CraftBukkit start - send a Set Slot to update the crafting result slot
+ if (EnumSet.of(InventoryType.CRAFTING,InventoryType.WORKBENCH).contains(container.getBukkitView().getType())) {
+ this.netServerHandler.sendPacket(new Packet103SetSlot(container.windowId, 0, container.b(0).getItem()));
+ }
+ // CraftBukkit end
}
public void a(Container container, int i, int j) {
diff --git a/src/main/java/net/minecraft/server/IInventory.java b/src/main/java/net/minecraft/server/IInventory.java
index b94ab24a..63c3f856 100644
--- a/src/main/java/net/minecraft/server/IInventory.java
+++ b/src/main/java/net/minecraft/server/IInventory.java
@@ -1,5 +1,13 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public interface IInventory {
int getSize();
@@ -22,5 +30,15 @@ public interface IInventory {
void g();
- public abstract ItemStack[] getContents(); // CraftBukkit
+ // CraftBukkit start
+ ItemStack[] getContents();
+
+ void onOpen(CraftHumanEntity who);
+
+ void onClose(CraftHumanEntity who);
+
+ List<HumanEntity> getViewers();
+
+ InventoryHolder getOwner();
+ //CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/InventoryCraftResult.java b/src/main/java/net/minecraft/server/InventoryCraftResult.java
index 154b603a..537f22ae 100644
--- a/src/main/java/net/minecraft/server/InventoryCraftResult.java
+++ b/src/main/java/net/minecraft/server/InventoryCraftResult.java
@@ -1,5 +1,14 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public class InventoryCraftResult implements IInventory {
private ItemStack[] items = new ItemStack[1];
@@ -8,6 +17,16 @@ public class InventoryCraftResult implements IInventory {
public ItemStack[] getContents() {
return this.items;
}
+ public InventoryHolder getOwner() {
+ return null; // Result slots don't get an owner
+ }
+
+ // Don't need a transaction; the InventoryCrafting keeps track of it for us
+ public void onOpen(CraftHumanEntity who) {}
+ public void onClose(CraftHumanEntity who) {}
+ public List<HumanEntity> getViewers() {
+ return new ArrayList<HumanEntity>();
+ }
// CraftBukkit end
public InventoryCraftResult() {}
diff --git a/src/main/java/net/minecraft/server/InventoryCrafting.java b/src/main/java/net/minecraft/server/InventoryCrafting.java
index 1ed97d79..1e22c7cc 100644
--- a/src/main/java/net/minecraft/server/InventoryCrafting.java
+++ b/src/main/java/net/minecraft/server/InventoryCrafting.java
@@ -1,5 +1,15 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public class InventoryCrafting implements IInventory {
private ItemStack[] items;
@@ -7,9 +17,33 @@ public class InventoryCrafting implements IInventory {
private Container c;
// CraftBukkit start
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
+ public CraftingRecipe currentRecipe;
+ public IInventory resultInventory;
+
public ItemStack[] getContents() {
return this.items;
}
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public InventoryType getInvType() {
+ return items.length == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH;
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public InventoryHolder getOwner() {
+ return null; // TODO: Crafting grids don't really have an owner? Maybe they should?
+ }
// CraftBukkit end
public InventoryCrafting(Container container, int i, int j) {
diff --git a/src/main/java/net/minecraft/server/InventoryLargeChest.java b/src/main/java/net/minecraft/server/InventoryLargeChest.java
index 5090563f..88cfdcce 100644
--- a/src/main/java/net/minecraft/server/InventoryLargeChest.java
+++ b/src/main/java/net/minecraft/server/InventoryLargeChest.java
@@ -1,12 +1,23 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public class InventoryLargeChest implements IInventory {
private String a;
- private IInventory b;
- private IInventory c;
+ public IInventory b; // CraftBukkit - private -> public
+ public IInventory c; // CraftBukkit - private -> public
// CraftBukkit start
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
+
public ItemStack[] getContents() {
ItemStack[] result = new ItemStack[this.getSize()];
for (int i = 0; i < result.length; i++) {
@@ -14,6 +25,26 @@ public class InventoryLargeChest implements IInventory {
}
return result;
}
+
+ public void onOpen(CraftHumanEntity who) {
+ b.onOpen(who);
+ c.onOpen(who);
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ b.onClose(who);
+ c.onClose(who);
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public InventoryHolder getOwner() {
+ return null; // Double chests technically have multiple owners, so there's no sensible way to pick one
+ }
// CraftBukkit end
public InventoryLargeChest(String s, IInventory iinventory, IInventory iinventory1) {
diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java
index d2cd707c..cf6ecc85 100644
--- a/src/main/java/net/minecraft/server/NetServerHandler.java
+++ b/src/main/java/net/minecraft/server/NetServerHandler.java
@@ -9,16 +9,20 @@ import java.util.logging.Logger;
// CraftBukkit start
import java.util.Arrays;
import java.util.HashSet;
+
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.ChunkCompressionThread;
import org.bukkit.Location;
import org.bukkit.command.CommandException;
import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.TextWrapper;
+import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
@@ -34,6 +38,12 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
+import org.bukkit.event.Event.Result;
+import org.bukkit.event.inventory.*;
+import org.bukkit.event.inventory.InventoryType.SlotType;
+import org.bukkit.inventory.CraftingInventory;
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.Recipe;
// CraftBukkit end
public class NetServerHandler extends NetHandler implements ICommandListener {
@@ -980,6 +990,12 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
public void a(Packet101CloseWindow packet101closewindow) {
if (this.player.dead) return; // CraftBukkit
+ // CraftBukkit start - INVENTORY_CLOSE hook
+ InventoryCloseEvent event = new InventoryCloseEvent(this.player.activeContainer.getBukkitView());
+ server.getPluginManager().callEvent(event);
+ this.player.activeContainer.transferTo(this.player.defaultContainer, getPlayer());
+ // CraftBukkit end
+
this.player.E();
}
@@ -987,10 +1003,53 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
if (this.player.dead) return; // CraftBukkit
if (this.player.activeContainer.windowId == packet102windowclick.a && this.player.activeContainer.c(this.player)) {
- ItemStack itemstack = this.player.activeContainer.a(packet102windowclick.b, packet102windowclick.c, packet102windowclick.f, this.player);
+ // CraftBukkit start - fire InventoryClickEvent
+ InventoryView inventory = this.player.activeContainer.getBukkitView();
+ SlotType type = CraftInventoryView.getSlotType(inventory, packet102windowclick.b);
+
+ InventoryClickEvent event;
+ if (inventory instanceof CraftingInventory) {
+ Recipe recipe = ((CraftingInventory)inventory.getTopInventory()).getRecipe();
+ event = new CraftItemEvent(recipe, inventory, type, packet102windowclick.b, packet102windowclick.c != 0, packet102windowclick.f);
+ } else {
+ event = new InventoryClickEvent(inventory, type, packet102windowclick.b, packet102windowclick.c != 0, packet102windowclick.f);
+ }
+ server.getPluginManager().callEvent(event);
+
+ ItemStack itemstack = null;
+ boolean defaultBehaviour = false;
+
+ switch(event.getResult()) {
+ case DEFAULT:
+ itemstack = this.player.activeContainer.a(packet102windowclick.b, packet102windowclick.c, packet102windowclick.f, this.player);
+ defaultBehaviour = true;
+ break;
+ case DENY: // Deny any change, including changes from the event
+ break;
+ case ALLOW: // Allow changes unconditionally
+ org.bukkit.inventory.ItemStack cursor = event.getCursor();
+ if (cursor == null) {
+ this.player.inventory.b((ItemStack) null);
+ } else {
+ this.player.inventory.b(CraftItemStack.createNMSItemStack(cursor));
+ }
+ org.bukkit.inventory.ItemStack item = event.getCurrentItem();
+ if (item != null) {
+ itemstack = CraftItemStack.createNMSItemStack(item);
+ if(packet102windowclick.b == -999) {
+ this.player.b(itemstack);
+ } else {
+ this.player.activeContainer.b(packet102windowclick.b).c(itemstack);
+ }
+ } else if (packet102windowclick.b != -999) {
+ this.player.activeContainer.b(packet102windowclick.b).c((ItemStack) null);
+ }
+ break;
+ }
+ // CraftBukkit end
- if (ItemStack.matches(packet102windowclick.e, itemstack)) {
- this.player.netServerHandler.sendPacket(new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true));
+ if (defaultBehaviour && ItemStack.matches(packet102windowclick.e, itemstack)) { // CraftBukkit - additional condition added
+ this.player.netServerHandler.sendPacket((Packet) (new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true)));
this.player.h = true;
this.player.activeContainer.a();
this.player.D();
@@ -1006,6 +1065,11 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
}
this.player.a(this.player.activeContainer, arraylist);
+
+ // CraftBukkit start - send a Set Slot to update the crafting result slot
+ if(type == SlotType.RESULT && itemstack != null)
+ this.player.netServerHandler.sendPacket((Packet) (new Packet103SetSlot(this.player.activeContainer.windowId, 0, itemstack)));
+ // CraftBukkit end
}
}
}
@@ -1025,17 +1089,46 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
boolean flag2 = itemstack == null || itemstack.id < Item.byId.length && itemstack.id >= 0 && Item.byId[itemstack.id] != null && !invalidItems.contains(itemstack.id); // CraftBukkit
boolean flag3 = itemstack == null || itemstack.getData() >= 0 && itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0;
- if (flag1 && flag2 && flag3) {
- if (itemstack == null) {
- this.player.defaultContainer.a(packet107setcreativeslot.a, (ItemStack) null);
- } else {
- this.player.defaultContainer.a(packet107setcreativeslot.a, itemstack);
+ // CraftBukkit start - Fire INVENTORY_CLICK event
+ HumanEntity player = this.player.getBukkitEntity();
+ InventoryView inventory = new CraftInventoryView(player, player.getInventory(), this.player.defaultContainer);
+ SlotType slot = SlotType.QUICKBAR;
+ if (packet107setcreativeslot.a == -1) {
+ slot = SlotType.OUTSIDE;
+ }
+ InventoryClickEvent event = new InventoryClickEvent(inventory, slot, slot == SlotType.OUTSIDE ? -999 : packet107setcreativeslot.a, false, false);
+ server.getPluginManager().callEvent(event);
+ org.bukkit.inventory.ItemStack item = event.getCurrentItem();
+ if (event.getResult() == Result.ALLOW) {
+ if (slot == SlotType.QUICKBAR) {
+ if (item == null) {
+ this.player.defaultContainer.a(packet107setcreativeslot.a, (ItemStack) null);
+ } else {
+ this.player.defaultContainer.a(packet107setcreativeslot.a, CraftItemStack.createNMSItemStack(item));
+ }
+ } else if (item != null) {
+ this.player.b(CraftItemStack.createNMSItemStack(item));
}
+ } else if (event.getResult() == Result.DENY) {
+ // TODO: Will this actually work?
+ if (packet107setcreativeslot.a > -1) {
+ this.player.netServerHandler.sendPacket(new Packet103SetSlot(this.player.defaultContainer.windowId, packet107setcreativeslot.a, CraftItemStack.createNMSItemStack(item)));
+ }
+ this.player.netServerHandler.sendPacket(new Packet103SetSlot(this.player.defaultContainer.windowId, -1, null));
+ } else if (event.getResult() == Result.DEFAULT) {
+ // CraftBukkit end
+ if (flag1 && flag2 && flag3) {
+ if (itemstack == null) {
+ this.player.defaultContainer.a(packet107setcreativeslot.a, (ItemStack) null);
+ } else {
+ this.player.defaultContainer.a(packet107setcreativeslot.a, itemstack);
+ }
- this.player.defaultContainer.a(this.player, true);
- } else if (flag && flag2 && flag3) {
- this.player.b(itemstack);
- }
+ this.player.defaultContainer.a(this.player, true);
+ } else if (flag && flag2 && flag3) {
+ this.player.b(itemstack);
+ }
+ } // CraftBukkit closing brace
}
}
@@ -1152,4 +1245,4 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
}
}
// CraftBukkit end
-} \ No newline at end of file
+}
diff --git a/src/main/java/net/minecraft/server/Packet.java b/src/main/java/net/minecraft/server/Packet.java
index 5f425338..930acd41 100644
--- a/src/main/java/net/minecraft/server/Packet.java
+++ b/src/main/java/net/minecraft/server/Packet.java
@@ -157,7 +157,7 @@ public abstract class Packet {
}
protected void a(ItemStack itemstack, DataOutputStream dataoutputstream) throws IOException { // CraftBukkit
- if (itemstack == null) {
+ if (itemstack == null || itemstack.id <= 0) {
dataoutputstream.writeShort(-1);
} else {
dataoutputstream.writeShort(itemstack.id);
diff --git a/src/main/java/net/minecraft/server/PlayerInventory.java b/src/main/java/net/minecraft/server/PlayerInventory.java
index dda79ed3..98116eb3 100644
--- a/src/main/java/net/minecraft/server/PlayerInventory.java
+++ b/src/main/java/net/minecraft/server/PlayerInventory.java
@@ -1,5 +1,14 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public class PlayerInventory implements IInventory {
public ItemStack[] items = new ItemStack[36];
@@ -10,6 +19,8 @@ public class PlayerInventory implements IInventory {
public boolean e = false;
// CraftBukkit start
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
+
public ItemStack[] getContents() {
return this.items;
}
@@ -17,6 +28,22 @@ public class PlayerInventory implements IInventory {
public ItemStack[] getArmorContents() {
return this.armor;
}
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public InventoryHolder getOwner() {
+ return d.getBukkitEntity();
+ }
// CraftBukkit end
public PlayerInventory(EntityHuman entityhuman) {
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index da9b4913..18095d2a 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -3,6 +3,11 @@ package net.minecraft.server;
import java.util.HashMap;
import java.util.Map;
+// CraftBukkit start
+import org.bukkit.block.BlockState;
+import org.bukkit.inventory.InventoryHolder;
+// CraftBukkit end
+
public class TileEntity {
private static Map a = new HashMap();
@@ -120,4 +125,12 @@ public class TileEntity {
a(TileEntityEnchantTable.class, "EnchantTable");
a(TileEntityEnderPortal.class, "Airportal");
}
+
+ // CraftBukkit start
+ public InventoryHolder getOwner() {
+ BlockState state = world.getWorld().getBlockAt(x, y, z).getState();
+ if(state instanceof InventoryHolder) return (InventoryHolder) state;
+ return null;
+ }
+ // CraftBukkit end
}
diff --git a/src/main/java/net/minecraft/server/TileEntityBrewingStand.java b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java
index 328dafa6..466b65eb 100644
--- a/src/main/java/net/minecraft/server/TileEntityBrewingStand.java
+++ b/src/main/java/net/minecraft/server/TileEntityBrewingStand.java
@@ -2,6 +2,16 @@ package net.minecraft.server;
import java.util.List;
+// CraftBukkit start
+import java.util.ArrayList;
+
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.event.inventory.BrewEvent;
+import org.bukkit.inventory.BrewerInventory;
+// CraftBukkit end
+
public class TileEntityBrewingStand extends TileEntity implements IInventory {
public ItemStack[] a = new ItemStack[4]; // CraftBukkit private -> public
@@ -12,6 +22,20 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
public TileEntityBrewingStand() {}
// CraftBukkit start
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
public ItemStack[] getContents() {
return this.a;
}
@@ -97,6 +121,12 @@ public class TileEntityBrewingStand extends TileEntity implements IInventory {
if (this.o()) {
ItemStack itemstack = this.a[3];
+ // CraftBukkit start - fire BREW event
+ BrewEvent event = new BrewEvent(world.getWorld().getBlockAt(x, y, z), (BrewerInventory) this.getOwner().getInventory());
+ Bukkit.getPluginManager().callEvent(event);
+ if(event.isCancelled()) return;
+ // CraftBukkit end
+
for (int i = 0; i < 3; ++i) {
if (this.a[i] != null && this.a[i].id == Item.POTION.id) {
int j = this.a[i].getData();
diff --git a/src/main/java/net/minecraft/server/TileEntityChest.java b/src/main/java/net/minecraft/server/TileEntityChest.java
index 17e3e236..1bae4976 100644
--- a/src/main/java/net/minecraft/server/TileEntityChest.java
+++ b/src/main/java/net/minecraft/server/TileEntityChest.java
@@ -1,5 +1,13 @@
package net.minecraft.server;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class TileEntityChest extends TileEntity implements IInventory {
private ItemStack[] items = new ItemStack[27]; // CraftBukkit
@@ -14,9 +22,23 @@ public class TileEntityChest extends TileEntity implements IInventory {
private int ticks;
// CraftBukkit start
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
+
public ItemStack[] getContents() {
return this.items;
}
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
// CraftBukkit end
public TileEntityChest() {}
diff --git a/src/main/java/net/minecraft/server/TileEntityDispenser.java b/src/main/java/net/minecraft/server/TileEntityDispenser.java
index 25c9b23c..7608aae8 100644
--- a/src/main/java/net/minecraft/server/TileEntityDispenser.java
+++ b/src/main/java/net/minecraft/server/TileEntityDispenser.java
@@ -2,15 +2,37 @@ package net.minecraft.server;
import java.util.Random;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class TileEntityDispenser extends TileEntity implements IInventory {
private ItemStack[] items = new ItemStack[9];
private Random b = new Random();
// CraftBukkit start
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
+
public ItemStack[] getContents() {
return this.items;
}
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
// CraftBukkit end
public TileEntityDispenser() {}
diff --git a/src/main/java/net/minecraft/server/TileEntityFurnace.java b/src/main/java/net/minecraft/server/TileEntityFurnace.java
index 6aac0de1..f6f951c7 100644
--- a/src/main/java/net/minecraft/server/TileEntityFurnace.java
+++ b/src/main/java/net/minecraft/server/TileEntityFurnace.java
@@ -1,9 +1,16 @@
package net.minecraft.server;
// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+
import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.HumanEntity;
+import org.bukkit.entity.Player;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.FurnaceSmeltEvent;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
// CraftBukkit end
public class TileEntityFurnace extends TileEntity implements IInventory {
@@ -15,10 +22,23 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
// CraftBukkit start
private int lastTick = (int) (System.currentTimeMillis() / 50);
+ public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
public ItemStack[] getContents() {
return this.items;
}
+
+ public void onOpen(CraftHumanEntity who) {
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
// CraftBukkit end
public TileEntityFurnace() {}