Look ma\! No NMS\!
This commit is contained in:
parent
5908636ef2
commit
50af17ee91
@ -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<World> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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; }
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user