From 50af17ee914147ba01245a7c1659926205e436f3 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 12 Sep 2014 22:01:52 +0200 Subject: [PATCH] Look ma\! No NMS\! --- .../mixin/InventoryMixinDefault.java | 28 ++-- .../mixin/MassiveCorePlayerInventory.java | 123 ------------------ .../massivecraft/massivecore/mixin/Mixin.java | 2 +- .../massivecore/util/InventoryUtil.java | 1 - 4 files changed, 20 insertions(+), 134 deletions(-) delete mode 100644 src/com/massivecraft/massivecore/mixin/MassiveCorePlayerInventory.java diff --git a/src/com/massivecraft/massivecore/mixin/InventoryMixinDefault.java b/src/com/massivecraft/massivecore/mixin/InventoryMixinDefault.java index 4de4e172..5772b5ce 100644 --- a/src/com/massivecraft/massivecore/mixin/InventoryMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/InventoryMixinDefault.java @@ -1,10 +1,15 @@ package com.massivecraft.massivecore.mixin; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.PlayerInventory; -import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryCustom; -import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryPlayer; public class InventoryMixinDefault extends InventoryMixinAbstract { @@ -22,17 +27,22 @@ public class InventoryMixinDefault extends InventoryMixinAbstract @Override public PlayerInventory createPlayerInventory() { - return new CraftInventoryPlayer(new MassiveCorePlayerInventory()); + List worlds = Bukkit.getWorlds(); + World world = worlds.get(0); + + Location location = world.getSpawnLocation().clone(); + location.setY(999); + + Player player = (Player) world.spawnEntity(location, EntityType.PLAYER); + PlayerInventory ret = player.getInventory(); + player.remove(); + return ret; } @Override public Inventory createInventory(InventoryHolder holder, int size, String title) { - if (title == null) - { - title = "Chest"; - } - return new CraftInventoryCustom(holder, size, title); + return Bukkit.createInventory(holder, size, title); } -} \ No newline at end of file +} diff --git a/src/com/massivecraft/massivecore/mixin/MassiveCorePlayerInventory.java b/src/com/massivecraft/massivecore/mixin/MassiveCorePlayerInventory.java deleted file mode 100644 index b8aff3f5..00000000 --- a/src/com/massivecraft/massivecore/mixin/MassiveCorePlayerInventory.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.massivecraft.massivecore.mixin; - -import net.minecraft.server.v1_7_R4.EntityHuman; -import net.minecraft.server.v1_7_R4.ItemStack; -import net.minecraft.server.v1_7_R4.PlayerInventory; - -import org.bukkit.inventory.InventoryHolder; - -/** - * This is an extended version of the NMS.PlayerInventory. - * It is extended in such a way that it has a no-arg constructor. - * It is mainly used for deserialization of PlayerInventor. - * - * There is a link/field to the holder/player. - * We override internal methods where necessary. - * - * How to update: - * https://github.com/Bukkit/CraftBukkit/commits/master/src/main/java/net/minecraft/server/PlayerInventory.java - * Make sure there is a no-arg constructor. - * Search for references to "public EntityHuman player". - * - * As of 1.5.1 these are the references: - * - * a(EntityHuman) (2 matches) - * g(int) - * getOwner() - * k() (2 matches) - * m() (2 matches) - * pickup(ItemStack) (2 matches) - * PlayerInventory(EntityHuman) - * - * As of 1.6.1 and 1.6.2 and 1.6.4 and 1.7.2 and 1.7.5 and 1.7.8 and 1.7.10 these are the references: - * - * a(EntityHuman) (2 matches) - * a(float) - * getOwner() - * k() (2 matches) - * m() (2 matches) - * pickup(ItemStack) (2 matches) - * PlayerInventory(EntityHuman) - * - */ - -public class MassiveCorePlayerInventory extends PlayerInventory -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public MassiveCorePlayerInventory() - { - super(null); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - // Is the entityhuman within reach? - // Can it edit the inventory content? - // According to the source code design entityhuman is never null. However we go for safety first. - @Override - public boolean a(EntityHuman entityhuman) - { - // Null cases - if (entityhuman == null) return true; - if (this.player == null) return true; - - // Other people can reach at any time - if (!this.player.equals(entityhuman)) return true; - - return super.a(entityhuman); - } - - // This method handles damage dealt to the armor inside the inventory. - // We simply ignore damage if there is no player. - @Override - public void a(float arg0) - { - if (this.player == null) return; - - super.a(arg0); - } - - // If the player is null there is no owner. - @Override - public InventoryHolder getOwner() - { - if (this.player == null) return null; - - return super.getOwner(); - } - - // This method looks like some sort of recurring tick to the items but not inventories. - // Let's just ignore it if the player is elsewhere. - @Override - public void k() - { - if (this.player == null) return; - - super.k(); - } - - // Called when the player dies and no items should be kept. - // This will cause the player to drop all the items. - @Override - public void m() - { - if (this.player == null) return; - - super.m(); - } - - // Pickup the item. Return if the pickup was successful or not. - @Override - public boolean pickup(ItemStack arg0) - { - if (this.player == null) return false; - - return super.pickup(arg0); - } - -} diff --git a/src/com/massivecraft/massivecore/mixin/Mixin.java b/src/com/massivecraft/massivecore/mixin/Mixin.java index e51d63d8..17fbbee3 100644 --- a/src/com/massivecraft/massivecore/mixin/Mixin.java +++ b/src/com/massivecraft/massivecore/mixin/Mixin.java @@ -34,7 +34,7 @@ public class Mixin private static InventoryMixin inventoryMixin = InventoryMixinDefault.get(); public static InventoryMixin getInventoryMixin() { return inventoryMixin; } - public static void setDisplayNameMixin(InventoryMixin val) { inventoryMixin = val; } + public static void setInventoryMixin(InventoryMixin val) { inventoryMixin = val; } private static SenderPsMixin senderPsMixin = SenderPsMixinDefault.get(); public static SenderPsMixin getSenderPsMixin() { return senderPsMixin; } diff --git a/src/com/massivecraft/massivecore/util/InventoryUtil.java b/src/com/massivecraft/massivecore/util/InventoryUtil.java index 386e62de..af813592 100644 --- a/src/com/massivecraft/massivecore/util/InventoryUtil.java +++ b/src/com/massivecraft/massivecore/util/InventoryUtil.java @@ -16,7 +16,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.mixin.MassiveCorePlayerInventory; import com.massivecraft.massivecore.mixin.Mixin; public class InventoryUtil