From bc558ff6912f07909301b998e74fb6a367890716 Mon Sep 17 00:00:00 2001 From: lishid Date: Fri, 10 Aug 2012 13:36:36 -0400 Subject: [PATCH] Added /openender and read-only inventories. --- src/lishid/openinv/OpenInv.java | 12 +- src/lishid/openinv/OpenInvEntityListener.java | 7 - .../openinv/OpenInvInventoryListener.java | 52 ++++++ src/lishid/openinv/OpenInvPlayerListener.java | 35 ++-- src/lishid/openinv/Permissions.java | 15 ++ .../commands/AnyChestPluginCommand.java | 3 +- .../commands/OpenEnderPluginCommand.java | 170 ++++++++++++++++++ .../commands/OpenInvPluginCommand.java | 9 +- .../commands/SearchInvPluginCommand.java | 3 +- .../commands/SilentChestPluginCommand.java | 3 +- .../commands/ToggleOpenInvPluginCommand.java | 3 +- .../openinv/utils/OpenInvEnderChest.java | 140 +++++++++++++++ .../openinv/utils/OpenInvPlayerInventory.java | 1 + src/plugin.yml | 7 +- 14 files changed, 424 insertions(+), 36 deletions(-) create mode 100644 src/lishid/openinv/OpenInvInventoryListener.java create mode 100644 src/lishid/openinv/Permissions.java create mode 100644 src/lishid/openinv/commands/OpenEnderPluginCommand.java create mode 100644 src/lishid/openinv/utils/OpenInvEnderChest.java diff --git a/src/lishid/openinv/OpenInv.java b/src/lishid/openinv/OpenInv.java index bf615fd..ac0b359 100644 --- a/src/lishid/openinv/OpenInv.java +++ b/src/lishid/openinv/OpenInv.java @@ -20,6 +20,7 @@ import java.util.HashMap; import lishid.openinv.commands.*; import lishid.openinv.utils.Metrics; +import lishid.openinv.utils.OpenInvEnderChest; import lishid.openinv.utils.OpenInvPlayerInventory; import org.bukkit.ChatColor; @@ -35,9 +36,8 @@ import org.bukkit.plugin.java.JavaPlugin; */ public class OpenInv extends JavaPlugin { - private final OpenInvPlayerListener playerListener = new OpenInvPlayerListener(this); - private final OpenInvEntityListener entityListener = new OpenInvEntityListener(this); public static HashMap inventories = new HashMap(); + public static HashMap enderChests = new HashMap(); public static OpenInv mainPlugin; private static Metrics metrics; @@ -55,14 +55,16 @@ public class OpenInv extends JavaPlugin mainPlugin.saveConfig(); PluginManager pm = getServer().getPluginManager(); - pm.registerEvents(playerListener, this); - pm.registerEvents(entityListener, this); + pm.registerEvents(new OpenInvPlayerListener(), this); + pm.registerEvents(new OpenInvEntityListener(), this); + pm.registerEvents(new OpenInvInventoryListener(), this); getCommand("openinv").setExecutor(new OpenInvPluginCommand(this)); getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this)); getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand()); getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this)); getCommand("anychest").setExecutor(new AnyChestPluginCommand(this)); + getCommand("openender").setExecutor(new OpenEnderPluginCommand(this)); // Metrics try @@ -145,6 +147,8 @@ public class OpenInv extends JavaPlugin { player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory"); player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); + player.sendMessage(ChatColor.GREEN + "/openender - Open a player's enderchest"); + player.sendMessage(ChatColor.GREEN + " (aliases: oe, enderchest)"); player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle item openinv function"); player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)"); player.sendMessage(ChatColor.GREEN + "/searchinv [MinAmount] - "); diff --git a/src/lishid/openinv/OpenInvEntityListener.java b/src/lishid/openinv/OpenInvEntityListener.java index b5634a8..4fb3e7b 100644 --- a/src/lishid/openinv/OpenInvEntityListener.java +++ b/src/lishid/openinv/OpenInvEntityListener.java @@ -26,13 +26,6 @@ import org.bukkit.event.Listener; public class OpenInvEntityListener implements Listener { - OpenInv plugin; - - public OpenInvEntityListener(OpenInv scrap) - { - plugin = scrap; - } - @EventHandler(priority = EventPriority.LOWEST) public void onEntityDamage(EntityDamageEvent event) { diff --git a/src/lishid/openinv/OpenInvInventoryListener.java b/src/lishid/openinv/OpenInvInventoryListener.java new file mode 100644 index 0000000..a7d974d --- /dev/null +++ b/src/lishid/openinv/OpenInvInventoryListener.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011-2012 lishid. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package lishid.openinv; + +import lishid.openinv.utils.OpenInvEnderChest; +import lishid.openinv.utils.OpenInvPlayerInventory; +import net.minecraft.server.IInventory; + +import org.bukkit.craftbukkit.inventory.CraftInventory; +import org.bukkit.entity.HumanEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; + +public class OpenInvInventoryListener implements Listener +{ + @EventHandler(priority = EventPriority.NORMAL) + public void onInventoryClick(InventoryClickEvent event) + { + IInventory inv = ((CraftInventory) event.getInventory()).getInventory(); + HumanEntity player = event.getWhoClicked(); + if (inv instanceof OpenInvPlayerInventory && event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot()) + { + if (!player.hasPermission(Permissions.PERM_EDITINV)) + { + event.setCancelled(true); + } + } + else if (inv instanceof OpenInvEnderChest && event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot()) + { + if (!player.hasPermission(Permissions.PERM_EDITENDER)) + { + event.setCancelled(true); + } + } + } +} \ No newline at end of file diff --git a/src/lishid/openinv/OpenInvPlayerListener.java b/src/lishid/openinv/OpenInvPlayerListener.java index 0729889..1f4a070 100644 --- a/src/lishid/openinv/OpenInvPlayerListener.java +++ b/src/lishid/openinv/OpenInvPlayerListener.java @@ -18,6 +18,7 @@ package lishid.openinv; import java.lang.reflect.Field; +import lishid.openinv.utils.OpenInvEnderChest; import lishid.openinv.utils.OpenInvPlayerInventory; import lishid.openinv.utils.SilentContainerChest; import net.minecraft.server.Block; @@ -44,13 +45,6 @@ import org.bukkit.event.player.PlayerQuitEvent; public class OpenInvPlayerListener implements Listener { - OpenInv plugin; - - public OpenInvPlayerListener(OpenInv plugin) - { - this.plugin = plugin; - } - @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { @@ -60,17 +54,30 @@ public class OpenInvPlayerListener implements Listener { inventory.PlayerGoOnline((CraftPlayer) event.getPlayer()); } + + OpenInvEnderChest chest = OpenInv.enderChests.get(event.getPlayer().getName().toLowerCase()); + + if (chest != null) + { + chest.PlayerGoOnline((CraftPlayer) event.getPlayer()); + } } @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { OpenInvPlayerInventory inventory = OpenInv.inventories.get(event.getPlayer().getName().toLowerCase()); - if(inventory != null) + if (inventory != null) { inventory.PlayerGoOffline(); inventory.InventoryRemovalCheck(); } + OpenInvEnderChest chest = OpenInv.enderChests.get(event.getPlayer().getName().toLowerCase()); + if (chest != null) + { + chest.PlayerGoOffline(); + chest.InventoryRemovalCheck(); + } } @EventHandler(priority = EventPriority.MONITOR) @@ -87,19 +94,15 @@ public class OpenInvPlayerListener implements Listener int y = event.getClickedBlock().getY(); int z = event.getClickedBlock().getZ(); - if (event.getPlayer().hasPermission("OpenInv.silent") && OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName())) + if (event.getPlayer().hasPermission(Permissions.PERM_SILENT) && OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName())) { silentchest = true; } - if (event.getPlayer().hasPermission("OpenInv.anychest") && OpenInv.GetPlayerAnyChestStatus(event.getPlayer().getName())) + if (event.getPlayer().hasPermission(Permissions.PERM_ANYCHEST) && OpenInv.GetPlayerAnyChestStatus(event.getPlayer().getName())) { try { - - - - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest EntityPlayer player = ((CraftPlayer) event.getPlayer()).getHandle(); World world = player.world; @@ -203,7 +206,7 @@ public class OpenInvPlayerListener implements Listener try { Sign sign = ((Sign) event.getClickedBlock().getState()); - if (player.hasPermission("OpenInv.openinv") && sign.getLine(0).equalsIgnoreCase("[openinv]")) + if (player.hasPermission(Permissions.PERM_OPENINV) && sign.getLine(0).equalsIgnoreCase("[openinv]")) { String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim(); player.performCommand("openinv " + text); @@ -220,7 +223,7 @@ public class OpenInvPlayerListener implements Listener { Player player = event.getPlayer(); - if (!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !player.hasPermission("OpenInv.openinv")) + if (!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !player.hasPermission(Permissions.PERM_OPENINV)) { return; } diff --git a/src/lishid/openinv/Permissions.java b/src/lishid/openinv/Permissions.java new file mode 100644 index 0000000..d2ce2bd --- /dev/null +++ b/src/lishid/openinv/Permissions.java @@ -0,0 +1,15 @@ +package lishid.openinv; + +public class Permissions +{ + public static final String PERM_OPENINV = "OpenInv.openinv"; + public static final String PERM_OVERRIDE = "OpenInv.override"; + public static final String PERM_EXEMPT = "OpenInv.exempt"; + public static final String PERM_CROSSWORLD = "OpenInv.crossworld"; + public static final String PERM_SILENT = "OpenInv.silent"; + public static final String PERM_ANYCHEST = "OpenInv.anychest"; + public static final String PERM_ENDERCHEST = "OpenInv.openender"; + public static final String PERM_SEARCH = "OpenInv.search"; + public static final String PERM_EDITINV = "OpenInv.editinv"; + public static final String PERM_EDITENDER = "OpenInv.editender"; +} diff --git a/src/lishid/openinv/commands/AnyChestPluginCommand.java b/src/lishid/openinv/commands/AnyChestPluginCommand.java index 910b1f4..9f7f819 100644 --- a/src/lishid/openinv/commands/AnyChestPluginCommand.java +++ b/src/lishid/openinv/commands/AnyChestPluginCommand.java @@ -17,6 +17,7 @@ package lishid.openinv.commands; import lishid.openinv.OpenInv; +import lishid.openinv.Permissions; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -38,7 +39,7 @@ public class AnyChestPluginCommand implements CommandExecutor sender.sendMessage(ChatColor.RED + "You can't use this from the console."); return true; } - if (!sender.hasPermission("OpenInv.anychest")) + if (!sender.hasPermission(Permissions.PERM_ANYCHEST)) { sender.sendMessage(ChatColor.RED + "You do not have permission to use anychest."); return true; diff --git a/src/lishid/openinv/commands/OpenEnderPluginCommand.java b/src/lishid/openinv/commands/OpenEnderPluginCommand.java new file mode 100644 index 0000000..69405e6 --- /dev/null +++ b/src/lishid/openinv/commands/OpenEnderPluginCommand.java @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2011-2012 lishid. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package lishid.openinv.commands; + +import java.io.File; +import java.util.Arrays; +import java.util.HashMap; + +import lishid.openinv.OpenInv; +import lishid.openinv.Permissions; +import lishid.openinv.utils.OpenInvEnderChest; +import lishid.openinv.utils.OpenInvPlayerInventory; + +import net.minecraft.server.EntityPlayer; +import net.minecraft.server.ItemInWorldManager; +import net.minecraft.server.MinecraftServer; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class OpenEnderPluginCommand implements CommandExecutor +{ + private final OpenInv plugin; + public static HashMap offlineEnder = new HashMap(); + public static HashMap openEnderHistory = new HashMap(); + + public OpenEnderPluginCommand(OpenInv plugin) + { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) + { + if (!(sender instanceof Player)) + { + sender.sendMessage(ChatColor.RED + "You can't use this from the console."); + return true; + } + + if (!sender.hasPermission(Permissions.PERM_ENDERCHEST)) + { + sender.sendMessage(ChatColor.RED + "You do not have permission to access player enderchest"); + return true; + } + + if (args.length > 0 && args[0].equalsIgnoreCase("?")) + { + OpenInv.ShowHelp((Player) sender); + return true; + } + + Player player = (Player) sender; + boolean offline = false; + + // History management + String history = openEnderHistory.get(player); + + if (history == null || history == "") + { + history = player.getName(); + openEnderHistory.put(player, history); + } + + // Target selecting + Player target; + + String name = ""; + + // Read from history if target is not named + if (args.length < 1) + { + if (history != null && history != "") + { + name = history; + } + else + { + sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!"); + return true; + } + } + else + { + name = args[0]; + } + + target = this.plugin.getServer().getPlayer(name); + + if (target == null) + { + // Offline ender here... + try + { + // Default player folder + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + if (!playerfolder.exists()) + { + sender.sendMessage(ChatColor.RED + "Player " + name + " not found!"); + return true; + } + + String playername = OpenInvPluginCommand.matchUser(Arrays.asList(playerfolder.listFiles()), name); + if (playername == null) + { + sender.sendMessage(ChatColor.RED + "Player " + name + " not found!"); + return true; + } + + // Create an entity to load the player data + final MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + final EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new ItemInWorldManager(server.getWorldServer(0))); + target = (entity == null) ? null : (Player) entity.getBukkitEntity(); + if (target != null) + { + target.loadData(); + offline = true; + } + else + { + sender.sendMessage(ChatColor.RED + "Player " + name + " not found!"); + return true; + } + } + catch (Exception e) + { + sender.sendMessage("Error while retrieving offline player data!"); + e.printStackTrace(); + return true; + } + } + + // Record the target + history = target.getName(); + openEnderHistory.put(player, history); + + // Create the inventory + OpenInvEnderChest chest = OpenInv.enderChests.get(target.getName().toLowerCase()); + if (chest == null) + { + chest = new OpenInvEnderChest((CraftPlayer) target, !offline); + + OpenInv.enderChests.put(target.getName().toLowerCase(), chest); + } + + // Open the inventory + (((CraftPlayer) player).getHandle()).openContainer(chest); + + return true; + } +} diff --git a/src/lishid/openinv/commands/OpenInvPluginCommand.java b/src/lishid/openinv/commands/OpenInvPluginCommand.java index 2480d74..bd3b322 100644 --- a/src/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/lishid/openinv/commands/OpenInvPluginCommand.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.HashMap; import lishid.openinv.OpenInv; +import lishid.openinv.Permissions; import lishid.openinv.utils.OpenInvPlayerInventory; import net.minecraft.server.EntityPlayer; @@ -55,7 +56,7 @@ public class OpenInvPluginCommand implements CommandExecutor sender.sendMessage(ChatColor.RED + "You can't use this from the console."); return true; } - if (!sender.hasPermission("OpenInv.openinv")) + if (!sender.hasPermission(Permissions.PERM_OPENINV)) { sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories"); return true; @@ -159,13 +160,13 @@ public class OpenInvPluginCommand implements CommandExecutor } // Permissions checks - if (!player.hasPermission("OpenInv.override") && target.hasPermission("OpenInv.exempt")) + if (!player.hasPermission(Permissions.PERM_OVERRIDE) && target.hasPermission(Permissions.PERM_EXEMPT)) { sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!"); return true; } - if ((!player.hasPermission("OpenInv.crossworld") && !player.hasPermission("OpenInv.override")) && target.getWorld() != player.getWorld()) + if ((!player.hasPermission(Permissions.PERM_CROSSWORLD) && !player.hasPermission(Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) { sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!"); return true; @@ -193,7 +194,7 @@ public class OpenInvPluginCommand implements CommandExecutor /** * @author Balor (aka Antoine Aflalo) */ - private String matchUser(final Collection container, final String search) + public static String matchUser(final Collection container, final String search) { String found = null; if (search == null) diff --git a/src/lishid/openinv/commands/SearchInvPluginCommand.java b/src/lishid/openinv/commands/SearchInvPluginCommand.java index 4bee2a8..057f13b 100644 --- a/src/lishid/openinv/commands/SearchInvPluginCommand.java +++ b/src/lishid/openinv/commands/SearchInvPluginCommand.java @@ -17,6 +17,7 @@ package lishid.openinv.commands; import lishid.openinv.OpenInv; +import lishid.openinv.Permissions; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -38,7 +39,7 @@ public class SearchInvPluginCommand implements CommandExecutor { if (sender instanceof Player) { - if (!sender.hasPermission("OpenInv.search")) + if (!sender.hasPermission(Permissions.PERM_SEARCH)) { sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories"); return true; diff --git a/src/lishid/openinv/commands/SilentChestPluginCommand.java b/src/lishid/openinv/commands/SilentChestPluginCommand.java index 62c7f3b..1223181 100644 --- a/src/lishid/openinv/commands/SilentChestPluginCommand.java +++ b/src/lishid/openinv/commands/SilentChestPluginCommand.java @@ -17,6 +17,7 @@ package lishid.openinv.commands; import lishid.openinv.OpenInv; +import lishid.openinv.Permissions; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -38,7 +39,7 @@ public class SilentChestPluginCommand implements CommandExecutor sender.sendMessage(ChatColor.RED + "You can't use this from the console."); return true; } - if (!sender.hasPermission("OpenInv.silent")) + if (!sender.hasPermission(Permissions.PERM_SILENT)) { sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest."); return true; diff --git a/src/lishid/openinv/commands/ToggleOpenInvPluginCommand.java b/src/lishid/openinv/commands/ToggleOpenInvPluginCommand.java index 2eb1baf..6663cf6 100644 --- a/src/lishid/openinv/commands/ToggleOpenInvPluginCommand.java +++ b/src/lishid/openinv/commands/ToggleOpenInvPluginCommand.java @@ -17,6 +17,7 @@ package lishid.openinv.commands; import lishid.openinv.OpenInv; +import lishid.openinv.Permissions; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -35,7 +36,7 @@ public class ToggleOpenInvPluginCommand implements CommandExecutor sender.sendMessage(ChatColor.RED + "You can't use this from the console."); return true; } - if (!sender.hasPermission("OpenInv.openinv")) + if (!sender.hasPermission(Permissions.PERM_OPENINV)) { sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories"); return true; diff --git a/src/lishid/openinv/utils/OpenInvEnderChest.java b/src/lishid/openinv/utils/OpenInvEnderChest.java new file mode 100644 index 0000000..940eff5 --- /dev/null +++ b/src/lishid/openinv/utils/OpenInvEnderChest.java @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2011-2012 lishid. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package lishid.openinv.utils; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import lishid.openinv.OpenInv; + +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.InventoryHolder; + +import net.minecraft.server.EntityHuman; +import net.minecraft.server.IInventory; +import net.minecraft.server.InventoryEnderChest; +import net.minecraft.server.InventorySubcontainer; +import net.minecraft.server.ItemStack; + +public class OpenInvEnderChest extends InventorySubcontainer implements IInventory +{ + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private CraftPlayer owner; + private InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + + public OpenInvEnderChest(CraftPlayer player, boolean online) + { + super(player.getHandle().getEnderChest().getName(), player.getHandle().getEnderChest().getSize()); + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + this.InventoryRemovalCheck(); + } + + public void InventoryRemovalCheck() + { + if (transaction.isEmpty() && !playerOnline) + { + owner.saveData(); + OpenInv.enderChests.remove(owner.getName().toLowerCase()); + } + } + + public void PlayerGoOnline(CraftPlayer p) + { + if (!playerOnline) + { + try + { + InventoryEnderChest playerEnderChest = p.getHandle().getEnderChest(); + Field field = playerEnderChest.getClass().getField("items"); + field.setAccessible(true); + field.set(playerEnderChest, this.items); + } + catch (Exception e) + { + } + p.saveData(); + playerOnline = true; + } + } + + public void PlayerGoOffline() + { + playerOnline = false; + } + + public ItemStack[] getContents() + { + return this.items; + } + + public void onOpen(CraftHumanEntity who) + { + transaction.add(who); + } + + public void onClose(CraftHumanEntity who) + { + transaction.remove(who); + } + + public List getViewers() + { + return transaction; + } + + public InventoryHolder getOwner() + { + return this.owner; + } + + public void setMaxStackSize(int size) + { + maxStack = size; + } + + public int getMaxStackSize() + { + return maxStack; + } + + public boolean a(EntityHuman entityhuman) + { + return true; + } + + public void startOpen() + { + + } + + public void f() + { + + } + + public void update() + { + enderChest.update(); + } +} diff --git a/src/lishid/openinv/utils/OpenInvPlayerInventory.java b/src/lishid/openinv/utils/OpenInvPlayerInventory.java index eaefc0d..dba6ca9 100644 --- a/src/lishid/openinv/utils/OpenInvPlayerInventory.java +++ b/src/lishid/openinv/utils/OpenInvPlayerInventory.java @@ -35,6 +35,7 @@ public class OpenInvPlayerInventory extends PlayerInventory { super(p.getHandle()); this.owner = p; + this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; } diff --git a/src/plugin.yml b/src/plugin.yml index 5bc5f2d..e78c27c 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: lishid.openinv.OpenInv -version: 1.8.6 +version: 1.8.7 author: lishid website: http://forums.bukkit.org/threads/15379/ description: > @@ -12,6 +12,11 @@ commands: usage: | / - Open last person's inventory / - Open a player's inventory + openender: + aliases: [oe, enderchest] + description: Opens the enderchest of a player + usage: | + / - Opens a player's enderchest searchinv: aliases: [si] description: Search and list players having a specific item