Add an InventoryMixin to prepare nms removal

This commit is contained in:
Olof Larsson 2014-09-12 21:37:27 +02:00
parent 8b175ba9a6
commit 5908636ef2
7 changed files with 87 additions and 20 deletions

View File

@ -2,14 +2,12 @@ package com.massivecraft.massivecore.adapter;
import java.lang.reflect.Type;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryCustom;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryPlayer;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.inventory.MassiveCorePlayerInventory;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext;
import com.massivecraft.massivecore.xlib.gson.JsonDeserializer;
import com.massivecraft.massivecore.xlib.gson.JsonElement;
@ -162,7 +160,7 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
size = 36;
// This is a PlayerInventory
ret = new CraftInventoryPlayer(new MassiveCorePlayerInventory());
ret = Mixin.createPlayerInventory();
PlayerInventory pret = (PlayerInventory)ret;
// helmet
@ -203,7 +201,7 @@ public class InventoryAdapter implements JsonDeserializer<Inventory>, JsonSerial
size = jsonSize.getAsInt();
// This is a "Custom" Inventory (content only).
ret = new CraftInventoryCustom(null, size);
ret = Mixin.createInventory(null, size, null);
}
// Now process content

View File

@ -0,0 +1,14 @@
package com.massivecraft.massivecore.mixin;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.PlayerInventory;
public interface InventoryMixin
{
// Create a Player Inventory without a Player
public PlayerInventory createPlayerInventory();
// Create an arbitrary size standard chest-like inventory
public Inventory createInventory(InventoryHolder holder, int size, String title);
}

View File

@ -0,0 +1,6 @@
package com.massivecraft.massivecore.mixin;
public abstract class InventoryMixinAbstract implements InventoryMixin
{
}

View File

@ -0,0 +1,38 @@
package com.massivecraft.massivecore.mixin;
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
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static InventoryMixinDefault i = new InventoryMixinDefault();
public static InventoryMixinDefault get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public PlayerInventory createPlayerInventory()
{
return new CraftInventoryPlayer(new MassiveCorePlayerInventory());
}
@Override
public Inventory createInventory(InventoryHolder holder, int size, String title)
{
if (title == null)
{
title = "Chest";
}
return new CraftInventoryCustom(holder, size, title);
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.massivecore.inventory;
package com.massivecraft.massivecore.mixin;
import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.server.v1_7_R4.ItemStack;

View File

@ -7,6 +7,9 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.Predictate;
@ -29,6 +32,10 @@ public class Mixin
public static DisplayNameMixin getDisplayNameMixin() { return displayNameMixin; }
public static void setDisplayNameMixin(DisplayNameMixin val) { displayNameMixin = val; }
private static InventoryMixin inventoryMixin = InventoryMixinDefault.get();
public static InventoryMixin getInventoryMixin() { return inventoryMixin; }
public static void setDisplayNameMixin(InventoryMixin val) { inventoryMixin = val; }
private static SenderPsMixin senderPsMixin = SenderPsMixinDefault.get();
public static SenderPsMixin getSenderPsMixin() { return senderPsMixin; }
public static void setSenderPsMixin(SenderPsMixin val) { senderPsMixin = val; }
@ -130,6 +137,20 @@ public class Mixin
return getDisplayNameMixin().getDisplayName(senderObject, watcherObject);
}
// -------------------------------------------- //
// STATIC EXPOSE: INVENTORY
// -------------------------------------------- //
public static PlayerInventory createPlayerInventory()
{
return getInventoryMixin().createPlayerInventory();
}
public static Inventory createInventory(InventoryHolder holder, int size, String title)
{
return getInventoryMixin().createInventory(holder, size, title);
}
// -------------------------------------------- //
// STATIC EXPOSE: SENDER PS
// -------------------------------------------- //

View File

@ -4,8 +4,6 @@ import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryCustom;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryPlayer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -18,7 +16,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.inventory.MassiveCorePlayerInventory;
import com.massivecraft.massivecore.mixin.MassiveCorePlayerInventory;
import com.massivecraft.massivecore.mixin.Mixin;
public class InventoryUtil
{
@ -202,15 +201,6 @@ public class InventoryUtil
System.out.println("===== DEBUG END =====");
}
// -------------------------------------------- //
// CREATE PLAYER INVENTORY
// -------------------------------------------- //
public static PlayerInventory createPlayerInventory()
{
return new CraftInventoryPlayer(new MassiveCorePlayerInventory());
}
// -------------------------------------------- //
// IS EMPTY?
// -------------------------------------------- //
@ -278,7 +268,7 @@ public class InventoryUtil
if (inventory instanceof PlayerInventory)
{
PlayerInventory pret = createPlayerInventory();
PlayerInventory pret = Mixin.createPlayerInventory();
ret = pret;
PlayerInventory pinventory = (PlayerInventory)inventory;
@ -290,7 +280,7 @@ public class InventoryUtil
}
else
{
ret = new CraftInventoryCustom(holder, size, title);
ret = Mixin.createInventory(holder, size, title);
}
ItemStack[] contents = cloneItemStacks(inventory.getContents());