Archiviert
13
0

fix bug with lootable API

was returning the NMS instance of objects instead of the Bukkit API objects
Dieser Commit ist enthalten in:
Aikar 2016-05-07 21:16:38 -04:00
Ursprung cc7e114f6b
Commit 0494f36efe

Datei anzeigen

@ -1,4 +1,4 @@
From a19f9f1576418e180545e27121f2667b0d74fbc5 Mon Sep 17 00:00:00 2001 From 94597bcbc07975928e87c481635d37e922e351a2 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co> From: Aikar <aikar@aikar.co>
Date: Sun, 1 May 2016 21:19:14 -0400 Date: Sun, 1 May 2016 21:19:14 -0400
Subject: [PATCH] LootTable API & Replenishable Lootables Feature Subject: [PATCH] LootTable API & Replenishable Lootables Feature
@ -61,10 +61,10 @@ index 0000000..36c36d1
+} +}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java
new file mode 100644 new file mode 100644
index 0000000..042fc6f index 0000000..20d236c
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java +++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java
@@ -0,0 +1,28 @@ @@ -0,0 +1,33 @@
+package com.destroystokyo.paper.loottable; +package com.destroystokyo.paper.loottable;
+ +
+import net.minecraft.server.BlockPosition; +import net.minecraft.server.BlockPosition;
@ -78,6 +78,11 @@ index 0000000..042fc6f
+ TileEntityLootable getTileEntity(); + TileEntityLootable getTileEntity();
+ +
+ @Override + @Override
+ default LootableInventory getAPILootableInventory() {
+ return this;
+ }
+
+ @Override
+ default World getNMSWorld() { + default World getNMSWorld() {
+ return getTileEntity().getWorld(); + return getTileEntity().getWorld();
+ } + }
@ -95,10 +100,10 @@ index 0000000..042fc6f
+} +}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java
new file mode 100644 new file mode 100644
index 0000000..6407c58 index 0000000..1150dee
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java +++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java
@@ -0,0 +1,26 @@ @@ -0,0 +1,31 @@
+package com.destroystokyo.paper.loottable; +package com.destroystokyo.paper.loottable;
+ +
+import net.minecraft.server.World; +import net.minecraft.server.World;
@ -108,6 +113,11 @@ index 0000000..6407c58
+ +
+ net.minecraft.server.Entity getHandle(); + net.minecraft.server.Entity getHandle();
+ +
+ @Override
+ default LootableInventory getAPILootableInventory() {
+ return this;
+ }
+
+ default Entity getEntity() { + default Entity getEntity() {
+ return getHandle().getBukkitEntity(); + return getHandle().getBukkitEntity();
+ } + }
@ -127,10 +137,10 @@ index 0000000..6407c58
+} +}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java
new file mode 100644 new file mode 100644
index 0000000..87917d5 index 0000000..6680976
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java +++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java
@@ -0,0 +1,87 @@ @@ -0,0 +1,88 @@
+package com.destroystokyo.paper.loottable; +package com.destroystokyo.paper.loottable;
+ +
+import org.apache.commons.lang.Validate; +import org.apache.commons.lang.Validate;
@ -140,6 +150,7 @@ index 0000000..87917d5
+public interface CraftLootableInventory extends CraftLootable, LootableInventory { +public interface CraftLootableInventory extends CraftLootable, LootableInventory {
+ +
+ CraftLootableInventoryData getLootableData(); + CraftLootableInventoryData getLootableData();
+ LootableInventory getAPILootableInventory();
+ +
+ @Override + @Override
+ default boolean isRefillEnabled() { + default boolean isRefillEnabled() {
@ -220,7 +231,7 @@ index 0000000..87917d5
+} +}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java
new file mode 100644 new file mode 100644
index 0000000..4b2c3fd index 0000000..353a4ff
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java +++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java
@@ -0,0 +1,179 @@ @@ -0,0 +1,179 @@
@ -304,7 +315,7 @@ index 0000000..4b2c3fd
+ +
+ +
+ final Player bukkitPlayer = (Player) player.getBukkitEntity(); + final Player bukkitPlayer = (Player) player.getBukkitEntity();
+ LootableInventoryReplenishEvent event = new LootableInventoryReplenishEvent(bukkitPlayer, lootable); + LootableInventoryReplenishEvent event = new LootableInventoryReplenishEvent(bukkitPlayer, lootable.getAPILootableInventory());
+ if (paperConfig.restrictPlayerReloot && hasPlayerLooted(player.getUniqueID())) { + if (paperConfig.restrictPlayerReloot && hasPlayerLooted(player.getUniqueID())) {
+ event.setCancelled(true); + event.setCancelled(true);
+ } + }
@ -404,16 +415,17 @@ index 0000000..4b2c3fd
+ } + }
+} +}
diff --git a/src/main/java/net/minecraft/server/EntityMinecartContainer.java b/src/main/java/net/minecraft/server/EntityMinecartContainer.java diff --git a/src/main/java/net/minecraft/server/EntityMinecartContainer.java b/src/main/java/net/minecraft/server/EntityMinecartContainer.java
index 56e7de8..4b3cf93 100644 index 56e7de8..92f92b8 100644
--- a/src/main/java/net/minecraft/server/EntityMinecartContainer.java --- a/src/main/java/net/minecraft/server/EntityMinecartContainer.java
+++ b/src/main/java/net/minecraft/server/EntityMinecartContainer.java +++ b/src/main/java/net/minecraft/server/EntityMinecartContainer.java
@@ -3,17 +3,20 @@ package net.minecraft.server; @@ -3,17 +3,21 @@ package net.minecraft.server;
import java.util.Random; import java.util.Random;
// CraftBukkit start // CraftBukkit start
import java.util.List; import java.util.List;
+ +
+import com.destroystokyo.paper.loottable.CraftLootableInventoryData; // Paper +import com.destroystokyo.paper.loottable.CraftLootableInventoryData; // Paper
+import com.destroystokyo.paper.loottable.CraftLootableInventory; // Paper +import com.destroystokyo.paper.loottable.CraftLootableInventory; // Paper
+import com.destroystokyo.paper.loottable.LootableInventory; // Paper
import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
@ -430,7 +442,7 @@ index 56e7de8..4b3cf93 100644
// CraftBukkit start // CraftBukkit start
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>(); public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
@@ -130,6 +133,7 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp @@ -130,6 +134,7 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
protected void b(NBTTagCompound nbttagcompound) { protected void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound); super.b(nbttagcompound);
@ -438,7 +450,7 @@ index 56e7de8..4b3cf93 100644
if (this.c != null) { if (this.c != null) {
nbttagcompound.setString("LootTable", this.c.toString()); nbttagcompound.setString("LootTable", this.c.toString());
if (this.d != 0L) { if (this.d != 0L) {
@@ -156,6 +160,7 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp @@ -156,6 +161,7 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
protected void a(NBTTagCompound nbttagcompound) { protected void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound); super.a(nbttagcompound);
this.items = new ItemStack[this.getSize()]; this.items = new ItemStack[this.getSize()];
@ -446,7 +458,7 @@ index 56e7de8..4b3cf93 100644
if (nbttagcompound.hasKeyOfType("LootTable", 8)) { if (nbttagcompound.hasKeyOfType("LootTable", 8)) {
this.c = new MinecraftKey(nbttagcompound.getString("LootTable")); this.c = new MinecraftKey(nbttagcompound.getString("LootTable"));
this.d = nbttagcompound.getLong("LootTableSeed"); this.d = nbttagcompound.getLong("LootTableSeed");
@@ -217,10 +222,10 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp @@ -217,10 +223,10 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
} }
public void f(EntityHuman entityhuman) { public void f(EntityHuman entityhuman) {
@ -459,7 +471,7 @@ index 56e7de8..4b3cf93 100644
Random random; Random random;
if (this.d == 0L) { if (this.d == 0L) {
@@ -249,12 +254,47 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp @@ -249,12 +255,52 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
} }
@ -476,7 +488,7 @@ index 56e7de8..4b3cf93 100644
} }
+ +
+ // Paper start + // Paper start
+ private CraftLootableInventoryData lootableData = new CraftLootableInventoryData(this); + private final CraftLootableInventoryData lootableData = new CraftLootableInventoryData(this);
+ +
+ @Override + @Override
+ public CraftLootableInventoryData getLootableData() { + public CraftLootableInventoryData getLootableData() {
@ -484,6 +496,11 @@ index 56e7de8..4b3cf93 100644
+ } + }
+ +
+ @Override + @Override
+ public LootableInventory getAPILootableInventory() {
+ return (LootableInventory) this.getBukkitEntity();
+ }
+
+ @Override
+ public World getNMSWorld() { + public World getNMSWorld() {
+ return this.world; + return this.world;
+ } + }
@ -508,14 +525,15 @@ index 56e7de8..4b3cf93 100644
+ // Paper end + // Paper end
} }
diff --git a/src/main/java/net/minecraft/server/TileEntityLootable.java b/src/main/java/net/minecraft/server/TileEntityLootable.java diff --git a/src/main/java/net/minecraft/server/TileEntityLootable.java b/src/main/java/net/minecraft/server/TileEntityLootable.java
index 437ac1e..2df98ff 100644 index 437ac1e..7b73c50 100644
--- a/src/main/java/net/minecraft/server/TileEntityLootable.java --- a/src/main/java/net/minecraft/server/TileEntityLootable.java
+++ b/src/main/java/net/minecraft/server/TileEntityLootable.java +++ b/src/main/java/net/minecraft/server/TileEntityLootable.java
@@ -1,15 +1,19 @@ @@ -1,15 +1,20 @@
package net.minecraft.server; package net.minecraft.server;
+import com.destroystokyo.paper.loottable.CraftLootableInventoryData; // Paper +import com.destroystokyo.paper.loottable.CraftLootableInventoryData; // Paper
+import com.destroystokyo.paper.loottable.CraftLootableInventory; // Paper +import com.destroystokyo.paper.loottable.CraftLootableInventory; // Paper
+import com.destroystokyo.paper.loottable.LootableInventory; // Paper
+ +
import java.util.Random; import java.util.Random;
@ -533,7 +551,7 @@ index 437ac1e..2df98ff 100644
if (nbttagcompound.hasKeyOfType("LootTable", 8)) { if (nbttagcompound.hasKeyOfType("LootTable", 8)) {
this.m = new MinecraftKey(nbttagcompound.getString("LootTable")); this.m = new MinecraftKey(nbttagcompound.getString("LootTable"));
this.n = nbttagcompound.getLong("LootTableSeed"); this.n = nbttagcompound.getLong("LootTableSeed");
@@ -20,6 +24,7 @@ public abstract class TileEntityLootable extends TileEntityContainer implements @@ -20,6 +25,7 @@ public abstract class TileEntityLootable extends TileEntityContainer implements
} }
protected boolean d(NBTTagCompound nbttagcompound) { protected boolean d(NBTTagCompound nbttagcompound) {
@ -541,7 +559,7 @@ index 437ac1e..2df98ff 100644
if (this.m != null) { if (this.m != null) {
nbttagcompound.setString("LootTable", this.m.toString()); nbttagcompound.setString("LootTable", this.m.toString());
if (this.n != 0L) { if (this.n != 0L) {
@@ -33,10 +38,10 @@ public abstract class TileEntityLootable extends TileEntityContainer implements @@ -33,10 +39,10 @@ public abstract class TileEntityLootable extends TileEntityContainer implements
} }
protected void d(EntityHuman entityhuman) { protected void d(EntityHuman entityhuman) {
@ -554,7 +572,7 @@ index 437ac1e..2df98ff 100644
Random random; Random random;
if (this.n == 0L) { if (this.n == 0L) {
@@ -56,12 +61,46 @@ public abstract class TileEntityLootable extends TileEntityContainer implements @@ -56,12 +62,51 @@ public abstract class TileEntityLootable extends TileEntityContainer implements
} }
@ -570,7 +588,7 @@ index 437ac1e..2df98ff 100644
} }
+ +
+ // Paper start - LootTable API + // Paper start - LootTable API
+ private CraftLootableInventoryData lootableData = new CraftLootableInventoryData(this); + private final CraftLootableInventoryData lootableData = new CraftLootableInventoryData(this);
+ +
+ @Override + @Override
+ public CraftLootableInventoryData getLootableData() { + public CraftLootableInventoryData getLootableData() {
@ -578,6 +596,11 @@ index 437ac1e..2df98ff 100644
+ } + }
+ +
+ @Override + @Override
+ public LootableInventory getAPILootableInventory() {
+ return (LootableInventory) getBukkitWorld().getBlockAt(MCUtil.toLocation(world, getPosition())).getState();
+ }
+
+ @Override
+ public World getNMSWorld() { + public World getNMSWorld() {
+ return world; + return world;
+ } + }