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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_5.IInventory; import net.minecraft.server.v1_4_5.IInventory;
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_4_5.EntityPlayer; import net.minecraft.server.v1_4_5.EntityPlayer;
import net.minecraft.server.v1_4_5.ItemInWorldManager; import net.minecraft.server.v1_4_5.ItemInWorldManager;
import net.minecraft.server.v1_4_5.MinecraftServer; import net.minecraft.server.v1_4_5.MinecraftServer;
import org.bukkit.craftbukkit.v1_4_5.CraftServer; import org.bukkit.craftbukkit.v1_4_5.CraftServer;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_4_5;
// Volatile
import net.minecraft.server.v1_4_5.ContainerChest; import net.minecraft.server.v1_4_5.ContainerChest;
import net.minecraft.server.v1_4_5.EntityHuman; import net.minecraft.server.v1_4_5.EntityHuman;
import net.minecraft.server.v1_4_5.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_4_5.InventoryEnderChest; import net.minecraft.server.v1_4_5.InventoryEnderChest;
import net.minecraft.server.v1_4_5.InventorySubcontainer; import net.minecraft.server.v1_4_5.InventorySubcontainer;
@ -46,12 +46,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); ((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -64,8 +64,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_5.ItemStack; import net.minecraft.server.v1_4_5.ItemStack;
import net.minecraft.server.v1_4_5.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_6.IInventory; import net.minecraft.server.v1_4_6.IInventory;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_4_6.EntityPlayer; import net.minecraft.server.v1_4_6.EntityPlayer;
import net.minecraft.server.v1_4_6.MinecraftServer; import net.minecraft.server.v1_4_6.MinecraftServer;
import net.minecraft.server.v1_4_6.PlayerInteractManager; import net.minecraft.server.v1_4_6.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_4_6.CraftServer; import org.bukkit.craftbukkit.v1_4_6.CraftServer;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_4_6;
// Volatile
import net.minecraft.server.v1_4_6.ContainerChest; import net.minecraft.server.v1_4_6.ContainerChest;
import net.minecraft.server.v1_4_6.EntityHuman; import net.minecraft.server.v1_4_6.EntityHuman;
import net.minecraft.server.v1_4_6.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_4_6.InventoryEnderChest; import net.minecraft.server.v1_4_6.InventoryEnderChest;
import net.minecraft.server.v1_4_6.InventorySubcontainer; import net.minecraft.server.v1_4_6.InventorySubcontainer;
@ -46,12 +46,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); ((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -64,8 +64,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_6.ItemStack; import net.minecraft.server.v1_4_6.ItemStack;
import net.minecraft.server.v1_4_6.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_10_R1.IInventory; import net.minecraft.server.v1_10_R1.IInventory;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.MinecraftServer; import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.PlayerInteractManager; import net.minecraft.server.v1_10_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer; import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers(); 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; package com.lishid.openinv.internal.v1_10_R1;
// Volatile
import net.minecraft.server.v1_10_R1.ContainerChest; import net.minecraft.server.v1_10_R1.ContainerChest;
import net.minecraft.server.v1_10_R1.EntityHuman; import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.IInventory; 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.entity.Player;
import org.bukkit.inventory.Inventory; 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.IInventory;
import net.minecraft.server.v1_10_R1.InventoryEnderChest; import net.minecraft.server.v1_10_R1.InventoryEnderChest;
import net.minecraft.server.v1_10_R1.InventorySubcontainer; import net.minecraft.server.v1_10_R1.InventorySubcontainer;
import net.minecraft.server.v1_10_R1.ItemStack; 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; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -40,12 +39,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = craftPlayer.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = craftPlayer; this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemArrays(this, enderChest.getContents()); setItemArrays(this, enderChest.getContents());
} }
@ -78,9 +77,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
this.bukkitOwner = player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
CraftPlayer craftPlayer = (CraftPlayer) player; this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items); setItemArrays(nmsPlayer.getEnderChest(), this.items);
} catch (Exception e) {} } catch (Exception e) {}
playerOnline = true; playerOnline = true;
} }

