From 4597db93bdb688a4d243a1c2acdf793b8ad58806 Mon Sep 17 00:00:00 2001 From: lishid Date: Fri, 5 Jul 2013 21:58:42 -0700 Subject: [PATCH] Update to 2.0.4 --- src/com/lishid/openinv/OpenInv.java | 27 +- .../internal/craftbukkit/AnySilentChest.java | 19 +- .../internal/v1_4_5/AnySilentChest.java | 19 +- .../internal/v1_4_6/AnySilentChest.java | 21 +- .../internal/v1_4_R1/AnySilentChest.java | 19 +- .../{v1_5_R1 => v1_5_R2}/AnySilentChest.java | 65 ++-- .../{v1_5_R1 => v1_5_R2}/InventoryAccess.java | 6 +- .../PlayerDataManager.java | 8 +- .../SilentContainerChest.java | 4 +- .../SpecialEnderChest.java | 8 +- .../SpecialPlayerInventory.java | 8 +- .../internal/v1_5_R3/AnySilentChest.java | 138 ++++++++ .../internal/v1_5_R3/InventoryAccess.java | 53 ++++ .../internal/v1_5_R3/PlayerDataManager.java | 110 +++++++ .../v1_5_R3/SilentContainerChest.java | 39 +++ .../internal/v1_5_R3/SpecialEnderChest.java | 148 +++++++++ .../v1_5_R3/SpecialPlayerInventory.java | 297 ++++++++++++++++++ .../internal/v1_6_R1/AnySilentChest.java | 136 ++++++++ .../internal/v1_6_R1/InventoryAccess.java | 53 ++++ .../internal/v1_6_R1/PlayerDataManager.java | 110 +++++++ .../v1_6_R1/SilentContainerChest.java | 39 +++ .../internal/v1_6_R1/SpecialEnderChest.java | 148 +++++++++ .../v1_6_R1/SpecialPlayerInventory.java | 297 ++++++++++++++++++ src/plugin.yml | 2 +- 24 files changed, 1699 insertions(+), 75 deletions(-) rename src/com/lishid/openinv/internal/{v1_5_R1 => v1_5_R2}/AnySilentChest.java (64%) rename src/com/lishid/openinv/internal/{v1_5_R1 => v1_5_R2}/InventoryAccess.java (88%) rename src/com/lishid/openinv/internal/{v1_5_R1 => v1_5_R2}/PlayerDataManager.java (90%) rename src/com/lishid/openinv/internal/{v1_5_R1 => v1_5_R2}/SilentContainerChest.java (89%) rename src/com/lishid/openinv/internal/{v1_5_R1 => v1_5_R2}/SpecialEnderChest.java (91%) rename src/com/lishid/openinv/internal/{v1_5_R1 => v1_5_R2}/SpecialPlayerInventory.java (93%) create mode 100644 src/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java create mode 100644 src/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java create mode 100644 src/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java create mode 100644 src/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java create mode 100644 src/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java create mode 100644 src/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java create mode 100644 src/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java create mode 100644 src/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java create mode 100644 src/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java create mode 100644 src/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java create mode 100644 src/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java create mode 100644 src/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java diff --git a/src/com/lishid/openinv/OpenInv.java b/src/com/lishid/openinv/OpenInv.java index cbbd2b0..34831d3 100644 --- a/src/com/lishid/openinv/OpenInv.java +++ b/src/com/lishid/openinv/OpenInv.java @@ -19,8 +19,8 @@ package com.lishid.openinv; import java.util.HashMap; import java.util.logging.Logger; - import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -77,10 +77,17 @@ public class OpenInv extends JavaPlugin anySilentChest = InternalAccessor.Instance.newAnySilentChest(); mainPlugin = this; - mainPlugin.getConfig().addDefault("ItemOpenInvItemID", 280); - mainPlugin.getConfig().addDefault("CheckForUpdates", true); - mainPlugin.getConfig().options().copyDefaults(true); - mainPlugin.saveConfig(); + FileConfiguration config = getConfig(); + config.set("CheckForUpdates", config.getBoolean("CheckForUpdates", true)); + config.set("NotifySilentChest", config.getBoolean("NotifySilentChest", true)); + config.set("NotifyAnyChest", config.getBoolean("NotifyAnyChest", true)); + config.set("ItemOpenInvItemID", config.getInt("ItemOpenInvItemID", 280)); + config.addDefault("ItemOpenInvItemID", 280); + config.addDefault("CheckForUpdates", true); + config.addDefault("NotifySilentChest", true); + config.addDefault("NotifyAnyChest", true); + config.options().copyDefaults(true); + saveConfig(); pm.registerEvents(new OpenInvPlayerListener(), this); pm.registerEvents(new OpenInvEntityListener(), this); @@ -107,6 +114,16 @@ public class OpenInv extends JavaPlugin } } + public static boolean NotifySilentChest() + { + return mainPlugin.getConfig().getBoolean("NotifySilentChest", true); + } + + public static boolean NotifyAnyChest() + { + return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true); + } + public static boolean GetCheckForUpdates() { return mainPlugin.getConfig().getBoolean("CheckForUpdates", true); diff --git a/src/com/lishid/openinv/internal/craftbukkit/AnySilentChest.java b/src/com/lishid/openinv/internal/craftbukkit/AnySilentChest.java index 674f312..7702682 100644 --- a/src/com/lishid/openinv/internal/craftbukkit/AnySilentChest.java +++ b/src/com/lishid/openinv/internal/craftbukkit/AnySilentChest.java @@ -21,10 +21,12 @@ import java.lang.reflect.Field; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IAnySilentChest; //Volatile import net.minecraft.server.*; + import org.bukkit.craftbukkit.entity.*; public class AnySilentChest implements IAnySilentChest @@ -82,6 +84,7 @@ public class AnySilentChest implements IAnySilentChest if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); + boolean returnValue = true; if (!silentchest) { player.openContainer((IInventory) chest); @@ -100,15 +103,17 @@ public class AnySilentChest implements IAnySilentChest windowID.setInt(player, id); } catch (NoSuchFieldException e) - { - } + {} player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); player.activeContainer.windowId = id; player.activeContainer.addSlotListener(player); - // event.getPlayer().sendMessage("You are opening a chest silently."); - return false; + if (OpenInv.NotifySilentChest()) + { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; } catch (Exception e) { @@ -117,9 +122,11 @@ public class AnySilentChest implements IAnySilentChest } } - if (anychest) + if (anychest && OpenInv.NotifyAnyChest()) + { p.sendMessage("You are opening a blocked chest."); + } - return true; + return returnValue; } } diff --git a/src/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java index 153589c..2c51fa3 100644 --- a/src/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java +++ b/src/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java @@ -21,10 +21,12 @@ import java.lang.reflect.Field; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IAnySilentChest; //Volatile import net.minecraft.server.v1_4_5.*; + import org.bukkit.craftbukkit.v1_4_5.entity.*; public class AnySilentChest implements IAnySilentChest @@ -82,6 +84,7 @@ public class AnySilentChest implements IAnySilentChest if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); + boolean returnValue = true; if (!silentchest) { player.openContainer((IInventory) chest); @@ -100,15 +103,17 @@ public class AnySilentChest implements IAnySilentChest windowID.setInt(player, id); } catch (NoSuchFieldException e) - { - } + {} player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); player.activeContainer.windowId = id; player.activeContainer.addSlotListener(player); - // event.getPlayer().sendMessage("You are opening a chest silently."); - return false; + if (OpenInv.NotifySilentChest()) + { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; } catch (Exception e) { @@ -117,9 +122,11 @@ public class AnySilentChest implements IAnySilentChest } } - if (anychest) + if (anychest && OpenInv.NotifyAnyChest()) + { p.sendMessage("You are opening a blocked chest."); + } - return true; + return returnValue; } } diff --git a/src/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java index 09f9886..d738404 100644 --- a/src/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java +++ b/src/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java @@ -21,10 +21,12 @@ import java.lang.reflect.Field; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IAnySilentChest; //Volatile import net.minecraft.server.v1_4_6.*; + import org.bukkit.craftbukkit.v1_4_6.entity.*; public class AnySilentChest implements IAnySilentChest @@ -81,7 +83,8 @@ public class AnySilentChest implements IAnySilentChest chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - + + boolean returnValue = true; if (!silentchest) { player.openContainer((IInventory) chest); @@ -100,15 +103,17 @@ public class AnySilentChest implements IAnySilentChest windowID.setInt(player, id); } catch (NoSuchFieldException e) - { - } + {} player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); player.activeContainer.windowId = id; player.activeContainer.addSlotListener(player); - // event.getPlayer().sendMessage("You are opening a chest silently."); - return false; + if (OpenInv.NotifySilentChest()) + { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; } catch (Exception e) { @@ -117,9 +122,11 @@ public class AnySilentChest implements IAnySilentChest } } - if (anychest) + if (anychest && OpenInv.NotifyAnyChest()) + { p.sendMessage("You are opening a blocked chest."); + } - return true; + return returnValue; } } diff --git a/src/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java index bceb1c9..bd8c963 100644 --- a/src/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java +++ b/src/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java @@ -21,10 +21,12 @@ import java.lang.reflect.Field; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IAnySilentChest; //Volatile import net.minecraft.server.v1_4_R1.*; + import org.bukkit.craftbukkit.v1_4_R1.entity.*; public class AnySilentChest implements IAnySilentChest @@ -82,6 +84,7 @@ public class AnySilentChest implements IAnySilentChest if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); + boolean returnValue = true; if (!silentchest) { player.openContainer((IInventory) chest); @@ -100,15 +103,17 @@ public class AnySilentChest implements IAnySilentChest windowID.setInt(player, id); } catch (NoSuchFieldException e) - { - } + {} player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); player.activeContainer.windowId = id; player.activeContainer.addSlotListener(player); - // event.getPlayer().sendMessage("You are opening a chest silently."); - return false; + if (OpenInv.NotifySilentChest()) + { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; } catch (Exception e) { @@ -117,9 +122,11 @@ public class AnySilentChest implements IAnySilentChest } } - if (anychest) + if (anychest && OpenInv.NotifyAnyChest()) + { p.sendMessage("You are opening a blocked chest."); + } - return true; + return returnValue; } } diff --git a/src/com/lishid/openinv/internal/v1_5_R1/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java similarity index 64% rename from src/com/lishid/openinv/internal/v1_5_R1/AnySilentChest.java rename to src/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java index 5f23147..eb4ce83 100644 --- a/src/com/lishid/openinv/internal/v1_5_R1/AnySilentChest.java +++ b/src/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java @@ -14,18 +14,20 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_5_R1; +package com.lishid.openinv.internal.v1_5_R2; import java.lang.reflect.Field; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IAnySilentChest; //Volatile -import net.minecraft.server.v1_5_R1.*; -import org.bukkit.craftbukkit.v1_5_R1.entity.*; +import net.minecraft.server.v1_5_R2.*; + +import org.bukkit.craftbukkit.v1_5_R2.entity.*; public class AnySilentChest implements IAnySilentChest { @@ -38,14 +40,16 @@ public class AnySilentChest implements IAnySilentChest if (world.t(x, y + 1, z)) return true; + int id = world.getTypeId(x, y, z); + // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.t(x - 1, y + 1, z))) + if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.t(x + 1, y + 1, z))) + if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.t(x, y + 1, z - 1))) + if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.t(x, y + 1, z + 1))) + if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) return true; return false; @@ -59,29 +63,32 @@ public class AnySilentChest implements IAnySilentChest if (chest == null) return true; + int id = world.getTypeId(x, y, z); + if (!anychest) { if (world.t(x, y + 1, z)) return true; - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.t(x - 1, y + 1, z))) + if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.t(x + 1, y + 1, z))) + if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.t(x, y + 1, z - 1))) + if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.t(x, y + 1, z + 1))) + if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) return true; } - if (world.getTypeId(x - 1, y, z) == Block.CHEST.id) + if (world.getTypeId(x - 1, y, z) == id) chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == Block.CHEST.id) + if (world.getTypeId(x + 1, y, z) == id) chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == Block.CHEST.id) + if (world.getTypeId(x, y, z - 1) == id) chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) + if (world.getTypeId(x, y, z + 1) == id) chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); + boolean returnValue = true; if (!silentchest) { player.openContainer((IInventory) chest); @@ -90,25 +97,27 @@ public class AnySilentChest implements IAnySilentChest { try { - int id = 0; + int windowId = 0; try { Field windowID = player.getClass().getDeclaredField("containerCounter"); windowID.setAccessible(true); - id = windowID.getInt(player); - id = id % 100 + 1; - windowID.setInt(player, id); + windowId = windowID.getInt(player); + windowId = windowId % 100 + 1; + windowID.setInt(player, windowId); } catch (NoSuchFieldException e) - { - } + {} - player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = id; + player.activeContainer.windowId = windowId; player.activeContainer.addSlotListener(player); - // event.getPlayer().sendMessage("You are opening a chest silently."); - return false; + if (OpenInv.NotifySilentChest()) + { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; } catch (Exception e) { @@ -117,9 +126,11 @@ public class AnySilentChest implements IAnySilentChest } } - if (anychest) + if (anychest && OpenInv.NotifyAnyChest()) + { p.sendMessage("You are opening a blocked chest."); + } - return true; + return returnValue; } } diff --git a/src/com/lishid/openinv/internal/v1_5_R1/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java similarity index 88% rename from src/com/lishid/openinv/internal/v1_5_R1/InventoryAccess.java rename to src/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java index 13b0c2e..8179dc9 100644 --- a/src/com/lishid/openinv/internal/v1_5_R1/InventoryAccess.java +++ b/src/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_5_R1; +package com.lishid.openinv.internal.v1_5_R2; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.Inventory; @@ -23,8 +23,8 @@ import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.IInventoryAccess; //Volatile -import net.minecraft.server.v1_5_R1.*; -import org.bukkit.craftbukkit.v1_5_R1.inventory.*; +import net.minecraft.server.v1_5_R2.*; +import org.bukkit.craftbukkit.v1_5_R2.inventory.*; public class InventoryAccess implements IInventoryAccess { diff --git a/src/com/lishid/openinv/internal/v1_5_R1/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java similarity index 90% rename from src/com/lishid/openinv/internal/v1_5_R1/PlayerDataManager.java rename to src/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java index dc7ead5..e62101f 100644 --- a/src/com/lishid/openinv/internal/v1_5_R1/PlayerDataManager.java +++ b/src/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_5_R1; +package com.lishid.openinv.internal.v1_5_R2; import java.io.File; import java.util.Arrays; @@ -27,8 +27,8 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IPlayerDataManager; //Volatile -import net.minecraft.server.v1_5_R1.*; -import org.bukkit.craftbukkit.v1_5_R1.*; +import net.minecraft.server.v1_5_R2.*; +import org.bukkit.craftbukkit.v1_5_R2.*; public class PlayerDataManager implements IPlayerDataManager { @@ -53,7 +53,7 @@ public class PlayerDataManager implements IPlayerDataManager MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager(server.getWorldServer(0))); + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); // Get the bukkit entity Player target = (entity == null) ? null : entity.getBukkitEntity(); diff --git a/src/com/lishid/openinv/internal/v1_5_R1/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java similarity index 89% rename from src/com/lishid/openinv/internal/v1_5_R1/SilentContainerChest.java rename to src/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java index f196959..17a0aa9 100644 --- a/src/com/lishid/openinv/internal/v1_5_R1/SilentContainerChest.java +++ b/src/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java @@ -14,10 +14,10 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_5_R1; +package com.lishid.openinv.internal.v1_5_R2; //Volatile -import net.minecraft.server.v1_5_R1.*; +import net.minecraft.server.v1_5_R2.*; public class SilentContainerChest extends ContainerChest { diff --git a/src/com/lishid/openinv/internal/v1_5_R1/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java similarity index 91% rename from src/com/lishid/openinv/internal/v1_5_R1/SpecialEnderChest.java rename to src/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java index c9ca26f..bfeb8a1 100644 --- a/src/com/lishid/openinv/internal/v1_5_R1/SpecialEnderChest.java +++ b/src/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_5_R1; +package com.lishid.openinv.internal.v1_5_R2; import java.lang.reflect.Field; import java.util.ArrayList; @@ -29,9 +29,9 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; //Volatile -import net.minecraft.server.v1_5_R1.*; -import org.bukkit.craftbukkit.v1_5_R1.entity.*; -import org.bukkit.craftbukkit.v1_5_R1.inventory.*; +import net.minecraft.server.v1_5_R2.*; +import org.bukkit.craftbukkit.v1_5_R2.entity.*; +import org.bukkit.craftbukkit.v1_5_R2.inventory.*; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { diff --git a/src/com/lishid/openinv/internal/v1_5_R1/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java similarity index 93% rename from src/com/lishid/openinv/internal/v1_5_R1/SpecialPlayerInventory.java rename to src/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java index c042c75..80d9f07 100644 --- a/src/com/lishid/openinv/internal/v1_5_R1/SpecialPlayerInventory.java +++ b/src/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_5_R1; +package com.lishid.openinv.internal.v1_5_R2; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -23,9 +23,9 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.ISpecialPlayerInventory; //Volatile -import net.minecraft.server.v1_5_R1.*; -import org.bukkit.craftbukkit.v1_5_R1.entity.*; -import org.bukkit.craftbukkit.v1_5_R1.inventory.*; +import net.minecraft.server.v1_5_R2.*; +import org.bukkit.craftbukkit.v1_5_R2.entity.*; +import org.bukkit.craftbukkit.v1_5_R2.inventory.*; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { diff --git a/src/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java new file mode 100644 index 0000000..421e374 --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java @@ -0,0 +1,138 @@ +/* + * 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 com.lishid.openinv.internal.v1_5_R3; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.IAnySilentChest; + +import com.lishid.openinv.internal.v1_5_R3.SilentContainerChest; + +//Volatile +import net.minecraft.server.v1_5_R3.*; + +import org.bukkit.craftbukkit.v1_5_R3.entity.*; + +public class AnySilentChest implements IAnySilentChest +{ + public boolean IsAnyChestNeeded(Player p, int x, int y, int z) + { + // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest + EntityPlayer player = ((CraftPlayer) p).getHandle(); + World world = player.world; + // If block on top + if (world.t(x, y + 1, z)) + return true; + + int id = world.getTypeId(x, y, z); + + // If block next to chest is chest and has a block on top + if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) + return true; + + return false; + } + + public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) + { + EntityPlayer player = ((CraftPlayer) p).getHandle(); + World world = player.world; + Object chest = (TileEntityChest) world.getTileEntity(x, y, z); + if (chest == null) + return true; + + int id = world.getTypeId(x, y, z); + + if (!anychest) + { + if (world.t(x, y + 1, z)) + return true; + if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) + return true; + } + + if (world.getTypeId(x - 1, y, z) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); + if (world.getTypeId(x + 1, y, z) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (world.getTypeId(x, y, z - 1) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); + if (world.getTypeId(x, y, z + 1) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); + + boolean returnValue = true; + if (!silentchest) + { + player.openContainer((IInventory) chest); + } + else + { + try + { + int windowId = 0; + try + { + Field windowID = player.getClass().getDeclaredField("containerCounter"); + windowID.setAccessible(true); + windowId = windowID.getInt(player); + windowId = windowId % 100 + 1; + windowID.setInt(player, windowId); + } + catch (NoSuchFieldException e) + {} + + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); + player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + if (OpenInv.NotifySilentChest()) + { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; + } + catch (Exception e) + { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + if (anychest && OpenInv.NotifyAnyChest()) + { + p.sendMessage("You are opening a blocked chest."); + } + + return returnValue; + } +} diff --git a/src/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java new file mode 100644 index 0000000..350b81d --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java @@ -0,0 +1,53 @@ +/* + * 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 com.lishid.openinv.internal.v1_5_R3; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +//Volatile +import net.minecraft.server.v1_5_R3.*; +import org.bukkit.craftbukkit.v1_5_R3.inventory.*; + +public class InventoryAccess implements IInventoryAccess +{ + public boolean check(Inventory inventory, HumanEntity player) + { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) + { + if (!player.hasPermission(Permissions.PERM_EDITINV)) + { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) + { + if (!player.hasPermission(Permissions.PERM_EDITENDER)) + { + return false; + } + } + + return true; + } +} diff --git a/src/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java new file mode 100644 index 0000000..d5b7af9 --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java @@ -0,0 +1,110 @@ +/* + * 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 com.lishid.openinv.internal.v1_5_R3; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.IPlayerDataManager; + +//Volatile +import net.minecraft.server.v1_5_R3.*; +import org.bukkit.craftbukkit.v1_5_R3.*; + +public class PlayerDataManager implements IPlayerDataManager +{ + public Player loadPlayer(String name) + { + try + { + // Default player folder + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + if (!playerfolder.exists()) + { + return null; + } + + String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); + + if (playername == null) + { + return null; + } + + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); + + // Get the bukkit entity + Player target = (entity == null) ? null : entity.getBukkitEntity(); + if (target != null) + { + // Load data + target.loadData(); + // Return the entity + return target; + } + } + catch (Exception e) + { + OpenInv.log(e); + } + + return null; + } + + /** + * @author Balor (aka Antoine Aflalo) + */ + private static String matchUser(final Collection container, final String search) + { + String found = null; + if (search == null) + { + return found; + } + final String lowerSearch = search.toLowerCase(); + int delta = Integer.MAX_VALUE; + for (final File file : container) + { + final String filename = file.getName(); + final String str = filename.substring(0, filename.length() - 4); + if (!str.toLowerCase().startsWith(lowerSearch)) + { + continue; + } + final int curDelta = str.length() - lowerSearch.length(); + if (curDelta < delta) + { + found = str; + delta = curDelta; + } + if (curDelta == 0) + { + break; + } + + } + return found; + } +} diff --git a/src/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java new file mode 100644 index 0000000..df42801 --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java @@ -0,0 +1,39 @@ +/* + * 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 com.lishid.openinv.internal.v1_5_R3; + +//Volatile +import net.minecraft.server.v1_5_R3.*; + +public class SilentContainerChest extends ContainerChest +{ + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) + { + super(i1, i2); + inv = i2; + // close signal + inv.g(); + } + + @Override + public void b(EntityHuman paramEntityHuman) + { + // Don't send close signal twice, might screw up + } +} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java new file mode 100644 index 0000000..520fd9a --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java @@ -0,0 +1,148 @@ +/* + * 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 com.lishid.openinv.internal.v1_5_R3; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.ISpecialEnderChest; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +//Volatile +import net.minecraft.server.v1_5_R3.*; +import org.bukkit.craftbukkit.v1_5_R3.entity.*; +import org.bukkit.craftbukkit.v1_5_R3.inventory.*; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest +{ + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private CraftPlayer owner; + private InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) + { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + OpenInv.enderChests.put(owner.getName().toLowerCase(), this); + } + + public Inventory getBukkitInventory() + { + return inventory; + } + + public void InventoryRemovalCheck() + { + owner.saveData(); + if (transaction.isEmpty() && !playerOnline) + { + OpenInv.enderChests.remove(owner.getName().toLowerCase()); + } + } + + public void PlayerGoOnline(Player p) + { + if (!playerOnline) + { + try + { + InventoryEnderChest playerEnderChest = ((CraftPlayer) 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); + this.InventoryRemovalCheck(); + } + + 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/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java new file mode 100644 index 0000000..d76d02c --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java @@ -0,0 +1,297 @@ +/* + * 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 com.lishid.openinv.internal.v1_5_R3; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +//Volatile +import net.minecraft.server.v1_5_R3.*; +import org.bukkit.craftbukkit.v1_5_R3.entity.*; +import org.bukkit.craftbukkit.v1_5_R3.inventory.*; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory +{ + CraftPlayer owner; + public boolean playerOnline = false; + private ItemStack[] extra = new ItemStack[5]; + private CraftInventory inventory = new CraftInventory(this); + + public SpecialPlayerInventory(Player p, Boolean online) + { + super(((CraftPlayer) p).getHandle()); + this.owner = ((CraftPlayer) p); + this.playerOnline = online; + this.items = player.inventory.items; + this.armor = player.inventory.armor; + OpenInv.inventories.put(owner.getName().toLowerCase(), this); + } + + @Override + public Inventory getBukkitInventory() + { + return inventory; + } + + @Override + public void InventoryRemovalCheck() + { + owner.saveData(); + if (transaction.isEmpty() && !playerOnline) + { + OpenInv.inventories.remove(owner.getName().toLowerCase()); + } + } + + @Override + public void PlayerGoOnline(Player player) + { + if (!playerOnline) + { + CraftPlayer p = (CraftPlayer) player; + p.getHandle().inventory.items = this.items; + p.getHandle().inventory.armor = this.armor; + p.saveData(); + playerOnline = true; + } + } + + @Override + public void PlayerGoOffline() + { + playerOnline = false; + this.InventoryRemovalCheck(); + } + + @Override + public void onClose(CraftHumanEntity who) + { + super.onClose(who); + this.InventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() + { + ItemStack[] C = new ItemStack[getSize()]; + System.arraycopy(items, 0, C, 0, items.length); + System.arraycopy(items, 0, C, items.length, armor.length); + return C; + } + + @Override + public int getSize() + { + return super.getSize() + 5; + } + + @Override + public ItemStack getItem(int i) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + return is[i]; + } + + @Override + public ItemStack splitStack(int i, int j) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + if (is[i] != null) + { + ItemStack itemstack; + + if (is[i].count <= j) + { + itemstack = is[i]; + is[i] = null; + return itemstack; + } + else + { + itemstack = is[i].a(j); + if (is[i].count == 0) + { + is[i] = null; + } + + return itemstack; + } + } + else + { + return null; + } + } + + @Override + public ItemStack splitWithoutUpdate(int i) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + if (is[i] != null) + { + ItemStack itemstack = is[i]; + + is[i] = null; + return itemstack; + } + else + { + return null; + } + } + + @Override + public void setItem(int i, ItemStack itemstack) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + // Effects + if (is == this.extra) + { + owner.getHandle().drop(itemstack); + itemstack = null; + } + + is[i] = itemstack; + + owner.getHandle().defaultContainer.b(); + } + + private int getReversedItemSlotNum(int i) + { + if (i >= 27) + return i - 27; + else + return i + 9; + } + + private int getReversedArmorSlotNum(int i) + { + if (i == 0) + return 3; + if (i == 1) + return 2; + if (i == 2) + return 1; + if (i == 3) + return 0; + else + return i; + } + + @Override + public String getName() + { + if (player.name.length() > 16) + { + return player.name.substring(0, 16); + } + return player.name; + } + + @Override + public boolean a(EntityHuman entityhuman) + { + return true; + } +} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java new file mode 100644 index 0000000..dfdce80 --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java @@ -0,0 +1,136 @@ +/* + * 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 com.lishid.openinv.internal.v1_6_R1; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.IAnySilentChest; + +//Volatile +import net.minecraft.server.v1_6_R1.*; + +import org.bukkit.craftbukkit.v1_6_R1.entity.*; + +public class AnySilentChest implements IAnySilentChest +{ + public boolean IsAnyChestNeeded(Player p, int x, int y, int z) + { + // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest + EntityPlayer player = ((CraftPlayer) p).getHandle(); + World world = player.world; + // If block on top + if (world.t(x, y + 1, z)) + return true; + + int id = world.getTypeId(x, y, z); + + // If block next to chest is chest and has a block on top + if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) + return true; + + return false; + } + + public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) + { + EntityPlayer player = ((CraftPlayer) p).getHandle(); + World world = player.world; + Object chest = (TileEntityChest) world.getTileEntity(x, y, z); + if (chest == null) + return true; + + int id = world.getTypeId(x, y, z); + + if (!anychest) + { + if (world.t(x, y + 1, z)) + return true; + if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) + return true; + } + + if (world.getTypeId(x - 1, y, z) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); + if (world.getTypeId(x + 1, y, z) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (world.getTypeId(x, y, z - 1) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); + if (world.getTypeId(x, y, z + 1) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); + + boolean returnValue = true; + if (!silentchest) + { + player.openContainer((IInventory) chest); + } + else + { + try + { + int windowId = 0; + try + { + Field windowID = player.getClass().getDeclaredField("containerCounter"); + windowID.setAccessible(true); + windowId = windowID.getInt(player); + windowId = windowId % 100 + 1; + windowID.setInt(player, windowId); + } + catch (NoSuchFieldException e) + {} + + player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); + player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + if (OpenInv.NotifySilentChest()) + { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; + } + catch (Exception e) + { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + if (anychest && OpenInv.NotifyAnyChest()) + { + p.sendMessage("You are opening a blocked chest."); + } + + return returnValue; + } +} diff --git a/src/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java new file mode 100644 index 0000000..77f4abe --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java @@ -0,0 +1,53 @@ +/* + * 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 com.lishid.openinv.internal.v1_6_R1; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +//Volatile +import net.minecraft.server.v1_6_R1.*; +import org.bukkit.craftbukkit.v1_6_R1.inventory.*; + +public class InventoryAccess implements IInventoryAccess +{ + public boolean check(Inventory inventory, HumanEntity player) + { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) + { + if (!player.hasPermission(Permissions.PERM_EDITINV)) + { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) + { + if (!player.hasPermission(Permissions.PERM_EDITENDER)) + { + return false; + } + } + + return true; + } +} diff --git a/src/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java new file mode 100644 index 0000000..21d9c11 --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java @@ -0,0 +1,110 @@ +/* + * 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 com.lishid.openinv.internal.v1_6_R1; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.IPlayerDataManager; + +//Volatile +import net.minecraft.server.v1_6_R1.*; +import org.bukkit.craftbukkit.v1_6_R1.*; + +public class PlayerDataManager implements IPlayerDataManager +{ + public Player loadPlayer(String name) + { + try + { + // Default player folder + File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); + if (!playerfolder.exists()) + { + return null; + } + + String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); + + if (playername == null) + { + return null; + } + + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); + + // Get the bukkit entity + Player target = (entity == null) ? null : entity.getBukkitEntity(); + if (target != null) + { + // Load data + target.loadData(); + // Return the entity + return target; + } + } + catch (Exception e) + { + OpenInv.log(e); + } + + return null; + } + + /** + * @author Balor (aka Antoine Aflalo) + */ + private static String matchUser(final Collection container, final String search) + { + String found = null; + if (search == null) + { + return found; + } + final String lowerSearch = search.toLowerCase(); + int delta = Integer.MAX_VALUE; + for (final File file : container) + { + final String filename = file.getName(); + final String str = filename.substring(0, filename.length() - 4); + if (!str.toLowerCase().startsWith(lowerSearch)) + { + continue; + } + final int curDelta = str.length() - lowerSearch.length(); + if (curDelta < delta) + { + found = str; + delta = curDelta; + } + if (curDelta == 0) + { + break; + } + + } + return found; + } +} diff --git a/src/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java new file mode 100644 index 0000000..5afbebe --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java @@ -0,0 +1,39 @@ +/* + * 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 com.lishid.openinv.internal.v1_6_R1; + +//Volatile +import net.minecraft.server.v1_6_R1.*; + +public class SilentContainerChest extends ContainerChest +{ + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) + { + super(i1, i2); + inv = i2; + // close signal + inv.g(); + } + + @Override + public void b(EntityHuman paramEntityHuman) + { + // Don't send close signal twice, might screw up + } +} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java new file mode 100644 index 0000000..6916bcb --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java @@ -0,0 +1,148 @@ +/* + * 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 com.lishid.openinv.internal.v1_6_R1; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.ISpecialEnderChest; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +//Volatile +import net.minecraft.server.v1_6_R1.*; +import org.bukkit.craftbukkit.v1_6_R1.entity.*; +import org.bukkit.craftbukkit.v1_6_R1.inventory.*; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest +{ + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private CraftPlayer owner; + private InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) + { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + OpenInv.enderChests.put(owner.getName().toLowerCase(), this); + } + + public Inventory getBukkitInventory() + { + return inventory; + } + + public void InventoryRemovalCheck() + { + owner.saveData(); + if (transaction.isEmpty() && !playerOnline) + { + OpenInv.enderChests.remove(owner.getName().toLowerCase()); + } + } + + public void PlayerGoOnline(Player p) + { + if (!playerOnline) + { + try + { + InventoryEnderChest playerEnderChest = ((CraftPlayer) 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); + this.InventoryRemovalCheck(); + } + + 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/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java new file mode 100644 index 0000000..259f25a --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java @@ -0,0 +1,297 @@ +/* + * 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 com.lishid.openinv.internal.v1_6_R1; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +//Volatile +import net.minecraft.server.v1_6_R1.*; +import org.bukkit.craftbukkit.v1_6_R1.entity.*; +import org.bukkit.craftbukkit.v1_6_R1.inventory.*; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory +{ + CraftPlayer owner; + public boolean playerOnline = false; + private ItemStack[] extra = new ItemStack[5]; + private CraftInventory inventory = new CraftInventory(this); + + public SpecialPlayerInventory(Player p, Boolean online) + { + super(((CraftPlayer) p).getHandle()); + this.owner = ((CraftPlayer) p); + this.playerOnline = online; + this.items = player.inventory.items; + this.armor = player.inventory.armor; + OpenInv.inventories.put(owner.getName().toLowerCase(), this); + } + + @Override + public Inventory getBukkitInventory() + { + return inventory; + } + + @Override + public void InventoryRemovalCheck() + { + owner.saveData(); + if (transaction.isEmpty() && !playerOnline) + { + OpenInv.inventories.remove(owner.getName().toLowerCase()); + } + } + + @Override + public void PlayerGoOnline(Player player) + { + if (!playerOnline) + { + CraftPlayer p = (CraftPlayer) player; + p.getHandle().inventory.items = this.items; + p.getHandle().inventory.armor = this.armor; + p.saveData(); + playerOnline = true; + } + } + + @Override + public void PlayerGoOffline() + { + playerOnline = false; + this.InventoryRemovalCheck(); + } + + @Override + public void onClose(CraftHumanEntity who) + { + super.onClose(who); + this.InventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() + { + ItemStack[] C = new ItemStack[getSize()]; + System.arraycopy(items, 0, C, 0, items.length); + System.arraycopy(items, 0, C, items.length, armor.length); + return C; + } + + @Override + public int getSize() + { + return super.getSize() + 5; + } + + @Override + public ItemStack getItem(int i) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + return is[i]; + } + + @Override + public ItemStack splitStack(int i, int j) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + if (is[i] != null) + { + ItemStack itemstack; + + if (is[i].count <= j) + { + itemstack = is[i]; + is[i] = null; + return itemstack; + } + else + { + itemstack = is[i].a(j); + if (is[i].count == 0) + { + is[i] = null; + } + + return itemstack; + } + } + else + { + return null; + } + } + + @Override + public ItemStack splitWithoutUpdate(int i) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + if (is[i] != null) + { + ItemStack itemstack = is[i]; + + is[i] = null; + return itemstack; + } + else + { + return null; + } + } + + @Override + public void setItem(int i, ItemStack itemstack) + { + ItemStack[] is = this.items; + + if (i >= is.length) + { + i -= is.length; + is = this.armor; + } + else + { + i = getReversedItemSlotNum(i); + } + + if (i >= is.length) + { + i -= is.length; + is = this.extra; + } + else if (is == this.armor) + { + i = getReversedArmorSlotNum(i); + } + + // Effects + if (is == this.extra) + { + owner.getHandle().drop(itemstack); + itemstack = null; + } + + is[i] = itemstack; + + owner.getHandle().defaultContainer.b(); + } + + private int getReversedItemSlotNum(int i) + { + if (i >= 27) + return i - 27; + else + return i + 9; + } + + private int getReversedArmorSlotNum(int i) + { + if (i == 0) + return 3; + if (i == 1) + return 2; + if (i == 2) + return 1; + if (i == 3) + return 0; + else + return i; + } + + @Override + public String getName() + { + if (player.getName().length() > 16) + { + return player.getName().substring(0, 16); + } + return player.getName(); + } + + @Override + public boolean a(EntityHuman entityhuman) + { + return true; + } +} \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml index 4ff2ffd..f39a561 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: com.lishid.openinv.OpenInv -version: 1.9.8 +version: 2.0.4 author: lishid description: > This plugin allows you to open a player's inventory as a chest and interact with it in real time.