Better support other Player implementations

Closes #60
Removed all volatile comments - they require me to occasionally manually maintain them and NMS/OBC imports are already kept separate
This commit is contained in:
Jikoo 2017-01-20 12:56:31 -05:00
parent 5ca2ae461a
commit e34e51d127
114 changed files with 693 additions and 403 deletions

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_4_5.AxisAlignedBB;
import net.minecraft.server.v1_4_5.BlockEnderChest;
import net.minecraft.server.v1_4_5.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_4_5.TileEntityChest;
import net.minecraft.server.v1_4_5.TileEntityEnderChest;
import net.minecraft.server.v1_4_5.World;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_5.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_5.IInventory;
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_4_5.EntityPlayer;
import net.minecraft.server.v1_4_5.ItemInWorldManager;
import net.minecraft.server.v1_4_5.MinecraftServer;
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_4_5;
// Volatile
import net.minecraft.server.v1_4_5.ContainerChest;
import net.minecraft.server.v1_4_5.EntityHuman;
import net.minecraft.server.v1_4_5.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_4_5.EntityPlayer;
import net.minecraft.server.v1_4_5.IInventory;
import net.minecraft.server.v1_4_5.InventoryEnderChest;
import net.minecraft.server.v1_4_5.InventorySubcontainer;
@ -46,12 +46,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -64,8 +64,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_5.ItemStack;
import net.minecraft.server.v1_4_5.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_4_6.AxisAlignedBB;
import net.minecraft.server.v1_4_6.BlockEnderChest;
import net.minecraft.server.v1_4_6.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_4_6.TileEntityChest;
import net.minecraft.server.v1_4_6.TileEntityEnderChest;
import net.minecraft.server.v1_4_6.World;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_6.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_6.IInventory;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_4_6.EntityPlayer;
import net.minecraft.server.v1_4_6.MinecraftServer;
import net.minecraft.server.v1_4_6.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_4_6;
// Volatile
import net.minecraft.server.v1_4_6.ContainerChest;
import net.minecraft.server.v1_4_6.EntityHuman;
import net.minecraft.server.v1_4_6.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_4_6.EntityPlayer;
import net.minecraft.server.v1_4_6.IInventory;
import net.minecraft.server.v1_4_6.InventoryEnderChest;
import net.minecraft.server.v1_4_6.InventorySubcontainer;
@ -46,12 +46,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -64,8 +64,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_6.ItemStack;
import net.minecraft.server.v1_4_6.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockChest;
@ -43,7 +42,6 @@ import net.minecraft.server.v1_10_R1.TileEntityChest;
import net.minecraft.server.v1_10_R1.TileEntityEnderChest;
import net.minecraft.server.v1_10_R1.World;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -55,7 +53,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
Block block = world.getType(blockPosition).getBlock();
@ -114,7 +112,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is pretty much API-only
if (silentchest && b.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_10_R1.IInventory;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;

View file

@ -25,14 +25,15 @@ import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers();
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_10_R1;
// Volatile
import net.minecraft.server.v1_10_R1.ContainerChest;
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.IInventory;

View file

@ -24,13 +24,12 @@ import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.IInventory;
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
import net.minecraft.server.v1_10_R1.InventorySubcontainer;
import net.minecraft.server.v1_10_R1.ItemStack;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -40,12 +39,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player;
this.enderChest = craftPlayer.getHandle().getEnderChest();
this.bukkitOwner = craftPlayer;
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemArrays(this, enderChest.getContents());
}
@ -78,9 +77,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
this.bukkitOwner = player;
CraftPlayer craftPlayer = (CraftPlayer) player;
setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items);
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemArrays(nmsPlayer.getEnderChest(), this.items);
} catch (Exception e) {}
playerOnline = true;
}

View file

@ -24,12 +24,10 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -39,7 +37,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
}
@ -89,7 +87,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
setItemArrays(this.player.inventory, items, armor, extraSlots);
playerOnline = true;
}

View file