View file

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

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_11_R1.IInventory; import net.minecraft.server.v1_11_R1.IInventory;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_11_R1.EntityPlayer; import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.MinecraftServer; import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.PlayerInteractManager; import net.minecraft.server.v1_11_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer; import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers(); 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; package com.lishid.openinv.internal.v1_11_R1;
// Volatile
import net.minecraft.server.v1_11_R1.ContainerChest; import net.minecraft.server.v1_11_R1.ContainerChest;
import net.minecraft.server.v1_11_R1.EntityHuman; import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory; 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.entity.Player;
import org.bukkit.inventory.Inventory; 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.IInventory;
import net.minecraft.server.v1_11_R1.InventoryEnderChest; import net.minecraft.server.v1_11_R1.InventoryEnderChest;
import net.minecraft.server.v1_11_R1.InventorySubcontainer; import net.minecraft.server.v1_11_R1.InventorySubcontainer;
import net.minecraft.server.v1_11_R1.ItemStack; 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; import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -41,12 +40,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = craftPlayer.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = craftPlayer; this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemLists(this, enderChest.getContents()); setItemLists(this, enderChest.getContents());
} }
@ -79,9 +78,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
this.bukkitOwner = player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
CraftPlayer craftPlayer = (CraftPlayer) player; this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemLists(craftPlayer.getHandle().getEnderChest(), this.items); setItemLists(nmsPlayer.getEnderChest(), this.items);
} catch (Exception e) {} } catch (Exception e) {}
playerOnline = true; playerOnline = true;
} }

