This commit is contained in:
Olof Larsson 2014-11-25 19:33:27 +01:00
parent 9bcdcc3120
commit f82a80a12b

View File

@ -1,16 +1,14 @@
package com.massivecraft.massivecore.mixin; package com.massivecraft.massivecore.mixin;
import java.util.List; import java.lang.reflect.Constructor;
import org.bukkit.Bukkit; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import com.massivecraft.massivecore.particleeffect.ReflectionUtils;
public class InventoryMixinDefault extends InventoryMixinAbstract public class InventoryMixinDefault extends InventoryMixinAbstract
{ {
// -------------------------------------------- // // -------------------------------------------- //
@ -20,6 +18,32 @@ public class InventoryMixinDefault extends InventoryMixinAbstract
private static InventoryMixinDefault i = new InventoryMixinDefault(); private static InventoryMixinDefault i = new InventoryMixinDefault();
public static InventoryMixinDefault get() { return i; } public static InventoryMixinDefault get() { return i; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public static Class<?> playerInventoryClass;
public static Class<?> entityHumanClass;
public static Constructor<?> playerInventoryConstructor;
public static Class<?> craftInventoryPlayerClass;
public static Constructor<?> craftInventoryPlayerConstructor;
static
{
try
{
playerInventoryClass = ReflectionUtils.PackageType.MINECRAFT_SERVER.getClass("PlayerInventory");
entityHumanClass = ReflectionUtils.PackageType.MINECRAFT_SERVER.getClass("EntityHuman");
playerInventoryConstructor = ReflectionUtils.getConstructor(playerInventoryClass, entityHumanClass);
craftInventoryPlayerClass = ReflectionUtils.PackageType.CRAFTBUKKIT_INVENTORY.getClass("CraftInventoryPlayer");
craftInventoryPlayerConstructor = ReflectionUtils.getConstructor(craftInventoryPlayerClass, playerInventoryClass);
}
catch (Exception e)
{
e.printStackTrace();
}
}
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@ -27,16 +51,17 @@ public class InventoryMixinDefault extends InventoryMixinAbstract
@Override @Override
public PlayerInventory createPlayerInventory() public PlayerInventory createPlayerInventory()
{ {
List<World> worlds = Bukkit.getWorlds(); try
World world = worlds.get(0); {
Object playerInventory = playerInventoryConstructor.newInstance(new Object[]{null});
Location location = world.getSpawnLocation().clone(); Object craftInventoryPlayer = craftInventoryPlayerConstructor.newInstance(playerInventory);
location.setY(999); return (PlayerInventory)craftInventoryPlayer;
}
Player player = (Player) world.spawnEntity(location, EntityType.PLAYER); catch (Exception e)
PlayerInventory ret = player.getInventory(); {
player.remove(); e.printStackTrace();
return ret; return null;
}
} }
@Override @Override