@ -25,7 +25,6 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
// Volatile
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockChest;
@ -49,7 +48,6 @@ import net.minecraft.server.v1_11_R1.TileEntityEnderChest;
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
import net.minecraft.server.v1_11_R1.World;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -65,7 +63,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
IBlockData blockData = world.getType(blockPosition);
@ -156,7 +154,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is pretty much API-only
if (silentchest && b.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_11_R1.IInventory;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;

View file

@ -25,14 +25,15 @@ import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers();
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_11_R1;
// Volatile
import net.minecraft.server.v1_11_R1.ContainerChest;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory;

View file

@ -25,13 +25,12 @@ import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
import net.minecraft.server.v1_11_R1.InventorySubcontainer;
import net.minecraft.server.v1_11_R1.ItemStack;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -41,12 +40,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player;
this.enderChest = craftPlayer.getHandle().getEnderChest();
this.bukkitOwner = craftPlayer;
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemLists(this, enderChest.getContents());
}
@ -79,9 +78,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
this.bukkitOwner = player;
CraftPlayer craftPlayer = (CraftPlayer) player;
setItemLists(craftPlayer.getHandle().getEnderChest(), this.items);
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemLists(nmsPlayer.getEnderChest(), this.items);
} catch (Exception e) {}
playerOnline = true;
}

View file