View file

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

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_R1.IInventory; import net.minecraft.server.v1_4_R1.IInventory;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_R1.EntityPlayer; import net.minecraft.server.v1_4_R1.EntityPlayer;
import net.minecraft.server.v1_4_R1.MinecraftServer; import net.minecraft.server.v1_4_R1.MinecraftServer;
import net.minecraft.server.v1_4_R1.PlayerInteractManager; import net.minecraft.server.v1_4_R1.PlayerInteractManager;
// Volatile
import org.bukkit.craftbukkit.v1_4_R1.CraftServer; import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -78,4 +79,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_4_R1;
// Volatile
import net.minecraft.server.v1_4_R1.ContainerChest; import net.minecraft.server.v1_4_R1.ContainerChest;
import net.minecraft.server.v1_4_R1.EntityHuman; import net.minecraft.server.v1_4_R1.EntityHuman;
import net.minecraft.server.v1_4_R1.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_4_R1.InventoryEnderChest; import net.minecraft.server.v1_4_R1.InventoryEnderChest;
import net.minecraft.server.v1_4_R1.InventorySubcontainer; import net.minecraft.server.v1_4_R1.InventorySubcontainer;
@ -46,12 +46,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -64,8 +64,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_4_R1.ItemStack; import net.minecraft.server.v1_4_R1.ItemStack;
import net.minecraft.server.v1_4_R1.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R2.IInventory; import net.minecraft.server.v1_5_R2.IInventory;
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_5_R2.EntityPlayer; import net.minecraft.server.v1_5_R2.EntityPlayer;
import net.minecraft.server.v1_5_R2.MinecraftServer; import net.minecraft.server.v1_5_R2.MinecraftServer;
import net.minecraft.server.v1_5_R2.PlayerInteractManager; import net.minecraft.server.v1_5_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_5_R2.CraftServer; import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_5_R2;
// Volatile
import net.minecraft.server.v1_5_R2.ContainerChest; import net.minecraft.server.v1_5_R2.ContainerChest;
import net.minecraft.server.v1_5_R2.EntityHuman; import net.minecraft.server.v1_5_R2.EntityHuman;
import net.minecraft.server.v1_5_R2.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_5_R2.InventoryEnderChest; import net.minecraft.server.v1_5_R2.InventoryEnderChest;
import net.minecraft.server.v1_5_R2.InventorySubcontainer; import net.minecraft.server.v1_5_R2.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R2.ItemStack; import net.minecraft.server.v1_5_R2.ItemStack;
import net.minecraft.server.v1_5_R2.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R3.IInventory; import net.minecraft.server.v1_5_R3.IInventory;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_5_R3.EntityPlayer; import net.minecraft.server.v1_5_R3.EntityPlayer;
import net.minecraft.server.v1_5_R3.MinecraftServer; import net.minecraft.server.v1_5_R3.MinecraftServer;
import net.minecraft.server.v1_5_R3.PlayerInteractManager; import net.minecraft.server.v1_5_R3.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_5_R3.CraftServer; import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_5_R3;
// Volatile
import net.minecraft.server.v1_5_R3.ContainerChest; import net.minecraft.server.v1_5_R3.ContainerChest;
import net.minecraft.server.v1_5_R3.EntityHuman; import net.minecraft.server.v1_5_R3.EntityHuman;
import net.minecraft.server.v1_5_R3.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_5_R3.InventoryEnderChest; import net.minecraft.server.v1_5_R3.InventoryEnderChest;
import net.minecraft.server.v1_5_R3.InventorySubcontainer; import net.minecraft.server.v1_5_R3.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_5_R3.ItemStack; import net.minecraft.server.v1_5_R3.ItemStack;
import net.minecraft.server.v1_5_R3.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R1.IInventory; import net.minecraft.server.v1_6_R1.IInventory;
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R1.EntityPlayer; import net.minecraft.server.v1_6_R1.EntityPlayer;
import net.minecraft.server.v1_6_R1.MinecraftServer; import net.minecraft.server.v1_6_R1.MinecraftServer;
import net.minecraft.server.v1_6_R1.PlayerInteractManager; import net.minecraft.server.v1_6_R1.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R1.CraftServer; import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_6_R1;
// Volatile
import net.minecraft.server.v1_6_R1.ContainerChest; import net.minecraft.server.v1_6_R1.ContainerChest;
import net.minecraft.server.v1_6_R1.EntityHuman; import net.minecraft.server.v1_6_R1.EntityHuman;
import net.minecraft.server.v1_6_R1.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_6_R1.InventoryEnderChest; import net.minecraft.server.v1_6_R1.InventoryEnderChest;
import net.minecraft.server.v1_6_R1.InventorySubcontainer; import net.minecraft.server.v1_6_R1.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R1.ItemStack; import net.minecraft.server.v1_6_R1.ItemStack;
import net.minecraft.server.v1_6_R1.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R2.IInventory; import net.minecraft.server.v1_6_R2.IInventory;
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R2.EntityPlayer; import net.minecraft.server.v1_6_R2.EntityPlayer;
import net.minecraft.server.v1_6_R2.MinecraftServer; import net.minecraft.server.v1_6_R2.MinecraftServer;
import net.minecraft.server.v1_6_R2.PlayerInteractManager; import net.minecraft.server.v1_6_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R2.CraftServer; import org.bukkit.craftbukkit.v1_6_R2.CraftServer;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_6_R2;
// Volatile
import net.minecraft.server.v1_6_R2.ContainerChest; import net.minecraft.server.v1_6_R2.ContainerChest;
import net.minecraft.server.v1_6_R2.EntityHuman; import net.minecraft.server.v1_6_R2.EntityHuman;
import net.minecraft.server.v1_6_R2.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_6_R2.InventoryEnderChest; import net.minecraft.server.v1_6_R2.InventoryEnderChest;
import net.minecraft.server.v1_6_R2.InventorySubcontainer; import net.minecraft.server.v1_6_R2.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R2.ItemStack; import net.minecraft.server.v1_6_R2.ItemStack;
import net.minecraft.server.v1_6_R2.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R3.IInventory; import net.minecraft.server.v1_6_R3.IInventory;
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_6_R3.EntityPlayer; import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.MinecraftServer; import net.minecraft.server.v1_6_R3.MinecraftServer;
import net.minecraft.server.v1_6_R3.PlayerInteractManager; import net.minecraft.server.v1_6_R3.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_6_R3.CraftServer; import org.bukkit.craftbukkit.v1_6_R3.CraftServer;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -77,4 +78,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_6_R3;
// Volatile
import net.minecraft.server.v1_6_R3.ContainerChest; import net.minecraft.server.v1_6_R3.ContainerChest;
import net.minecraft.server.v1_6_R3.EntityHuman; import net.minecraft.server.v1_6_R3.EntityHuman;
import net.minecraft.server.v1_6_R3.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_6_R3.InventoryEnderChest; import net.minecraft.server.v1_6_R3.InventoryEnderChest;
import net.minecraft.server.v1_6_R3.InventorySubcontainer; import net.minecraft.server.v1_6_R3.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) p).getHandle().getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_6_R3.ItemStack; import net.minecraft.server.v1_6_R3.ItemStack;
import net.minecraft.server.v1_6_R3.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R1.IInventory; import net.minecraft.server.v1_7_R1.IInventory;
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R1.EntityPlayer; import net.minecraft.server.v1_7_R1.EntityPlayer;
import net.minecraft.server.v1_7_R1.MinecraftServer; import net.minecraft.server.v1_7_R1.MinecraftServer;
import net.minecraft.server.v1_7_R1.PlayerInteractManager; import net.minecraft.server.v1_7_R1.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -78,4 +79,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_7_R1;
// Volatile
import net.minecraft.server.v1_7_R1.ContainerChest; import net.minecraft.server.v1_7_R1.ContainerChest;
import net.minecraft.server.v1_7_R1.EntityHuman; import net.minecraft.server.v1_7_R1.EntityHuman;
import net.minecraft.server.v1_7_R1.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_7_R1.InventoryEnderChest; import net.minecraft.server.v1_7_R1.InventoryEnderChest;
import net.minecraft.server.v1_7_R1.InventorySubcontainer; import net.minecraft.server.v1_7_R1.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), super(PlayerDataManager.getHandle(player).getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(), PlayerDataManager.getHandle(player).getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R1.ItemStack; import net.minecraft.server.v1_7_R1.ItemStack;
import net.minecraft.server.v1_7_R1.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R2.IInventory; import net.minecraft.server.v1_7_R2.IInventory;
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
//Volatile
import net.minecraft.server.v1_7_R2.EntityPlayer; import net.minecraft.server.v1_7_R2.EntityPlayer;
import net.minecraft.server.v1_7_R2.MinecraftServer; import net.minecraft.server.v1_7_R2.MinecraftServer;
import net.minecraft.server.v1_7_R2.PlayerInteractManager; import net.minecraft.server.v1_7_R2.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R2.CraftServer; 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. @SuppressWarnings("deprecation") // Deprecated methods are used properly and will not change.
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -79,4 +80,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_7_R2;
// Volatile
import net.minecraft.server.v1_7_R2.ContainerChest; import net.minecraft.server.v1_7_R2.ContainerChest;
import net.minecraft.server.v1_7_R2.EntityHuman; import net.minecraft.server.v1_7_R2.EntityHuman;
import net.minecraft.server.v1_7_R2.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_7_R2.InventoryEnderChest; import net.minecraft.server.v1_7_R2.InventoryEnderChest;
import net.minecraft.server.v1_7_R2.InventorySubcontainer; import net.minecraft.server.v1_7_R2.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), super(((CraftPlayer) player).getHandle().getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) player).getHandle().getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); ((CraftPlayer) player).getHandle().getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R2.ItemStack; import net.minecraft.server.v1_7_R2.ItemStack;
import net.minecraft.server.v1_7_R2.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R3.IInventory; import net.minecraft.server.v1_7_R3.IInventory;
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R3.EntityPlayer; import net.minecraft.server.v1_7_R3.EntityPlayer;
import net.minecraft.server.v1_7_R3.MinecraftServer; import net.minecraft.server.v1_7_R3.MinecraftServer;
import net.minecraft.server.v1_7_R3.PlayerInteractManager; import net.minecraft.server.v1_7_R3.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R3.CraftServer; import org.bukkit.craftbukkit.v1_7_R3.CraftServer;
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Arrays.asList(Bukkit.getOnlinePlayers()); 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; package com.lishid.openinv.internal.v1_7_R3;
// Volatile
import net.minecraft.server.v1_7_R3.ContainerChest; import net.minecraft.server.v1_7_R3.ContainerChest;
import net.minecraft.server.v1_7_R3.EntityHuman; import net.minecraft.server.v1_7_R3.EntityHuman;
import net.minecraft.server.v1_7_R3.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_7_R3.InventoryEnderChest; import net.minecraft.server.v1_7_R3.InventoryEnderChest;
import net.minecraft.server.v1_7_R3.InventorySubcontainer; import net.minecraft.server.v1_7_R3.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), super(PlayerDataManager.getHandle(player).getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(), PlayerDataManager.getHandle(player).getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R3.ItemStack; import net.minecraft.server.v1_7_R3.ItemStack;
import net.minecraft.server.v1_7_R3.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R4.IInventory; import net.minecraft.server.v1_7_R4.IInventory;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_7_R4.EntityPlayer; import net.minecraft.server.v1_7_R4.EntityPlayer;
import net.minecraft.server.v1_7_R4.MinecraftServer; import net.minecraft.server.v1_7_R4.MinecraftServer;
import net.minecraft.server.v1_7_R4.PlayerInteractManager; import net.minecraft.server.v1_7_R4.PlayerInteractManager;
import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.craftbukkit.v1_7_R4.CraftServer; import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -84,4 +85,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers(); 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; package com.lishid.openinv.internal.v1_7_R4;
// Volatile
import net.minecraft.server.v1_7_R4.ContainerChest; import net.minecraft.server.v1_7_R4.ContainerChest;
import net.minecraft.server.v1_7_R4.EntityHuman; import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.server.v1_7_R4.IInventory; 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.Inventory;
import org.bukkit.inventory.InventoryHolder; 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.IInventory;
import net.minecraft.server.v1_7_R4.InventoryEnderChest; import net.minecraft.server.v1_7_R4.InventoryEnderChest;
import net.minecraft.server.v1_7_R4.InventorySubcontainer; import net.minecraft.server.v1_7_R4.InventorySubcontainer;
@ -46,13 +46,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player p, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), super(PlayerDataManager.getHandle(player).getEnderChest().getInventoryName(),
((CraftPlayer) p).getHandle().getEnderChest().k_(), PlayerDataManager.getHandle(player).getEnderChest().k_(),
((CraftPlayer) p).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer player = (CraftPlayer) p; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = player.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = player; this.owner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -65,8 +65,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
owner = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); this.owner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_7_R4.ItemStack; import net.minecraft.server.v1_7_R4.ItemStack;
import net.minecraft.server.v1_7_R4.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R1.IInventory; import net.minecraft.server.v1_8_R1.IInventory;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R1.EntityPlayer; import net.minecraft.server.v1_8_R1.EntityPlayer;
import net.minecraft.server.v1_8_R1.MinecraftServer; import net.minecraft.server.v1_8_R1.MinecraftServer;
import net.minecraft.server.v1_8_R1.PlayerInteractManager; import net.minecraft.server.v1_8_R1.PlayerInteractManager;
//Volatile
import org.bukkit.craftbukkit.v1_8_R1.CraftServer; import org.bukkit.craftbukkit.v1_8_R1.CraftServer;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers(); 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; package com.lishid.openinv.internal.v1_8_R1;
//Volatile
import net.minecraft.server.v1_8_R1.ContainerChest; import net.minecraft.server.v1_8_R1.ContainerChest;
import net.minecraft.server.v1_8_R1.EntityHuman; import net.minecraft.server.v1_8_R1.EntityHuman;
import net.minecraft.server.v1_8_R1.IInventory; 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.entity.Player;
import org.bukkit.inventory.Inventory; 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.IInventory;
import net.minecraft.server.v1_8_R1.InventoryEnderChest; import net.minecraft.server.v1_8_R1.InventoryEnderChest;
import net.minecraft.server.v1_8_R1.InventorySubcontainer; 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; import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -38,12 +37,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = craftPlayer.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = craftPlayer; this.bukkitOwner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -56,9 +55,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
this.bukkitOwner = player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
CraftPlayer craftPlayer = (CraftPlayer) player; this.bukkitOwner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest(); InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
//Volatile
import net.minecraft.server.v1_8_R1.ItemStack; import net.minecraft.server.v1_8_R1.ItemStack;
import net.minecraft.server.v1_8_R1.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R2.IInventory; import net.minecraft.server.v1_8_R2.IInventory;
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
// Volatile
import net.minecraft.server.v1_8_R2.EntityPlayer; import net.minecraft.server.v1_8_R2.EntityPlayer;
import net.minecraft.server.v1_8_R2.MinecraftServer; import net.minecraft.server.v1_8_R2.MinecraftServer;
import net.minecraft.server.v1_8_R2.PlayerInteractManager; import net.minecraft.server.v1_8_R2.PlayerInteractManager;
import org.bukkit.craftbukkit.v1_8_R2.CraftServer; import org.bukkit.craftbukkit.v1_8_R2.CraftServer;
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers(); 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; package com.lishid.openinv.internal.v1_8_R2;
// Volatile
import net.minecraft.server.v1_8_R2.ContainerChest; import net.minecraft.server.v1_8_R2.ContainerChest;
import net.minecraft.server.v1_8_R2.EntityHuman; import net.minecraft.server.v1_8_R2.EntityHuman;
import net.minecraft.server.v1_8_R2.IInventory; 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.entity.Player;
import org.bukkit.inventory.Inventory; 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.IInventory;
import net.minecraft.server.v1_8_R2.InventoryEnderChest; import net.minecraft.server.v1_8_R2.InventoryEnderChest;
import net.minecraft.server.v1_8_R2.InventorySubcontainer; 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; import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
@ -38,12 +37,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
CraftPlayer craftPlayer = (CraftPlayer) player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = craftPlayer.getHandle().getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = craftPlayer; this.bukkitOwner = nmsPlayer.getBukkitEntity();
this.items = enderChest.getContents(); this.items = enderChest.getContents();
} }
@ -56,9 +55,9 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
this.bukkitOwner = player; EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
CraftPlayer craftPlayer = (CraftPlayer) player; this.bukkitOwner = nmsPlayer.getBukkitEntity();
InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest(); InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); 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.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_8_R2.ItemStack;
import net.minecraft.server.v1_8_R2.PlayerInventory; 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; import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
@ -35,7 +33,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
private boolean playerOnline = false; private boolean playerOnline = false;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(((CraftPlayer) bukkitPlayer).getHandle()); super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online; this.playerOnline = online;
this.items = player.inventory.items; this.items = player.inventory.items;
this.armor = player.inventory.armor; this.armor = player.inventory.armor;
@ -49,7 +47,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = ((CraftPlayer) player).getHandle(); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;
this.player.inventory.armor = this.armor; this.player.inventory.armor = this.armor;
playerOnline = true; playerOnline = true;

View file

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

View file

@ -23,7 +23,6 @@ import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
// Volatile
import net.minecraft.server.v1_8_R3.IInventory; import net.minecraft.server.v1_8_R3.IInventory;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; 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.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.EntityPlayer;
import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.MinecraftServer;
import net.minecraft.server.v1_8_R3.PlayerInteractManager; import net.minecraft.server.v1_8_R3.PlayerInteractManager;
//Volatile
import org.bukkit.craftbukkit.v1_8_R3.CraftServer; import org.bukkit.craftbukkit.v1_8_R3.CraftServer;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@ -85,4 +86,24 @@ public class PlayerDataManager implements IPlayerDataManager {
return Bukkit.getOnlinePlayers(); 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; package com.lishid.openinv.internal.v1_8_R3;
// Volatile
import net.minecraft.server.v1_8_R3.ContainerChest; import net.minecraft.server.v1_8_R3.ContainerChest;
import net.minecraft.server.v1_8_R3.EntityHuman; import net.minecraft.server.v1_8_R3.EntityHuman;
import net.minecraft.server.v1_8_R3.IInventory; import net.minecraft.server.v1_8_R3.IInventory;

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