diff --git a/src/lishid/openinv/OpenInv.java b/src/lishid/openinv/OpenInv.java index e542fde..da8d092 100644 --- a/src/lishid/openinv/OpenInv.java +++ b/src/lishid/openinv/OpenInv.java @@ -6,6 +6,7 @@ import lishid.openinv.utils.PlayerInventoryChest; import net.minecraft.server.ContainerPlayer; import net.minecraft.server.EntityPlayer; +import net.minecraft.server.ICrafting; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.event.Event; @@ -24,6 +25,7 @@ import org.bukkit.plugin.Plugin; public class OpenInv extends JavaPlugin { private final OpenInvPlayerListener playerListener = new OpenInvPlayerListener(this); private final OpenInvEntityListener entityListener = new OpenInvEntityListener(this); + //private final OpenInvInventoryListener inventoryListener = new OpenInvInventoryListener(this); public static PermissionHandler permissionHandler; public void onDisable() { } @@ -47,10 +49,11 @@ public class OpenInv extends JavaPlugin { //pm.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this); + //pm.registerEvent(Event.Type.INVENTORY_CLOSE, inventoryListener, Event.Priority.Normal, this); setupPermissions(); - // EXAMPLE: Custom code, here we just output some info so we can check all is well + PluginDescriptionFile pdfFile = this.getDescription(); - System.out.println("[" + pdfFile.getName() + "] version " + pdfFile.getVersion() + " is enabled!" ); + System.out.println("[" + pdfFile.getName() + "] version " + pdfFile.getVersion() + " enabled!" ); getCommand("openinv").setExecutor(new OpenInvPluginCommand(this)); getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this)); @@ -59,11 +62,19 @@ public class OpenInv extends JavaPlugin { public static void ReplaceInv(CraftPlayer player) { - EntityPlayer entityplayer = player.getHandle(); - entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory); - entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic); - entityplayer.activeContainer = entityplayer.defaultContainer; - player.setHandle(entityplayer); + try{ + EntityPlayer entityplayer = player.getHandle(); + entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory); + entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic); + entityplayer.activeContainer = entityplayer.defaultContainer; + //sync + ((ICrafting)entityplayer).a(entityplayer.activeContainer, entityplayer.activeContainer.b()); + entityplayer.activeContainer.a(); + + player.setHandle(entityplayer); + } + catch(Exception e) + {} } diff --git a/src/lishid/openinv/commands/OpenInvPluginCommand.java b/src/lishid/openinv/commands/OpenInvPluginCommand.java index d9caa5a..56a1e31 100644 --- a/src/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/lishid/openinv/commands/OpenInvPluginCommand.java @@ -19,6 +19,7 @@ import org.bukkit.entity.Player; public class OpenInvPluginCommand implements CommandExecutor { private final OpenInv plugin; + public static HashMap offlineInv = new HashMap(); public static HashMap theOpenInvHistory = new HashMap(); public OpenInvPluginCommand(OpenInv plugin) { this.plugin = plugin; @@ -30,6 +31,7 @@ public class OpenInvPluginCommand implements CommandExecutor { return true; } + //boolean Offline = false; Player player = (Player)sender; OpenInvHistory history = theOpenInvHistory.get(player); @@ -60,13 +62,11 @@ public class OpenInvPluginCommand implements CommandExecutor { if(history.lastPlayer != null) { target = this.plugin.getServer().getPlayer(history.lastPlayer); - //EntityPlayer entply = new EntityPlayer(((CraftServer)this.plugin.getServer()).getServer(), ((CraftPlayer)player).getHandle().world, "", null); - //CraftPlayer ply = new CraftPlayer((CraftServer) this.plugin.getServer(), null); } else { - sender.sendMessage("OpenInv history is empty!"); - return false; + sender.sendMessage(ChatColor.RED + "OpenInv history is empty!"); + return true; } } else @@ -77,19 +77,44 @@ public class OpenInvPluginCommand implements CommandExecutor { if(target == null) { - sender.sendMessage("Player not found!"); - return false; + //Offline inv here... + /*try{ + MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer(); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), args[0], new ItemInWorldManager(server.getWorldServer(0))); + target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if(target != null) + { + Offline = true; + target.loadData(); + } + else + { + sender.sendMessage(ChatColor.RED + "Player not found!"); + return false; + } + } catch(Exception e) + {*/ + //sender.sendMessage("Error while retrieving offline player data!"); + sender.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found!"); + return true; + /*}*/ } if(target == player) { - sender.sendMessage("Cannot target yourself!"); - return false; + sender.sendMessage(ChatColor.RED + "Cannot OpenInv yourself!"); + return true; } if (!PermissionRelay.hasPermission(player, "OpenInv.override") && PermissionRelay.hasPermission(target, "OpenInv.exempt")) { sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!"); return true; } + + if((!PermissionRelay.hasPermission(player, "OpenInv.crossworld") && !PermissionRelay.hasPermission(player, "OpenInv.override")) && + target.getWorld() != player.getWorld()){ + sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!"); + return true; + } history.lastPlayer = target.getName(); @@ -103,7 +128,12 @@ public class OpenInvPluginCommand implements CommandExecutor { { OpenInv.ReplaceInv((CraftPlayer) target); } - + /* + if(Offline && entitytarget.inventory instanceof PlayerInventoryChest) + { + offlineInv.put(target, (PlayerInventoryChest) entitytarget.inventory); + } + */ entityplayer.a(entitytarget.inventory); return true; diff --git a/src/lishid/openinv/utils/PlayerInventoryChest.java b/src/lishid/openinv/utils/PlayerInventoryChest.java index 1e5b11d..f199445 100644 --- a/src/lishid/openinv/utils/PlayerInventoryChest.java +++ b/src/lishid/openinv/utils/PlayerInventoryChest.java @@ -20,7 +20,7 @@ public class PlayerInventoryChest extends InventoryPlayer @Override public String getName() { - return ((EntityPlayer)this.d).displayName; + return ((EntityPlayer)this.d).displayName + " (" + this.itemInHandIndex + ")"; } @Override diff --git a/src/plugin.yml b/src/plugin.yml index ef950ff..7c738b3 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: lishid.openinv.OpenInv -version: 1.3.1 +version: 1.3.3 author: lishid description: > This plugin allows you to open another player's inventory as a chest