@ -26,13 +26,11 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_11_R1.ContainerUtil;
// Volatile
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NonNullList;
import net.minecraft.server.v1_11_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -41,7 +39,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
}
@ -91,7 +89,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);;
setItemArrays(this.player.inventory, items, armor, extraSlots);
playerOnline = true;
}

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
import net.minecraft.server.v1_4_R1.BlockEnderChest;
import net.minecraft.server.v1_4_R1.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_4_R1.TileEntityChest;
import net.minecraft.server.v1_4_R1.TileEntityEnderChest;
import net.minecraft.server.v1_4_R1.World;
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_R1.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_R1.IInventory;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_R1.EntityPlayer;
import net.minecraft.server.v1_4_R1.MinecraftServer;
import net.minecraft.server.v1_4_R1.PlayerInteractManager;
// Volatile
import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -78,4 +79,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_4_R1;
// Volatile
import net.minecraft.server.v1_4_R1.ContainerChest;
import net.minecraft.server.v1_4_R1.EntityHuman;
import net.minecraft.server.v1_4_R1.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_4_R1.EntityPlayer;
import net.minecraft.server.v1_4_R1.IInventory;
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
import net.minecraft.server.v1_4_R1.InventorySubcontainer;
@ -46,12 +46,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -64,8 +64,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_R1.ItemStack;
import net.minecraft.server.v1_4_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
import net.minecraft.server.v1_5_R2.BlockEnderChest;
import net.minecraft.server.v1_5_R2.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_5_R2.TileEntityChest;
import net.minecraft.server.v1_5_R2.TileEntityEnderChest;
import net.minecraft.server.v1_5_R2.World;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R2.IInventory;
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_5_R2.EntityPlayer;
import net.minecraft.server.v1_5_R2.MinecraftServer;
import net.minecraft.server.v1_5_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().f(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_5_R2;
// Volatile
import net.minecraft.server.v1_5_R2.ContainerChest;
import net.minecraft.server.v1_5_R2.EntityHuman;
import net.minecraft.server.v1_5_R2.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_5_R2.EntityPlayer;
import net.minecraft.server.v1_5_R2.IInventory;
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
import net.minecraft.server.v1_5_R2.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R2.ItemStack;
import net.minecraft.server.v1_5_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_5_R3.AxisAlignedBB;
import net.minecraft.server.v1_5_R3.BlockEnderChest;
import net.minecraft.server.v1_5_R3.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_5_R3.TileEntityChest;
import net.minecraft.server.v1_5_R3.TileEntityEnderChest;
import net.minecraft.server.v1_5_R3.World;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R3.IInventory;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_5_R3.EntityPlayer;
import net.minecraft.server.v1_5_R3.MinecraftServer;
import net.minecraft.server.v1_5_R3.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_5_R3;
// Volatile
import net.minecraft.server.v1_5_R3.ContainerChest;
import net.minecraft.server.v1_5_R3.EntityHuman;
import net.minecraft.server.v1_5_R3.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_5_R3.EntityPlayer;
import net.minecraft.server.v1_5_R3.IInventory;
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
import net.minecraft.server.v1_5_R3.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R3.ItemStack;
import net.minecraft.server.v1_5_R3.PlayerInventory;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R1.AxisAlignedBB;
import net.minecraft.server.v1_6_R1.BlockEnderChest;
import net.minecraft.server.v1_6_R1.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_6_R1.TileEntityChest;
import net.minecraft.server.v1_6_R1.TileEntityEnderChest;
import net.minecraft.server.v1_6_R1.World;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R1.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R1.IInventory;
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R1.EntityPlayer;
import net.minecraft.server.v1_6_R1.MinecraftServer;
import net.minecraft.server.v1_6_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_6_R1;
// Volatile
import net.minecraft.server.v1_6_R1.ContainerChest;
import net.minecraft.server.v1_6_R1.EntityHuman;
import net.minecraft.server.v1_6_R1.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_6_R1.EntityPlayer;
import net.minecraft.server.v1_6_R1.IInventory;
import net.minecraft.server.v1_6_R1.InventoryEnderChest;
import net.minecraft.server.v1_6_R1.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R1.ItemStack;
import net.minecraft.server.v1_6_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R2.AxisAlignedBB;
import net.minecraft.server.v1_6_R2.BlockEnderChest;
import net.minecraft.server.v1_6_R2.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_6_R2.TileEntityChest;
import net.minecraft.server.v1_6_R2.TileEntityEnderChest;
import net.minecraft.server.v1_6_R2.World;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R2.IInventory;
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R2.EntityPlayer;
import net.minecraft.server.v1_6_R2.MinecraftServer;
import net.minecraft.server.v1_6_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R2.CraftServer;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_6_R2;
// Volatile
import net.minecraft.server.v1_6_R2.ContainerChest;
import net.minecraft.server.v1_6_R2.EntityHuman;
import net.minecraft.server.v1_6_R2.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_6_R2.EntityPlayer;
import net.minecraft.server.v1_6_R2.IInventory;
import net.minecraft.server.v1_6_R2.InventoryEnderChest;
import net.minecraft.server.v1_6_R2.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R2.ItemStack;
import net.minecraft.server.v1_6_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R3.AxisAlignedBB;
import net.minecraft.server.v1_6_R3.BlockEnderChest;
import net.minecraft.server.v1_6_R3.Container;
@ -36,7 +35,6 @@ import net.minecraft.server.v1_6_R3.TileEntityChest;
import net.minecraft.server.v1_6_R3.TileEntityEnderChest;
import net.minecraft.server.v1_6_R3.World;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -49,7 +47,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -97,7 +95,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R3.IInventory;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;

View file

@ -23,14 +23,15 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.MinecraftServer;
import net.minecraft.server.v1_6_R3.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R3.CraftServer;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_6_R3;
// Volatile
import net.minecraft.server.v1_6_R3.ContainerChest;
import net.minecraft.server.v1_6_R3.EntityHuman;
import net.minecraft.server.v1_6_R3.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.IInventory;
import net.minecraft.server.v1_6_R3.InventoryEnderChest;
import net.minecraft.server.v1_6_R3.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R3.ItemStack;
import net.minecraft.server.v1_6_R3.PlayerInventory;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_7_R1.AxisAlignedBB;
import net.minecraft.server.v1_7_R1.Block;
import net.minecraft.server.v1_7_R1.BlockEnderChest;
@ -37,7 +36,6 @@ import net.minecraft.server.v1_7_R1.TileEntityChest;
import net.minecraft.server.v1_7_R1.TileEntityEnderChest;
import net.minecraft.server.v1_7_R1.World;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -50,7 +48,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -98,7 +96,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R1.IInventory;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;

View file

@ -23,15 +23,16 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R1.EntityPlayer;
import net.minecraft.server.v1_7_R1.MinecraftServer;
import net.minecraft.server.v1_7_R1.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -78,4 +79,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_7_R1;
// Volatile
import net.minecraft.server.v1_7_R1.ContainerChest;
import net.minecraft.server.v1_7_R1.EntityHuman;
import net.minecraft.server.v1_7_R1.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_7_R1.EntityPlayer;
import net.minecraft.server.v1_7_R1.IInventory;
import net.minecraft.server.v1_7_R1.InventoryEnderChest;
import net.minecraft.server.v1_7_R1.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getInventoryName(),
PlayerDataManager.getHandle(player).getEnderChest().k_(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R1.ItemStack;
import net.minecraft.server.v1_7_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_7_R2.AxisAlignedBB;
import net.minecraft.server.v1_7_R2.Block;
import net.minecraft.server.v1_7_R2.BlockEnderChest;
@ -37,7 +36,6 @@ import net.minecraft.server.v1_7_R2.TileEntityChest;
import net.minecraft.server.v1_7_R2.TileEntityEnderChest;
import net.minecraft.server.v1_7_R2.World;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -50,7 +48,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -98,7 +96,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R2.IInventory;
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;

View file

@ -23,15 +23,16 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_7_R2.EntityPlayer;
import net.minecraft.server.v1_7_R2.MinecraftServer;
import net.minecraft.server.v1_7_R2.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
@SuppressWarnings("deprecation") // Deprecated methods are used properly and will not change.
public class PlayerDataManager implements IPlayerDataManager {
@ -79,4 +80,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_7_R2;
// Volatile
import net.minecraft.server.v1_7_R2.ContainerChest;
import net.minecraft.server.v1_7_R2.EntityHuman;
import net.minecraft.server.v1_7_R2.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_7_R2.EntityPlayer;
import net.minecraft.server.v1_7_R2.IInventory;
import net.minecraft.server.v1_7_R2.InventoryEnderChest;
import net.minecraft.server.v1_7_R2.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getInventoryName(),
((CraftPlayer) player).getHandle().getEnderChest().k_(),
((CraftPlayer) player).getHandle().getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R2.ItemStack;
import net.minecraft.server.v1_7_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R3.AxisAlignedBB;
import net.minecraft.server.v1_7_R3.Block;
import net.minecraft.server.v1_7_R3.BlockEnderChest;
@ -37,7 +36,6 @@ import net.minecraft.server.v1_7_R3.TileEntityChest;
import net.minecraft.server.v1_7_R3.TileEntityEnderChest;
import net.minecraft.server.v1_7_R3.World;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -50,7 +48,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -98,7 +96,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R3.IInventory;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;

View file

@ -24,15 +24,16 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R3.EntityPlayer;
import net.minecraft.server.v1_7_R3.MinecraftServer;
import net.minecraft.server.v1_7_R3.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers());
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_7_R3;
// Volatile
import net.minecraft.server.v1_7_R3.ContainerChest;
import net.minecraft.server.v1_7_R3.EntityHuman;
import net.minecraft.server.v1_7_R3.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
// Volatile
import net.minecraft.server.v1_7_R3.EntityPlayer;
import net.minecraft.server.v1_7_R3.IInventory;
import net.minecraft.server.v1_7_R3.InventoryEnderChest;
import net.minecraft.server.v1_7_R3.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getInventoryName(),
PlayerDataManager.getHandle(player).getEnderChest().k_(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R3.ItemStack;
import net.minecraft.server.v1_7_R3.PlayerInventory;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.Block;
import net.minecraft.server.v1_7_R4.BlockEnderChest;
@ -37,7 +36,6 @@ import net.minecraft.server.v1_7_R4.TileEntityChest;
import net.minecraft.server.v1_7_R4.TileEntityEnderChest;
import net.minecraft.server.v1_7_R4.World;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -50,7 +48,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
if (block instanceof BlockEnderChest) {
@ -98,7 +96,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R4.IInventory;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory;

View file

@ -23,15 +23,16 @@ import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R4.EntityPlayer;
import net.minecraft.server.v1_7_R4.MinecraftServer;
import net.minecraft.server.v1_7_R4.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -84,4 +85,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers();
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_7_R4;
// Volatile
import net.minecraft.server.v1_7_R4.ContainerChest;
import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.server.v1_7_R4.IInventory;

View file

@ -27,7 +27,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
//Volatile
import net.minecraft.server.v1_7_R4.EntityPlayer;
import net.minecraft.server.v1_7_R4.IInventory;
import net.minecraft.server.v1_7_R4.InventoryEnderChest;
import net.minecraft.server.v1_7_R4.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner;
private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p;
this.enderChest = player.getHandle().getEnderChest();
this.owner = player;
public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getInventoryName(),
PlayerDataManager.getHandle(player).getEnderChest().k_(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
owner = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R4.ItemStack;
import net.minecraft.server.v1_7_R4.PlayerInventory;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
import net.minecraft.server.v1_8_R1.Block;
import net.minecraft.server.v1_8_R1.BlockChest;
@ -41,7 +40,6 @@ import net.minecraft.server.v1_8_R1.TileEntityChest;
import net.minecraft.server.v1_8_R1.TileEntityEnderChest;
import net.minecraft.server.v1_8_R1.World;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -53,7 +51,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
Block block = world.getType(blockPosition).getBlock();
@ -117,7 +115,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is API-only
if (silentchest && b.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R1.IInventory;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory;

View file

@ -25,14 +25,15 @@ import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R1.EntityPlayer;
import net.minecraft.server.v1_8_R1.MinecraftServer;
import net.minecraft.server.v1_8_R1.PlayerInteractManager;
//Volatile
import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers();
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_8_R1;
//Volatile
import net.minecraft.server.v1_8_R1.ContainerChest;
import net.minecraft.server.v1_8_R1.EntityHuman;
import net.minecraft.server.v1_8_R1.IInventory;

View file

@ -23,12 +23,11 @@ import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
//Volatile
import net.minecraft.server.v1_8_R1.EntityPlayer;
import net.minecraft.server.v1_8_R1.IInventory;
import net.minecraft.server.v1_8_R1.InventoryEnderChest;
import net.minecraft.server.v1_8_R1.InventorySubcontainer;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -38,12 +37,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player;
this.enderChest = craftPlayer.getHandle().getEnderChest();
this.bukkitOwner = craftPlayer;
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -56,9 +55,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
this.bukkitOwner = player;
CraftPlayer craftPlayer = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
//Volatile
import net.minecraft.server.v1_8_R1.ItemStack;
import net.minecraft.server.v1_8_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
import net.minecraft.server.v1_8_R2.Block;
import net.minecraft.server.v1_8_R2.BlockChest;
@ -43,7 +42,6 @@ import net.minecraft.server.v1_8_R2.TileEntityChest;
import net.minecraft.server.v1_8_R2.TileEntityEnderChest;
import net.minecraft.server.v1_8_R2.World;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -55,7 +53,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
Block block = world.getType(blockPosition).getBlock();
@ -114,7 +112,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is pretty much API-only
if (silentchest && b.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R2.IInventory;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;

View file

@ -25,14 +25,15 @@ import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_8_R2.CraftServer;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers();
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_8_R2;
// Volatile
import net.minecraft.server.v1_8_R2.ContainerChest;
import net.minecraft.server.v1_8_R2.EntityHuman;
import net.minecraft.server.v1_8_R2.IInventory;

View file

@ -23,12 +23,11 @@ import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.IInventory;
import net.minecraft.server.v1_8_R2.InventoryEnderChest;
import net.minecraft.server.v1_8_R2.InventorySubcontainer;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -38,12 +37,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player;
this.enderChest = craftPlayer.getHandle().getEnderChest();
this.bukkitOwner = craftPlayer;
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize());
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents();
}
@ -56,9 +55,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) {
if (!playerOnline) {
try {
this.bukkitOwner = player;
CraftPlayer craftPlayer = (CraftPlayer) player;
InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest();
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true);
field.set(playerEnderChest, this.items);

View file

@ -21,11 +21,9 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R2.ItemStack;
import net.minecraft.server.v1_8_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle());
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = player.inventory.items;
this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override
public void setPlayerOnline(Player player) {
if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle();
this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor;
playerOnline = true;

View file

@ -22,7 +22,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
import net.minecraft.server.v1_8_R3.Block;
import net.minecraft.server.v1_8_R3.BlockChest;
@ -43,7 +42,6 @@ import net.minecraft.server.v1_8_R3.TileEntityChest;
import net.minecraft.server.v1_8_R3.TileEntityEnderChest;
import net.minecraft.server.v1_8_R3.World;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
@ -55,7 +53,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
Block block = world.getType(blockPosition).getBlock();
@ -114,7 +112,7 @@ public class AnySilentContainer implements IAnySilentContainer {
@Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
EntityPlayer player = ((CraftPlayer) p).getHandle();
EntityPlayer player = PlayerDataManager.getHandle(p);
// Silent ender chest is pretty much API-only
if (silentchest && b.getType() == Material.ENDER_CHEST) {

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R3.IInventory;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;

View file

@ -25,14 +25,15 @@ import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.PlayerInteractManager;
//Volatile
import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers();
}
public static EntityPlayer getHandle(Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
}

View file

@ -16,7 +16,6 @@
package com.lishid.openinv.internal.v1_8_R3;
// Volatile
import net.minecraft.server.v1_8_R3.ContainerChest;
import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.IInventory;

Some files were not shown because too many files have changed in this diff Show more