From fb48f6a783eae12e9381fed671921d36839c9901 Mon Sep 17 00:00:00 2001 From: Jikoo Date: Fri, 4 Mar 2016 05:35:30 -0500 Subject: [PATCH] Fix up legacy code to use new interfaces This took way more time than it was worth. Converted line endings to Unix, some other trivial crap. Thanks to Phoenix616 for already having a multi-version pom, it would have taken me much longer to figure out without a functional example. The only legacy code which is not supported is that of the pre-versioned package era. I compiled a copy of Craftbukkit about 15 commits prior to the introduction of versioned packages, and NMS had already been fiddled with. Anyone who needs support for builds in that range can use an older OpenInv build instead, it's not like UUIDs are a big concern. --- .../org.eclipse.ltk.core.refactoring.prefs | 3 - README.MD | 50 ++-- pom.xml | 167 ++++++++++-- src/main/java/com/lishid/openinv/OpenInv.java | 2 +- .../openinv/OpenInvInventoryListener.java | 100 +++---- .../lishid/openinv/OpenInvPlayerListener.java | 256 +++++++++--------- .../java/com/lishid/openinv/Permissions.java | 32 +-- .../openinv/internal/IAnySilentChest.java | 50 ++-- .../openinv/internal/IInventoryAccess.java | 48 ++-- .../openinv/internal/IPlayerDataManager.java | 52 ++-- .../openinv/internal/ISpecialEnderChest.java | 74 ++--- .../internal/ISpecialPlayerInventory.java | 72 ++--- .../openinv/internal/InternalAccessor.java | 228 ++++++++-------- .../internal/v1_4_5/AnySilentChest.java | 120 ++++++++ .../internal/v1_4_5/InventoryAccess.java | 50 ++++ .../internal/v1_4_5/PlayerDataManager.java | 56 ++++ .../internal/v1_4_5/SilentContainerChest.java | 38 +++ .../internal/v1_4_5/SpecialEnderChest.java | 143 ++++++++++ .../v1_4_5/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_4_6/AnySilentChest.java | 120 ++++++++ .../internal/v1_4_6/InventoryAccess.java | 50 ++++ .../internal/v1_4_6/PlayerDataManager.java | 56 ++++ .../internal/v1_4_6/SilentContainerChest.java | 38 +++ .../internal/v1_4_6/SpecialEnderChest.java | 143 ++++++++++ .../v1_4_6/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_4_R1/AnySilentChest.java | 120 ++++++++ .../internal/v1_4_R1/InventoryAccess.java | 50 ++++ .../internal/v1_4_R1/PlayerDataManager.java | 57 ++++ .../v1_4_R1/SilentContainerChest.java | 38 +++ .../internal/v1_4_R1/SpecialEnderChest.java | 143 ++++++++++ .../v1_4_R1/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_5_R2/AnySilentChest.java | 123 +++++++++ .../internal/v1_5_R2/InventoryAccess.java | 50 ++++ .../internal/v1_5_R2/PlayerDataManager.java | 56 ++++ .../v1_5_R2/SilentContainerChest.java | 38 +++ .../internal/v1_5_R2/SpecialEnderChest.java | 143 ++++++++++ .../v1_5_R2/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_5_R3/AnySilentChest.java | 123 +++++++++ .../internal/v1_5_R3/InventoryAccess.java | 50 ++++ .../internal/v1_5_R3/PlayerDataManager.java | 56 ++++ .../v1_5_R3/SilentContainerChest.java | 38 +++ .../internal/v1_5_R3/SpecialEnderChest.java | 143 ++++++++++ .../v1_5_R3/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_6_R1/AnySilentChest.java | 123 +++++++++ .../internal/v1_6_R1/InventoryAccess.java | 50 ++++ .../internal/v1_6_R1/PlayerDataManager.java | 56 ++++ .../v1_6_R1/SilentContainerChest.java | 38 +++ .../internal/v1_6_R1/SpecialEnderChest.java | 143 ++++++++++ .../v1_6_R1/SpecialPlayerInventory.java | 254 +++++++++++++++++ .../internal/v1_6_R2/AnySilentChest.java | 123 +++++++++ .../internal/v1_6_R2/InventoryAccess.java | 50 ++++ .../internal/v1_6_R2/PlayerDataManager.java | 56 ++++ .../v1_6_R2/SilentContainerChest.java | 38 +++ .../internal/v1_6_R2/SpecialEnderChest.java | 143 ++++++++++ .../v1_6_R2/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_6_R3/AnySilentChest.java | 123 +++++++++ .../internal/v1_6_R3/InventoryAccess.java | 50 ++++ .../internal/v1_6_R3/PlayerDataManager.java | 56 ++++ .../v1_6_R3/SilentContainerChest.java | 38 +++ .../internal/v1_6_R3/SpecialEnderChest.java | 143 ++++++++++ .../v1_6_R3/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_7_R1/AnySilentChest.java | 124 +++++++++ .../internal/v1_7_R1/InventoryAccess.java | 50 ++++ .../internal/v1_7_R1/PlayerDataManager.java | 58 ++++ .../v1_7_R1/SilentContainerChest.java | 38 +++ .../internal/v1_7_R1/SpecialEnderChest.java | 143 ++++++++++ .../v1_7_R1/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_7_R2/AnySilentChest.java | 124 +++++++++ .../internal/v1_7_R2/InventoryAccess.java | 50 ++++ .../internal/v1_7_R2/PlayerDataManager.java | 58 ++++ .../v1_7_R2/SilentContainerChest.java | 38 +++ .../internal/v1_7_R2/SpecialEnderChest.java | 143 ++++++++++ .../v1_7_R2/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_7_R3/AnySilentChest.java | 124 +++++++++ .../internal/v1_7_R3/InventoryAccess.java | 50 ++++ .../internal/v1_7_R3/PlayerDataManager.java | 58 ++++ .../v1_7_R3/SilentContainerChest.java | 38 +++ .../internal/v1_7_R3/SpecialEnderChest.java | 143 ++++++++++ .../v1_7_R3/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_7_R4/AnySilentChest.java | 124 +++++++++ .../internal/v1_7_R4/InventoryAccess.java | 73 +++++ .../internal/v1_7_R4/PlayerDataManager.java | 58 ++++ .../v1_7_R4/SilentContainerChest.java | 38 +++ .../internal/v1_7_R4/SpecialEnderChest.java | 143 ++++++++++ .../v1_7_R4/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_8_R1/AnySilentChest.java | 116 ++++++++ .../internal/v1_8_R1/InventoryAccess.java | 73 +++++ .../internal/v1_8_R1/PlayerDataManager.java | 57 ++++ .../v1_8_R1/SilentContainerChest.java | 38 +++ .../internal/v1_8_R1/SpecialEnderChest.java | 142 ++++++++++ .../v1_8_R1/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_8_R2/AnySilentChest.java | 116 ++++++++ .../internal/v1_8_R2/InventoryAccess.java | 74 +++++ .../internal/v1_8_R2/PlayerDataManager.java | 58 ++++ .../v1_8_R2/SilentContainerChest.java | 38 +++ .../internal/v1_8_R2/SpecialEnderChest.java | 142 ++++++++++ .../v1_8_R2/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_8_R3/AnySilentChest.java | 116 ++++++++ .../internal/v1_8_R3/InventoryAccess.java | 74 +++++ .../internal/v1_8_R3/PlayerDataManager.java | 58 ++++ .../v1_8_R3/SilentContainerChest.java | 38 +++ .../internal/v1_8_R3/SpecialEnderChest.java | 142 ++++++++++ .../v1_8_R3/SpecialPlayerInventory.java | 253 +++++++++++++++++ .../internal/v1_9_R1/AnySilentChest.java | 8 +- .../internal/v1_9_R1/InventoryAccess.java | 7 +- .../internal/v1_9_R1/PlayerDataManager.java | 97 +------ .../v1_9_R1/SilentContainerChest.java | 4 +- .../internal/v1_9_R1/SpecialEnderChest.java | 14 +- .../v1_9_R1/SpecialPlayerInventory.java | 12 +- src/main/resources/plugin.yml | 78 +++--- 110 files changed, 10717 insertions(+), 662 deletions(-) delete mode 100644 .settings/org.eclipse.ltk.core.refactoring.prefs create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_5/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_5/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_6/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_6/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_R1/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_R1/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R2/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R2/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R3/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R3/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R1/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R1/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R2/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R2/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R3/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R3/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R4/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R1/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R1/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R3/InventoryAccess.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R3/SilentContainerChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java create mode 100644 src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs deleted file mode 100644 index 5634a95d..00000000 --- a/.settings/org.eclipse.ltk.core.refactoring.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Wed Jun 01 17:38:54 EDT 2011 -eclipse.preferences.version=1 -org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/README.MD b/README.MD index 8536e488..170d2d17 100644 --- a/README.MD +++ b/README.MD @@ -1,26 +1,26 @@ -## Goals -This fork of OpenInv was created when the lag caused by offline player lookups post-UUID migration became too much to bear. Overall, it does not differ much from the original. - -### Changes of Note -- Removed updater -- Removed wand - -## Previous Versions -Any version of Minecraft this fork has been existent for should have a [release](https://github.com/Jikoo/OpenInv/releases) tagged. Features are not backported, however. - -## License -``` -Copyright (C) 2011-2014 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 . +## Goals +This fork of OpenInv was created when the lag caused by offline player lookups post-UUID migration became too much to bear. Overall, it does not differ much from the original. + +### Changes of Note +- Removed updater +- Removed wand + +## Previous Versions +Any version of Minecraft this fork has been existent for should have a [release](https://github.com/Jikoo/OpenInv/releases) tagged. Features are not backported, however. + +## License +``` +Copyright (C) 2011-2014 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 . ``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5d02ec4b..39fba579 100644 --- a/pom.xml +++ b/pom.xml @@ -1,28 +1,141 @@ - - 4.0.0 - OpenInv - OpenInv - 0.0.1-SNAPSHOT - - - - org.spigotmc - spigot - 1.9-R0.1-SNAPSHOT - provided - - - - - - - maven-compiler-plugin - 3.1 - - 1.6 - 1.6 - - - - + + 4.0.0 + OpenInv + OpenInv + 0.0.1-SNAPSHOT + + + + org.spigotmc + spigot + 1.9-R0.1-SNAPSHOT + provided + v1_9_R1 + + + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + v1_8_R3 + + + org.spigotmc + spigot + 1.8.3-R0.1-SNAPSHOT + provided + v1_8_R2 + + + org.spigotmc + spigot + 1.8-R0.1-SNAPSHOT + provided + v1_8_R1 + + + org.bukkit + craftbukkit + 1.7.10-R0.1-SNAPSHOT + provided + v1_7_R4 + + + org.bukkit + craftbukkit + 1.7.9-R0.2-SNAPSHOT + provided + v1_7_R3 + + + org.bukkit + craftbukkit + 1.7.5-R0.1-SNAPSHOT + provided + v1_7_R2 + + + org.bukkit + craftbukkit + 1.7.2-R0.4-SNAPSHOT + provided + v1_7_R1 + + + org.bukkit + craftbukkit + 1.6.4-R2.0-SNAPSHOT + provided + v1_6_R3 + + + org.bukkit + craftbukkit + 1.6.2-R1.1-SNAPSHOT + provided + v1_6_R2 + + + org.bukkit + craftbukkit + 1.6.1-R0.1-SNAPSHOT + provided + v1_6_R1 + + + org.bukkit + craftbukkit + 1.5.2-R1.0-SNAPSHOT + provided + v1_5_R3 + + + org.bukkit + craftbukkit + 1.5.1-R0.1-SNAPSHOT + provided + v1_5_R2 + + + org.bukkit + craftbukkit + 1.5-R0.1-SNAPSHOT + provided + v1_5_R1 + + + org.bukkit + craftbukkit + 1.4.7-R1.1-SNAPSHOT + provided + v1_4_R1 + + + org.bukkit + craftbukkit + 1.4.6-R0.4-SNAPSHOT + provided + v1_4_6 + + + org.bukkit + craftbukkit + 1.4.5-R1.1-SNAPSHOT + provided + v1_4_5 + + + + + + + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + \ No newline at end of file diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index aaea98c7..c27cd90f 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -217,4 +217,4 @@ public static boolean hasPermission(Permissible player, String permission) { } return player.hasPermission(permission); } -} \ No newline at end of file +} diff --git a/src/main/java/com/lishid/openinv/OpenInvInventoryListener.java b/src/main/java/com/lishid/openinv/OpenInvInventoryListener.java index 5ff6ded8..9b2ef0f9 100644 --- a/src/main/java/com/lishid/openinv/OpenInvInventoryListener.java +++ b/src/main/java/com/lishid/openinv/OpenInvInventoryListener.java @@ -1,50 +1,50 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryDragEvent; - -public class OpenInvInventoryListener implements Listener { - - private final OpenInv plugin; - - public OpenInvInventoryListener(OpenInv plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onInventoryClick(InventoryClickEvent event) { - // If this is the top inventory - // if (event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot()) - // { - if (!plugin.getInventoryAccess().check(event.getInventory(), event.getWhoClicked())) { - event.setCancelled(true); - } - // } - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onInventoryDrag(InventoryDragEvent event) { - if (!plugin.getInventoryAccess().check(event.getInventory(), event.getWhoClicked())) { - event.setCancelled(true); - } - } -} \ No newline at end of file +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; + +public class OpenInvInventoryListener implements Listener { + + private final OpenInv plugin; + + public OpenInvInventoryListener(OpenInv plugin) { + this.plugin = plugin; + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onInventoryClick(InventoryClickEvent event) { + // If this is the top inventory + // if (event.getView().convertSlot(event.getRawSlot()) == event.getRawSlot()) + // { + if (!plugin.getInventoryAccess().check(event.getInventory(), event.getWhoClicked())) { + event.setCancelled(true); + } + // } + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onInventoryDrag(InventoryDragEvent event) { + if (!plugin.getInventoryAccess().check(event.getInventory(), event.getWhoClicked())) { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java b/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java index 907caef0..97d5050e 100644 --- a/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java +++ b/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java @@ -1,128 +1,128 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.ChatColor; -import org.bukkit.block.Chest; -import org.bukkit.entity.Player; -import org.bukkit.event.Event.Result; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -import com.lishid.openinv.internal.ISpecialEnderChest; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -public class OpenInvPlayerListener implements Listener { - - private final OpenInv plugin; - - public OpenInvPlayerListener(OpenInv plugin) { - this.plugin = plugin; - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerJoin(PlayerJoinEvent event) { - ISpecialPlayerInventory inventory = plugin.getInventoryFor(event.getPlayer()); - - if (inventory != null) { - inventory.setPlayerOnline(event.getPlayer()); - } - - ISpecialEnderChest chest = plugin.getEnderChestFor(event.getPlayer()); - - if (chest != null) { - chest.setPlayerOnline(event.getPlayer()); - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerQuit(PlayerQuitEvent event) { - ISpecialPlayerInventory inventory = plugin.getInventoryFor(event.getPlayer()); - if (inventory != null) { - if (inventory.setPlayerOffline()) { - plugin.removeLoadedInventory(event.getPlayer()); - } - } - ISpecialEnderChest chest = plugin.getEnderChestFor(event.getPlayer()); - if (chest != null) { - if (chest.setPlayerOffline()) { - plugin.removeLoadedEnderChest(event.getPlayer()); - } - } - } - - @EventHandler(priority = EventPriority.MONITOR) - public void onPlayerInteract(PlayerInteractEvent event) { - Player player = event.getPlayer(); - - if (event.getPlayer().isSneaking()) { - return; - } - - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) { - return; - } - - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) { - if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) { - event.setCancelled(true); - player.openInventory(player.getEnderChest()); - } - } - - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest) { - boolean silentchest = false; - boolean anychest = false; - int x = event.getClickedBlock().getX(); - int y = event.getClickedBlock().getY(); - int z = event.getClickedBlock().getZ(); - - if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) { - silentchest = true; - } - - if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && plugin.getPlayerAnyChestStatus(player)) { - try { - anychest = plugin.getAnySilentChest().isAnyChestNeeded(player, x, y, z); - } - catch (Exception e) { - player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit."); - e.printStackTrace(); - } - } - - // If the anychest or silentchest is active - if (anychest || silentchest) { - if (!plugin.getAnySilentChest().activateChest(player, anychest, silentchest, x, y, z)) { - if (silentchest && plugin.notifySilentChest()) { - player.sendMessage("You are opening a chest silently."); - } - if (anychest && plugin.notifyAnyChest()) { - player.sendMessage("You are opening a blocked chest."); - } - event.setCancelled(true); - } - } - } - } - -} +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.ChatColor; +import org.bukkit.block.Chest; +import org.bukkit.entity.Player; +import org.bukkit.event.Event.Result; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.lishid.openinv.internal.ISpecialEnderChest; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +public class OpenInvPlayerListener implements Listener { + + private final OpenInv plugin; + + public OpenInvPlayerListener(OpenInv plugin) { + this.plugin = plugin; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerJoin(PlayerJoinEvent event) { + ISpecialPlayerInventory inventory = plugin.getInventoryFor(event.getPlayer()); + + if (inventory != null) { + inventory.setPlayerOnline(event.getPlayer()); + } + + ISpecialEnderChest chest = plugin.getEnderChestFor(event.getPlayer()); + + if (chest != null) { + chest.setPlayerOnline(event.getPlayer()); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent event) { + ISpecialPlayerInventory inventory = plugin.getInventoryFor(event.getPlayer()); + if (inventory != null) { + if (inventory.setPlayerOffline()) { + plugin.removeLoadedInventory(event.getPlayer()); + } + } + ISpecialEnderChest chest = plugin.getEnderChestFor(event.getPlayer()); + if (chest != null) { + if (chest.setPlayerOffline()) { + plugin.removeLoadedEnderChest(event.getPlayer()); + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerInteract(PlayerInteractEvent event) { + Player player = event.getPlayer(); + + if (event.getPlayer().isSneaking()) { + return; + } + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) { + return; + } + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) { + if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) { + event.setCancelled(true); + player.openInventory(player.getEnderChest()); + } + } + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest) { + boolean silentchest = false; + boolean anychest = false; + int x = event.getClickedBlock().getX(); + int y = event.getClickedBlock().getY(); + int z = event.getClickedBlock().getZ(); + + if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) { + silentchest = true; + } + + if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && plugin.getPlayerAnyChestStatus(player)) { + try { + anychest = plugin.getAnySilentChest().isAnyChestNeeded(player, x, y, z); + } + catch (Exception e) { + player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit."); + e.printStackTrace(); + } + } + + // If the anychest or silentchest is active + if (anychest || silentchest) { + if (!plugin.getAnySilentChest().activateChest(player, anychest, silentchest, x, y, z)) { + if (silentchest && plugin.notifySilentChest()) { + player.sendMessage("You are opening a chest silently."); + } + if (anychest && plugin.notifyAnyChest()) { + player.sendMessage("You are opening a blocked chest."); + } + event.setCancelled(true); + } + } + } + } + +} diff --git a/src/main/java/com/lishid/openinv/Permissions.java b/src/main/java/com/lishid/openinv/Permissions.java index f0de7750..4956c17f 100644 --- a/src/main/java/com/lishid/openinv/Permissions.java +++ b/src/main/java/com/lishid/openinv/Permissions.java @@ -1,16 +1,16 @@ -package com.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_ENDERCHEST_ALL = "OpenInv.openenderall"; - public static final String PERM_SEARCH = "OpenInv.search"; - public static final String PERM_EDITINV = "OpenInv.editinv"; - public static final String PERM_EDITENDER = "OpenInv.editender"; - public static final String PERM_OPENSELF = "OpenInv.openself"; -} +package com.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_ENDERCHEST_ALL = "OpenInv.openenderall"; + public static final String PERM_SEARCH = "OpenInv.search"; + public static final String PERM_EDITINV = "OpenInv.editinv"; + public static final String PERM_EDITENDER = "OpenInv.editender"; + public static final String PERM_OPENSELF = "OpenInv.openself"; +} diff --git a/src/main/java/com/lishid/openinv/internal/IAnySilentChest.java b/src/main/java/com/lishid/openinv/internal/IAnySilentChest.java index 5aac4221..10ccaa5a 100644 --- a/src/main/java/com/lishid/openinv/internal/IAnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/IAnySilentChest.java @@ -1,25 +1,25 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.entity.Player; - -public interface IAnySilentChest { - public boolean isAnyChestNeeded(Player player, int x, int y, int z); - - public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z); -} +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.entity.Player; + +public interface IAnySilentChest { + public boolean isAnyChestNeeded(Player player, int x, int y, int z); + + public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z); +} diff --git a/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java b/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java index f49c1688..ed47174b 100644 --- a/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java +++ b/src/main/java/com/lishid/openinv/internal/IInventoryAccess.java @@ -1,24 +1,24 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -public interface IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player); -} +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +public interface IInventoryAccess { + public boolean check(Inventory inventory, HumanEntity player); +} diff --git a/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java index b1aaf4bc..f0c34f3c 100644 --- a/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java @@ -1,26 +1,26 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -public interface IPlayerDataManager { - public Player loadPlayer(OfflinePlayer offline); - - public String getPlayerDataID(OfflinePlayer player); -} +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public interface IPlayerDataManager { + public Player loadPlayer(OfflinePlayer offline); + + public String getPlayerDataID(OfflinePlayer player); +} diff --git a/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java index 56c7e998..9378c926 100644 --- a/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java @@ -1,37 +1,37 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -public interface ISpecialEnderChest { - - public Inventory getBukkitInventory(); - - public boolean inventoryRemovalCheck(); - - public void setPlayerOnline(Player p); - - /** - * Sets the Player associated with this ISpecialEnderChest offline. - * - * @return true if the ISpecialEnderChest is eligible for removal - */ - public boolean setPlayerOffline(); - -} +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +public interface ISpecialEnderChest { + + public Inventory getBukkitInventory(); + + public boolean inventoryRemovalCheck(); + + public void setPlayerOnline(Player p); + + /** + * Sets the Player associated with this ISpecialEnderChest offline. + * + * @return true if the ISpecialEnderChest is eligible for removal + */ + public boolean setPlayerOffline(); + +} diff --git a/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java index a0e72818..f8ef50b2 100644 --- a/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java @@ -1,36 +1,36 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -public interface ISpecialPlayerInventory { - - public Inventory getBukkitInventory(); - - public boolean inventoryRemovalCheck(); - - public void setPlayerOnline(Player player); - - /** - * Sets the Player associated with this ISpecialPlayerInventory offline. - * - * @return true if the ISpecialPlayerInventory is eligible for removal - */ - public boolean setPlayerOffline(); -} +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +public interface ISpecialPlayerInventory { + + public Inventory getBukkitInventory(); + + public boolean inventoryRemovalCheck(); + + public void setPlayerOnline(Player player); + + /** + * Sets the Player associated with this ISpecialPlayerInventory offline. + * + * @return true if the ISpecialPlayerInventory is eligible for removal + */ + public boolean setPlayerOffline(); +} diff --git a/src/main/java/com/lishid/openinv/internal/InternalAccessor.java b/src/main/java/com/lishid/openinv/internal/InternalAccessor.java index 1c895052..8ed39698 100644 --- a/src/main/java/com/lishid/openinv/internal/InternalAccessor.java +++ b/src/main/java/com/lishid/openinv/internal/InternalAccessor.java @@ -1,114 +1,114 @@ -/* - * Copyright (C) 2011-2014 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; - -import org.bukkit.Server; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; - -public class InternalAccessor { - - private final OpenInv plugin; - - private String version; - - public InternalAccessor(OpenInv plugin) { - this.plugin = plugin; - } - - /** - * Check if the current server version is supported, and, if it is, prepare to load version-specific code. - * - * @param server the Server - * - * @return true if supported - */ - public boolean initialize(Server server) { - String packageName = server.getClass().getPackage().getName(); - version = packageName.substring(packageName.lastIndexOf('.') + 1); - - try { - Class.forName("com.lishid.openinv.internal." + version + ".AnySilentChest"); - return true; - } - catch (Exception e) { - return false; - } - } - - private void printErrorMessage() { - plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv."); - } - - public IPlayerDataManager newPlayerDataManager() { - return (IPlayerDataManager) createObject(IPlayerDataManager.class, "PlayerDataManager"); - } - - public IInventoryAccess newInventoryAccess() { - return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess"); - } - - public IAnySilentChest newAnySilentChest() { - return (IAnySilentChest) createObject(IAnySilentChest.class, "AnySilentChest"); - } - - public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) { - try { - Class internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialPlayerInventory"); - if (ISpecialPlayerInventory.class.isAssignableFrom(internalClass)) { - return (ISpecialPlayerInventory) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline); - } - } - catch (Exception e) { - printErrorMessage(); - e.printStackTrace(); - } - - return null; - } - - public ISpecialEnderChest newSpecialEnderChest(Player player, boolean offline) { - try { - Class internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialEnderChest"); - if (ISpecialEnderChest.class.isAssignableFrom(internalClass)) { - return (ISpecialEnderChest) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline); - } - } - catch (Exception e) { - printErrorMessage(); - e.printStackTrace(); - } - - return null; - } - - private Object createObject(Class assignableClass, String className) { - try { - Class internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className); - if (assignableClass.isAssignableFrom(internalClass)) { - return internalClass.getConstructor().newInstance(); - } - } - catch (Exception e) { - printErrorMessage(); - e.printStackTrace(); - } - - return null; - } -} +/* + * Copyright (C) 2011-2014 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; + +import org.bukkit.Server; +import org.bukkit.entity.Player; + +import com.lishid.openinv.OpenInv; + +public class InternalAccessor { + + private final OpenInv plugin; + + private String version; + + public InternalAccessor(OpenInv plugin) { + this.plugin = plugin; + } + + /** + * Check if the current server version is supported, and, if it is, prepare to load version-specific code. + * + * @param server the Server + * + * @return true if supported + */ + public boolean initialize(Server server) { + String packageName = server.getClass().getPackage().getName(); + version = packageName.substring(packageName.lastIndexOf('.') + 1); + + try { + Class.forName("com.lishid.openinv.internal." + version + ".AnySilentChest"); + return true; + } + catch (Exception e) { + return false; + } + } + + private void printErrorMessage() { + plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv."); + } + + public IPlayerDataManager newPlayerDataManager() { + return (IPlayerDataManager) createObject(IPlayerDataManager.class, "PlayerDataManager"); + } + + public IInventoryAccess newInventoryAccess() { + return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess"); + } + + public IAnySilentChest newAnySilentChest() { + return (IAnySilentChest) createObject(IAnySilentChest.class, "AnySilentChest"); + } + + public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) { + try { + Class internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialPlayerInventory"); + if (ISpecialPlayerInventory.class.isAssignableFrom(internalClass)) { + return (ISpecialPlayerInventory) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline); + } + } + catch (Exception e) { + printErrorMessage(); + e.printStackTrace(); + } + + return null; + } + + public ISpecialEnderChest newSpecialEnderChest(Player player, boolean offline) { + try { + Class internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialEnderChest"); + if (ISpecialEnderChest.class.isAssignableFrom(internalClass)) { + return (ISpecialEnderChest) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline); + } + } + catch (Exception e) { + printErrorMessage(); + e.printStackTrace(); + } + + return null; + } + + private Object createObject(Class assignableClass, String className) { + try { + Class internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className); + if (assignableClass.isAssignableFrom(internalClass)) { + return internalClass.getConstructor().newInstance(); + } + } + catch (Exception e) { + printErrorMessage(); + e.printStackTrace(); + } + + return null; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java new file mode 100644 index 00000000..7eff2d21 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2011-2014 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_4_5; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +// Volatile +import net.minecraft.server.v1_4_5.Block; +import net.minecraft.server.v1_4_5.EntityPlayer; +import net.minecraft.server.v1_4_5.IInventory; +import net.minecraft.server.v1_4_5.InventoryLargeChest; +import net.minecraft.server.v1_4_5.Packet100OpenWindow; +import net.minecraft.server.v1_4_5.TileEntityChest; +import net.minecraft.server.v1_4_5.World; + +import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.s(x, y + 1, z)) + return true; + + // If block next to chest is chest and has a block on top + if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(x, y, z); + if (chest == null) + return true; + + if (!anychest) { + if (world.s(x, y + 1, z)) + return true; + if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) + return true; + } + + if (world.getTypeId(x - 1, y, z) == Block.CHEST.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) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (world.getTypeId(x, y, z - 1) == Block.CHEST.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) + 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 id = 0; + try { + Field windowID = player.getClass().getDeclaredField("containerCounter"); + windowID.setAccessible(true); + id = windowID.getInt(player); + id = id % 100 + 1; + 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/InventoryAccess.java new file mode 100644 index 00000000..3b1323b4 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_4_5; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_4_5.IInventory; + +import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java new file mode 100644 index 00000000..d3c7ec85 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011-2014 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_4_5; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_4_5.EntityPlayer; +import net.minecraft.server.v1_4_5.ItemInWorldManager; +import net.minecraft.server.v1_4_5.MinecraftServer; + +import org.bukkit.craftbukkit.v1_4_5.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new ItemInWorldManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/SilentContainerChest.java new file mode 100644 index 00000000..6c77e5d1 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_4_5; + +// Volatile +import net.minecraft.server.v1_4_5.ContainerChest; +import net.minecraft.server.v1_4_5.EntityHuman; +import net.minecraft.server.v1_4_5.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) { + super(i1, i2); + inv = i2; + // close signal + inv.f(); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java new file mode 100644 index 00000000..820e4012 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_4_5; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_4_5.EntityHuman; +import net.minecraft.server.v1_4_5.IInventory; +import net.minecraft.server.v1_4_5.InventoryEnderChest; +import net.minecraft.server.v1_4_5.InventorySubcontainer; +import net.minecraft.server.v1_4_5.ItemStack; + +import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return this.inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + @Override + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java new file mode 100644 index 00000000..326a2e47 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_4_5; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_4_5.EntityHuman; +import net.minecraft.server.v1_4_5.ItemStack; +import net.minecraft.server.v1_4_5.PlayerInventory; + +import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java new file mode 100644 index 00000000..af8c2eaa --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2011-2014 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_4_6; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +import net.minecraft.server.v1_4_6.Block; +import net.minecraft.server.v1_4_6.EntityPlayer; +import net.minecraft.server.v1_4_6.IInventory; +import net.minecraft.server.v1_4_6.InventoryLargeChest; +import net.minecraft.server.v1_4_6.Packet100OpenWindow; +import net.minecraft.server.v1_4_6.TileEntityChest; +import net.minecraft.server.v1_4_6.World; + +// Volatile +import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.s(x, y + 1, z)) + return true; + + // If block next to chest is chest and has a block on top + if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(x, y, z); + if (chest == null) + return true; + + if (!anychest) { + if (world.s(x, y + 1, z)) + return true; + if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) + return true; + } + + if (world.getTypeId(x - 1, y, z) == Block.CHEST.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) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (world.getTypeId(x, y, z - 1) == Block.CHEST.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) + 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 id = 0; + try { + Field windowID = player.getClass().getDeclaredField("containerCounter"); + windowID.setAccessible(true); + id = windowID.getInt(player); + id = id % 100 + 1; + 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/InventoryAccess.java new file mode 100644 index 00000000..124cad28 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_4_6; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +import net.minecraft.server.v1_4_6.IInventory; + +// Volatile +import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java new file mode 100644 index 00000000..6ae3b417 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011-2014 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_4_6; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_4_6.EntityPlayer; +import net.minecraft.server.v1_4_6.MinecraftServer; +import net.minecraft.server.v1_4_6.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_4_6.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/SilentContainerChest.java new file mode 100644 index 00000000..368b4827 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_4_6; + +// Volatile +import net.minecraft.server.v1_4_6.ContainerChest; +import net.minecraft.server.v1_4_6.EntityHuman; +import net.minecraft.server.v1_4_6.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) { + super(i1, i2); + inv = i2; + // close signal + inv.f(); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java new file mode 100644 index 00000000..21968b26 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_4_6; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_4_6.EntityHuman; +import net.minecraft.server.v1_4_6.IInventory; +import net.minecraft.server.v1_4_6.InventoryEnderChest; +import net.minecraft.server.v1_4_6.InventorySubcontainer; +import net.minecraft.server.v1_4_6.ItemStack; + +import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + @Override + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java new file mode 100644 index 00000000..b2e3b576 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_4_6; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_4_6.EntityHuman; +import net.minecraft.server.v1_4_6.ItemStack; +import net.minecraft.server.v1_4_6.PlayerInventory; + +import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java new file mode 100644 index 00000000..250c2e0c --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2011-2014 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_4_R1; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +import net.minecraft.server.v1_4_R1.Block; +import net.minecraft.server.v1_4_R1.EntityPlayer; +import net.minecraft.server.v1_4_R1.IInventory; +import net.minecraft.server.v1_4_R1.InventoryLargeChest; +import net.minecraft.server.v1_4_R1.Packet100OpenWindow; +import net.minecraft.server.v1_4_R1.TileEntityChest; +import net.minecraft.server.v1_4_R1.World; + +// Volatile +import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.s(x, y + 1, z)) + return true; + + // If block next to chest is chest and has a block on top + if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(x, y, z); + if (chest == null) + return true; + + if (!anychest) { + if (world.s(x, y + 1, z)) + return true; + if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) + return true; + if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) + return true; + if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) + return true; + if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) + return true; + } + + if (world.getTypeId(x - 1, y, z) == Block.CHEST.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) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (world.getTypeId(x, y, z - 1) == Block.CHEST.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) + 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 id = 0; + try { + Field windowID = player.getClass().getDeclaredField("containerCounter"); + windowID.setAccessible(true); + id = windowID.getInt(player); + id = id % 100 + 1; + 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/InventoryAccess.java new file mode 100644 index 00000000..5c499d50 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_4_R1; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +import net.minecraft.server.v1_4_R1.IInventory; + +// Volatile +import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java new file mode 100644 index 00000000..15f72724 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2014 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_4_R1; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +import net.minecraft.server.v1_4_R1.EntityPlayer; +import net.minecraft.server.v1_4_R1.MinecraftServer; +import net.minecraft.server.v1_4_R1.PlayerInteractManager; + +// Volatile +import org.bukkit.craftbukkit.v1_4_R1.CraftServer; + + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SilentContainerChest.java new file mode 100644 index 00000000..b9715a12 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_4_R1; + +// Volatile +import net.minecraft.server.v1_4_R1.ContainerChest; +import net.minecraft.server.v1_4_R1.EntityHuman; +import net.minecraft.server.v1_4_R1.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) { + super(i1, i2); + inv = i2; + // close signal + inv.f(); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java new file mode 100644 index 00000000..11a6a1ef --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_4_R1; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +// Volatile +import com.lishid.openinv.internal.ISpecialEnderChest; + +import net.minecraft.server.v1_4_R1.EntityHuman; +import net.minecraft.server.v1_4_R1.IInventory; +import net.minecraft.server.v1_4_R1.InventoryEnderChest; +import net.minecraft.server.v1_4_R1.InventorySubcontainer; +import net.minecraft.server.v1_4_R1.ItemStack; + +import org.bukkit.craftbukkit.v1_4_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + @Override + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java new file mode 100644 index 00000000..c85aebfd --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_4_R1; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +import net.minecraft.server.v1_4_R1.EntityHuman; +import net.minecraft.server.v1_4_R1.ItemStack; +import net.minecraft.server.v1_4_R1.PlayerInventory; + +// Volatile +import org.bukkit.craftbukkit.v1_4_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java new file mode 100644 index 00000000..0006dd88 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +// Volatile +import net.minecraft.server.v1_5_R2.EntityPlayer; +import net.minecraft.server.v1_5_R2.IInventory; +import net.minecraft.server.v1_5_R2.InventoryLargeChest; +import net.minecraft.server.v1_5_R2.Packet100OpenWindow; +import net.minecraft.server.v1_5_R2.TileEntityChest; +import net.minecraft.server.v1_5_R2.World; + +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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; + } + + @Override + 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 = 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java new file mode 100644 index 00000000..a6182bf3 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_5_R2.IInventory; + +import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java new file mode 100644 index 00000000..b6ea8a00 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_5_R2.EntityPlayer; +import net.minecraft.server.v1_5_R2.MinecraftServer; +import net.minecraft.server.v1_5_R2.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_5_R2.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java new file mode 100644 index 00000000..c6d9307e --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +// Volatile +import net.minecraft.server.v1_5_R2.ContainerChest; +import net.minecraft.server.v1_5_R2.EntityHuman; +import net.minecraft.server.v1_5_R2.IInventory; + +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 + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java new file mode 100644 index 00000000..458e8326 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_5_R2.EntityHuman; +import net.minecraft.server.v1_5_R2.IInventory; +import net.minecraft.server.v1_5_R2.InventoryEnderChest; +import net.minecraft.server.v1_5_R2.InventorySubcontainer; +import net.minecraft.server.v1_5_R2.ItemStack; + +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final 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(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java new file mode 100644 index 00000000..d307c335 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_5_R2.EntityHuman; +import net.minecraft.server.v1_5_R2.ItemStack; +import net.minecraft.server.v1_5_R2.PlayerInventory; + +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java new file mode 100644 index 00000000..1572aa91 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2011-2014 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.internal.IAnySilentChest; + +//Volatile +import net.minecraft.server.v1_5_R3.EntityPlayer; +import net.minecraft.server.v1_5_R3.IInventory; +import net.minecraft.server.v1_5_R3.InventoryLargeChest; +import net.minecraft.server.v1_5_R3.Packet100OpenWindow; +import net.minecraft.server.v1_5_R3.TileEntityChest; +import net.minecraft.server.v1_5_R3.World; + +import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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; + } + + @Override + 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 = 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java new file mode 100644 index 00000000..582725f1 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_5_R3.IInventory; + +import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java new file mode 100644 index 00000000..679411fb --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011-2014 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.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_5_R3.EntityPlayer; +import net.minecraft.server.v1_5_R3.MinecraftServer; +import net.minecraft.server.v1_5_R3.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_5_R3.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java new file mode 100644 index 00000000..177c4f59 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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.ContainerChest; +import net.minecraft.server.v1_5_R3.EntityHuman; +import net.minecraft.server.v1_5_R3.IInventory; + +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 + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java new file mode 100644 index 00000000..c8d37e20 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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 org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_5_R3.EntityHuman; +import net.minecraft.server.v1_5_R3.IInventory; +import net.minecraft.server.v1_5_R3.InventoryEnderChest; +import net.minecraft.server.v1_5_R3.InventorySubcontainer; +import net.minecraft.server.v1_5_R3.ItemStack; + +import org.bukkit.craftbukkit.v1_5_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final 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(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java new file mode 100644 index 00000000..79e4fa06 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_5_R3.EntityHuman; +import net.minecraft.server.v1_5_R3.ItemStack; +import net.minecraft.server.v1_5_R3.PlayerInventory; + +import org.bukkit.craftbukkit.v1_5_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java new file mode 100644 index 00000000..c93d76dc --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2011-2014 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.internal.IAnySilentChest; + +// Volatile +import net.minecraft.server.v1_6_R1.EntityPlayer; +import net.minecraft.server.v1_6_R1.IInventory; +import net.minecraft.server.v1_6_R1.InventoryLargeChest; +import net.minecraft.server.v1_6_R1.Packet100OpenWindow; +import net.minecraft.server.v1_6_R1.TileEntityChest; +import net.minecraft.server.v1_6_R1.World; + +import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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; + } + + @Override + 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 = 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java new file mode 100644 index 00000000..640556f6 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_6_R1.IInventory; + +import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java new file mode 100644 index 00000000..a73798ce --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011-2014 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.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_6_R1.EntityPlayer; +import net.minecraft.server.v1_6_R1.MinecraftServer; +import net.minecraft.server.v1_6_R1.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_6_R1.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java new file mode 100644 index 00000000..6373beec --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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.ContainerChest; +import net.minecraft.server.v1_6_R1.EntityHuman; +import net.minecraft.server.v1_6_R1.IInventory; + +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 + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java new file mode 100644 index 00000000..c21e7ff3 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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 org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_6_R1.EntityHuman; +import net.minecraft.server.v1_6_R1.IInventory; +import net.minecraft.server.v1_6_R1.InventoryEnderChest; +import net.minecraft.server.v1_6_R1.InventorySubcontainer; +import net.minecraft.server.v1_6_R1.ItemStack; + +import org.bukkit.craftbukkit.v1_6_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final 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(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java new file mode 100644 index 00000000..833f8137 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2011-2014 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.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_6_R1.EntityHuman; +import net.minecraft.server.v1_6_R1.ItemStack; +import net.minecraft.server.v1_6_R1.PlayerInventory; + +import org.bukkit.craftbukkit.v1_6_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory; + + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentChest.java new file mode 100644 index 00000000..d69ec499 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/AnySilentChest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +// Volatile +import net.minecraft.server.v1_6_R2.EntityPlayer; +import net.minecraft.server.v1_6_R2.IInventory; +import net.minecraft.server.v1_6_R2.InventoryLargeChest; +import net.minecraft.server.v1_6_R2.Packet100OpenWindow; +import net.minecraft.server.v1_6_R2.TileEntityChest; +import net.minecraft.server.v1_6_R2.World; + +import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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; + } + + @Override + 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 = 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/InventoryAccess.java new file mode 100644 index 00000000..338887b2 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_6_R2.IInventory; + +import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java new file mode 100644 index 00000000..351aec59 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_6_R2.EntityPlayer; +import net.minecraft.server.v1_6_R2.MinecraftServer; +import net.minecraft.server.v1_6_R2.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_6_R2.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SilentContainerChest.java new file mode 100644 index 00000000..82b2525a --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +// Volatile +import net.minecraft.server.v1_6_R2.ContainerChest; +import net.minecraft.server.v1_6_R2.EntityHuman; +import net.minecraft.server.v1_6_R2.IInventory; + +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 + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java new file mode 100644 index 00000000..ac62c7c9 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_6_R2.EntityHuman; +import net.minecraft.server.v1_6_R2.IInventory; +import net.minecraft.server.v1_6_R2.InventoryEnderChest; +import net.minecraft.server.v1_6_R2.InventorySubcontainer; +import net.minecraft.server.v1_6_R2.ItemStack; + +import org.bukkit.craftbukkit.v1_6_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final 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(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java new file mode 100644 index 00000000..0b4a5bb7 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_R2; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_6_R2.EntityHuman; +import net.minecraft.server.v1_6_R2.ItemStack; +import net.minecraft.server.v1_6_R2.PlayerInventory; + +import org.bukkit.craftbukkit.v1_6_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentChest.java new file mode 100644 index 00000000..619375b0 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/AnySilentChest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2011-2014 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_R3; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +// Volatile +import net.minecraft.server.v1_6_R3.EntityPlayer; +import net.minecraft.server.v1_6_R3.IInventory; +import net.minecraft.server.v1_6_R3.InventoryLargeChest; +import net.minecraft.server.v1_6_R3.Packet100OpenWindow; +import net.minecraft.server.v1_6_R3.TileEntityChest; +import net.minecraft.server.v1_6_R3.World; + +import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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; + } + + @Override + 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 = 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); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/InventoryAccess.java new file mode 100644 index 00000000..b66e71d7 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_R3; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_6_R3.IInventory; + +import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java new file mode 100644 index 00000000..d340d47d --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011-2014 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_R3; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_6_R3.EntityPlayer; +import net.minecraft.server.v1_6_R3.MinecraftServer; +import net.minecraft.server.v1_6_R3.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_6_R3.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(), new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SilentContainerChest.java new file mode 100644 index 00000000..bf2f2137 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_R3; + +// Volatile +import net.minecraft.server.v1_6_R3.ContainerChest; +import net.minecraft.server.v1_6_R3.EntityHuman; +import net.minecraft.server.v1_6_R3.IInventory; + +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 + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java new file mode 100644 index 00000000..a4ea88d1 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_R3; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_6_R3.EntityHuman; +import net.minecraft.server.v1_6_R3.IInventory; +import net.minecraft.server.v1_6_R3.InventoryEnderChest; +import net.minecraft.server.v1_6_R3.InventorySubcontainer; +import net.minecraft.server.v1_6_R3.ItemStack; + +import org.bukkit.craftbukkit.v1_6_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final 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(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java new file mode 100644 index 00000000..b2705770 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_R3; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_6_R3.EntityHuman; +import net.minecraft.server.v1_6_R3.ItemStack; +import net.minecraft.server.v1_6_R3.PlayerInventory; + +import org.bukkit.craftbukkit.v1_6_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentChest.java new file mode 100644 index 00000000..43a07787 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/AnySilentChest.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2011-2014 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_7_R1; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +//Volatile +import net.minecraft.server.v1_7_R1.Block; +import net.minecraft.server.v1_7_R1.EntityPlayer; +import net.minecraft.server.v1_7_R1.IInventory; +import net.minecraft.server.v1_7_R1.InventoryLargeChest; +import net.minecraft.server.v1_7_R1.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_7_R1.TileEntityChest; +import net.minecraft.server.v1_7_R1.World; + +import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.getType(x, y + 1, z).c()) + return true; + + int id = Block.b(world.getType(x, y, z)); + + // If block next to chest is chest and has a block on top + if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(x, y, z); + if (chest == null) + return true; + + int id = Block.b(world.getType(x, y, z)); + + if (!anychest) { + if (world.getType(x, y + 1, z).c()) + return true; + if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + } + + if (Block.b(world.getType(x - 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); + if (Block.b(world.getType(x + 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (Block.b(world.getType(x, y, z - 1)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); + if (Block.b(world.getType(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 PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); + player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/InventoryAccess.java new file mode 100644 index 00000000..5b967d67 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_7_R1; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_7_R1.IInventory; + +import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java new file mode 100644 index 00000000..7b67ac57 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011-2014 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_7_R1; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_7_R1.EntityPlayer; +import net.minecraft.server.v1_7_R1.MinecraftServer; +import net.minecraft.server.v1_7_R1.PlayerInteractManager; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +import org.bukkit.craftbukkit.v1_7_R1.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + GameProfile profile = new GameProfile(null, offline.getName()); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SilentContainerChest.java new file mode 100644 index 00000000..3541d1b5 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_7_R1; + +// Volatile +import net.minecraft.server.v1_7_R1.ContainerChest; +import net.minecraft.server.v1_7_R1.EntityHuman; +import net.minecraft.server.v1_7_R1.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) { + super(i1, i2); + inv = i2; + // close signal + inv.l_(); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java new file mode 100644 index 00000000..80c00e5a --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_7_R1; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_7_R1.EntityHuman; +import net.minecraft.server.v1_7_R1.IInventory; +import net.minecraft.server.v1_7_R1.InventoryEnderChest; +import net.minecraft.server.v1_7_R1.InventorySubcontainer; +import net.minecraft.server.v1_7_R1.ItemStack; + +import org.bukkit.craftbukkit.v1_7_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java new file mode 100644 index 00000000..847b18f5 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_7_R1; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_7_R1.EntityHuman; +import net.minecraft.server.v1_7_R1.ItemStack; +import net.minecraft.server.v1_7_R1.PlayerInventory; + +import org.bukkit.craftbukkit.v1_7_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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, true); + 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 getInventoryName() { + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); + } + return player.getName(); + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentChest.java new file mode 100644 index 00000000..b3f6ab2d --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/AnySilentChest.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2011-2014 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_7_R2; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +import net.minecraft.server.v1_7_R2.Block; +//Volatile +import net.minecraft.server.v1_7_R2.EntityPlayer; +import net.minecraft.server.v1_7_R2.IInventory; +import net.minecraft.server.v1_7_R2.InventoryLargeChest; +import net.minecraft.server.v1_7_R2.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_7_R2.TileEntityChest; +import net.minecraft.server.v1_7_R2.World; + +import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.getType(x, y + 1, z).c()) + return true; + + int id = Block.b(world.getType(x, y, z)); + + // If block next to chest is chest and has a block on top + if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(x, y, z); + if (chest == null) + return true; + + int id = Block.b(world.getType(x, y, z)); + + if (!anychest) { + if (world.getType(x, y + 1, z).c()) + return true; + if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + } + + if (Block.b(world.getType(x - 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); + if (Block.b(world.getType(x + 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (Block.b(world.getType(x, y, z - 1)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); + if (Block.b(world.getType(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 PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); + player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/InventoryAccess.java new file mode 100644 index 00000000..d83d794c --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_7_R2; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_7_R2.IInventory; + +import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java new file mode 100644 index 00000000..b76a2571 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011-2014 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_7_R2; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +//Volatile +import net.minecraft.server.v1_7_R2.EntityPlayer; +import net.minecraft.server.v1_7_R2.MinecraftServer; +import net.minecraft.server.v1_7_R2.PlayerInteractManager; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +import org.bukkit.craftbukkit.v1_7_R2.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + GameProfile profile = new GameProfile(null, offline.getName()); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getName(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SilentContainerChest.java new file mode 100644 index 00000000..e0a459c5 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_7_R2; + +// Volatile +import net.minecraft.server.v1_7_R2.ContainerChest; +import net.minecraft.server.v1_7_R2.EntityHuman; +import net.minecraft.server.v1_7_R2.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) { + super(i1, i2); + inv = i2; + // close signal + inv.l_(); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java new file mode 100644 index 00000000..23aa4a36 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_7_R2; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_7_R2.EntityHuman; +import net.minecraft.server.v1_7_R2.IInventory; +import net.minecraft.server.v1_7_R2.InventoryEnderChest; +import net.minecraft.server.v1_7_R2.InventorySubcontainer; +import net.minecraft.server.v1_7_R2.ItemStack; + +import org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java new file mode 100644 index 00000000..85ba2c1b --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_7_R2; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_7_R2.EntityHuman; +import net.minecraft.server.v1_7_R2.ItemStack; +import net.minecraft.server.v1_7_R2.PlayerInventory; + +import org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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, true); + 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 getInventoryName() { + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); + } + return player.getName(); + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentChest.java new file mode 100644 index 00000000..87c6a0bd --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/AnySilentChest.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2011-2014 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_7_R3; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +// Volatile +import net.minecraft.server.v1_7_R3.Block; +import net.minecraft.server.v1_7_R3.EntityPlayer; +import net.minecraft.server.v1_7_R3.IInventory; +import net.minecraft.server.v1_7_R3.InventoryLargeChest; +import net.minecraft.server.v1_7_R3.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_7_R3.TileEntityChest; +import net.minecraft.server.v1_7_R3.World; + +import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.getType(x, y + 1, z).c()) + return true; + + int id = Block.b(world.getType(x, y, z)); + + // If block next to chest is chest and has a block on top + if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(x, y, z); + if (chest == null) + return true; + + int id = Block.b(world.getType(x, y, z)); + + if (!anychest) { + if (world.getType(x, y + 1, z).c()) + return true; + if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + } + + if (Block.b(world.getType(x - 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); + if (Block.b(world.getType(x + 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (Block.b(world.getType(x, y, z - 1)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); + if (Block.b(world.getType(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 PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); + player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/InventoryAccess.java new file mode 100644 index 00000000..10f9fbd0 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/InventoryAccess.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011-2014 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_7_R3; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_7_R3.IInventory; + +import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = ((CraftInventory) inventory).getInventory(); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java new file mode 100644 index 00000000..66bc1ae1 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011-2014 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_7_R3; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_7_R3.EntityPlayer; +import net.minecraft.server.v1_7_R3.MinecraftServer; +import net.minecraft.server.v1_7_R3.PlayerInteractManager; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +import org.bukkit.craftbukkit.v1_7_R3.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getUniqueId().toString(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SilentContainerChest.java new file mode 100644 index 00000000..ff2c49ab --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_7_R3; + +// Volatile +import net.minecraft.server.v1_7_R3.ContainerChest; +import net.minecraft.server.v1_7_R3.EntityHuman; +import net.minecraft.server.v1_7_R3.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) { + super(i1, i2); + inv = i2; + // close signal + inv.l_(); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java new file mode 100644 index 00000000..73d1bf54 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_7_R3; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_7_R3.EntityHuman; +import net.minecraft.server.v1_7_R3.IInventory; +import net.minecraft.server.v1_7_R3.InventoryEnderChest; +import net.minecraft.server.v1_7_R3.InventorySubcontainer; +import net.minecraft.server.v1_7_R3.ItemStack; + +import org.bukkit.craftbukkit.v1_7_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java new file mode 100644 index 00000000..5471848e --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_7_R3; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_7_R3.EntityHuman; +import net.minecraft.server.v1_7_R3.ItemStack; +import net.minecraft.server.v1_7_R3.PlayerInventory; + +import org.bukkit.craftbukkit.v1_7_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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, true); + 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 getInventoryName() { + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); + } + return player.getName(); + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentChest.java new file mode 100644 index 00000000..196e1779 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/AnySilentChest.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2011-2014 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_7_R4; + +import java.lang.reflect.Field; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +// Volatile +import net.minecraft.server.v1_7_R4.Block; +import net.minecraft.server.v1_7_R4.EntityPlayer; +import net.minecraft.server.v1_7_R4.IInventory; +import net.minecraft.server.v1_7_R4.InventoryLargeChest; +import net.minecraft.server.v1_7_R4.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_7_R4.TileEntityChest; +import net.minecraft.server.v1_7_R4.World; + +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.getType(x, y + 1, z).c()) + return true; + + int id = Block.getId(world.getType(x, y, z)); + + // If block next to chest is chest and has a block on top + if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(x, y, z); + if (chest == null) + return true; + + int id = Block.getId(world.getType(x, y, z)); + + if (!anychest) { + if (world.getType(x, y + 1, z).c()) + return true; + if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) + return true; + if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) + return true; + if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) + return true; + if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) + return true; + } + + if (Block.getId(world.getType(x - 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); + if (Block.getId(world.getType(x + 1, y, z)) == id) + chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); + if (Block.getId(world.getType(x, y, z - 1)) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); + if (Block.getId(world.getType(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 PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); + player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java new file mode 100644 index 00000000..7dd4e19a --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011-2014 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_7_R4; + +import java.lang.reflect.Field; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_7_R4.IInventory; + +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = grabInventory(inventory); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } + + private IInventory grabInventory(Inventory inventory) { + if (inventory instanceof CraftInventory) { + return ((CraftInventory) inventory).getInventory(); + } + + // Use reflection to find the iiventory + Class clazz = inventory.getClass(); + IInventory result = null; + for (Field f : clazz.getDeclaredFields()) { + f.setAccessible(true); + if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) { + try { + result = (IInventory) f.get(inventory); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return result; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java new file mode 100644 index 00000000..e2c84f4d --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011-2014 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_7_R4; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; + +// Volatile +import net.minecraft.server.v1_7_R4.EntityPlayer; +import net.minecraft.server.v1_7_R4.MinecraftServer; +import net.minecraft.server.v1_7_R4.PlayerInteractManager; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +import org.bukkit.craftbukkit.v1_7_R4.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getUniqueId().toString(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SilentContainerChest.java new file mode 100644 index 00000000..6cf1d5c4 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_7_R4; + +// Volatile +import net.minecraft.server.v1_7_R4.ContainerChest; +import net.minecraft.server.v1_7_R4.EntityHuman; +import net.minecraft.server.v1_7_R4.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2) { + super(i1, i2); + inv = i2; + // close signal + inv.closeContainer(); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java new file mode 100644 index 00000000..91c28495 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2011-2014 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_7_R4; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +//Volatile +import net.minecraft.server.v1_7_R4.EntityHuman; +import net.minecraft.server.v1_7_R4.IInventory; +import net.minecraft.server.v1_7_R4.InventoryEnderChest; +import net.minecraft.server.v1_7_R4.InventorySubcontainer; +import net.minecraft.server.v1_7_R4.ItemStack; + +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + @Override + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java new file mode 100644 index 00000000..1d5a5b88 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_7_R4; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_7_R4.EntityHuman; +import net.minecraft.server.v1_7_R4.ItemStack; +import net.minecraft.server.v1_7_R4.PlayerInventory; + +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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, true); + 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 getInventoryName() { + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); + } + return player.getName(); + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentChest.java new file mode 100644 index 00000000..8303e0f0 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/AnySilentChest.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2011-2014 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_8_R1; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +import net.minecraft.server.v1_8_R1.Block; +import net.minecraft.server.v1_8_R1.BlockPosition; +import net.minecraft.server.v1_8_R1.EntityPlayer; +import net.minecraft.server.v1_8_R1.IInventory; +import net.minecraft.server.v1_8_R1.ITileInventory; +import net.minecraft.server.v1_8_R1.InventoryLargeChest; +import net.minecraft.server.v1_8_R1.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_8_R1.TileEntityChest; +import net.minecraft.server.v1_8_R1.World; + +//Volatile +import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + // If block next to chest is chest and has a block on top + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(new BlockPosition(x, y, z)); + if (chest == null) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + if (!anychest) { + if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + } + + if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z))); + if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1))); + + boolean returnValue = true; + if (!silentchest) { + player.openContainer((IInventory) chest); + } + else { + try { + SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player); + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize())); + player.activeContainer = silentContainerChest; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/InventoryAccess.java new file mode 100644 index 00000000..7a961cea --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/InventoryAccess.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011-2014 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_8_R1; + +import java.lang.reflect.Field; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +import net.minecraft.server.v1_8_R1.IInventory; + +// Volatile +import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = grabInventory(inventory); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } + + private IInventory grabInventory(Inventory inventory) { + if (inventory instanceof CraftInventory) { + return ((CraftInventory) inventory).getInventory(); + } + + // Use reflection to find the iiventory + Class clazz = inventory.getClass(); + IInventory result = null; + for (Field f : clazz.getDeclaredFields()) { + f.setAccessible(true); + if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) { + try { + result = (IInventory) f.get(inventory); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return result; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java new file mode 100644 index 00000000..81465a5b --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011-2014 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_8_R1; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; +import com.mojang.authlib.GameProfile; + +import net.minecraft.server.v1_8_R1.EntityPlayer; +import net.minecraft.server.v1_8_R1.MinecraftServer; +import net.minecraft.server.v1_8_R1.PlayerInteractManager; + +//Volatile +import org.bukkit.craftbukkit.v1_8_R1.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getUniqueId().toString(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SilentContainerChest.java new file mode 100644 index 00000000..e26b3a38 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_8_R1; + +//Volatile +import net.minecraft.server.v1_8_R1.ContainerChest; +import net.minecraft.server.v1_8_R1.EntityHuman; +import net.minecraft.server.v1_8_R1.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) { + super(i1, i2, e1); + inv = i2; + // close signal + inv.closeContainer(e1); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java new file mode 100644 index 00000000..5929a01b --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2011-2014 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_8_R1; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +import net.minecraft.server.v1_8_R1.EntityHuman; +import net.minecraft.server.v1_8_R1.IInventory; +import net.minecraft.server.v1_8_R1.InventoryEnderChest; +import net.minecraft.server.v1_8_R1.InventorySubcontainer; +import net.minecraft.server.v1_8_R1.ItemStack; + +//Volatile +import org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return this.inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java new file mode 100644 index 00000000..9a555c49 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_8_R1; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +import net.minecraft.server.v1_8_R1.EntityHuman; +import net.minecraft.server.v1_8_R1.ItemStack; +//Volatile +import net.minecraft.server.v1_8_R1.PlayerInventory; + +import org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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, true); + 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java new file mode 100644 index 00000000..29d1835b --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2011-2014 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_8_R2; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +import net.minecraft.server.v1_8_R2.Block; +import net.minecraft.server.v1_8_R2.BlockPosition; +import net.minecraft.server.v1_8_R2.EntityPlayer; +import net.minecraft.server.v1_8_R2.IInventory; +import net.minecraft.server.v1_8_R2.ITileInventory; +import net.minecraft.server.v1_8_R2.InventoryLargeChest; +import net.minecraft.server.v1_8_R2.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_8_R2.TileEntityChest; +import net.minecraft.server.v1_8_R2.World; + +//Volatile +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + // If block next to chest is chest and has a block on top + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(new BlockPosition(x, y, z)); + if (chest == null) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + if (!anychest) { + if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + } + + if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z))); + if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1))); + + boolean returnValue = true; + if (!silentchest) { + player.openContainer((IInventory) chest); + } + else { + try { + SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player); + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize())); + player.activeContainer = silentContainerChest; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java new file mode 100644 index 00000000..35f43d7c --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011-2014 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_8_R2; + +import java.lang.reflect.Field; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_8_R2.IInventory; + +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = grabInventory(inventory); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } + + private IInventory grabInventory(Inventory inventory) { + if(inventory instanceof CraftInventory) { + return ((CraftInventory) inventory).getInventory(); + } + + //Use reflection to find the iiventory + Class clazz = inventory.getClass(); + IInventory result = null; + for(Field f : clazz.getDeclaredFields()) { + f.setAccessible(true); + if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) { + try { + result = (IInventory) f.get(inventory); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + return result; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java new file mode 100644 index 00000000..8e1815e7 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011-2014 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_8_R2; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; +import com.mojang.authlib.GameProfile; + +// Volatile +import net.minecraft.server.v1_8_R2.EntityPlayer; +import net.minecraft.server.v1_8_R2.MinecraftServer; +import net.minecraft.server.v1_8_R2.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_8_R2.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getUniqueId().toString(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java new file mode 100644 index 00000000..8ee6f796 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_8_R2; + +// Volatile +import net.minecraft.server.v1_8_R2.ContainerChest; +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) { + super(i1, i2, e1); + inv = i2; + // close signal + inv.closeContainer(e1); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java new file mode 100644 index 00000000..631cf939 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2011-2014 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_8_R2; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.IInventory; +import net.minecraft.server.v1_8_R2.InventoryEnderChest; +import net.minecraft.server.v1_8_R2.InventorySubcontainer; +import net.minecraft.server.v1_8_R2.ItemStack; + +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java new file mode 100644 index 00000000..7fae684d --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_8_R2; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +// Volatile +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.ItemStack; +import net.minecraft.server.v1_8_R2.PlayerInventory; + +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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(armor, 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, true); + 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentChest.java new file mode 100644 index 00000000..6c6e686c --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/AnySilentChest.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2011-2014 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_8_R3; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IAnySilentChest; + +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.IInventory; +import net.minecraft.server.v1_8_R3.ITileInventory; +import net.minecraft.server.v1_8_R3.InventoryLargeChest; +import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_8_R3.TileEntityChest; +import net.minecraft.server.v1_8_R3.World; + +//Volatile +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; + +public class AnySilentChest implements IAnySilentChest { + @Override + 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.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + // If block next to chest is chest and has a block on top + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + + return false; + } + + @Override + 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 = world.getTileEntity(new BlockPosition(x, y, z)); + if (chest == null) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + if (!anychest) { + if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + } + + if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z))); + if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1))); + + boolean returnValue = true; + if (!silentchest) { + player.openContainer((IInventory) chest); + } + else { + try { + SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player); + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize())); + player.activeContainer = silentContainerChest; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + return returnValue; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/InventoryAccess.java new file mode 100644 index 00000000..437b02e5 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/InventoryAccess.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011-2014 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_8_R3; + +import java.lang.reflect.Field; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_8_R3.IInventory; + +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = grabInventory(inventory); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } + + private IInventory grabInventory(Inventory inventory) { + if (inventory instanceof CraftInventory) { + return ((CraftInventory) inventory).getInventory(); + } + + // Use reflection to find the iiventory + Class clazz = inventory.getClass(); + IInventory result = null; + for (Field f : clazz.getDeclaredFields()) { + f.setAccessible(true); + if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) { + try { + result = (IInventory) f.get(inventory); + } catch (Exception e) { + e.printStackTrace(); + ; + } + } + } + return result; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java new file mode 100644 index 00000000..61b136bd --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2011-2014 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_8_R3; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import com.lishid.openinv.internal.IPlayerDataManager; +import com.mojang.authlib.GameProfile; + +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.MinecraftServer; +import net.minecraft.server.v1_8_R3.PlayerInteractManager; + +//Volatile +import org.bukkit.craftbukkit.v1_8_R3.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + + GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getUniqueId().toString(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SilentContainerChest.java new file mode 100644 index 00000000..0a7602c2 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SilentContainerChest.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011-2014 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_8_R3; + +// Volatile +import net.minecraft.server.v1_8_R3.ContainerChest; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) { + super(i1, i2, e1); + inv = i2; + // close signal + inv.closeContainer(e1); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java new file mode 100644 index 00000000..3b79f873 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2011-2014 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_8_R3; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +// Volatile +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.IInventory; +import net.minecraft.server.v1_8_R3.InventoryEnderChest; +import net.minecraft.server.v1_8_R3.InventorySubcontainer; +import net.minecraft.server.v1_8_R3.ItemStack; + +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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; + } + } + + @Override + public boolean setPlayerOffline() { + playerOnline = false; + return inventoryRemovalCheck(); + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.inventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java new file mode 100644 index 00000000..058d7ace --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2011-2014 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_8_R3; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +//Volatile +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.ItemStack; +import net.minecraft.server.v1_8_R3.PlayerInventory; + +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + CraftPlayer owner; + public boolean playerOnline = false; + private final ItemStack[] extra = new ItemStack[5]; + private final 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; + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public boolean inventoryRemovalCheck() { + owner.saveData(); + return transaction.isEmpty() && !playerOnline; + } + + @Override + public void setPlayerOnline(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 boolean setPlayerOffline() { + playerOnline = false; + return 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(armor, 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].cloneAndSubtract(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, true); + 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; + } +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentChest.java index 2d4e95e6..6edb90f6 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/AnySilentChest.java @@ -21,9 +21,7 @@ import com.lishid.openinv.internal.IAnySilentChest; -//Volatile -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; - +// Volatile import net.minecraft.server.v1_9_R1.AxisAlignedBB; import net.minecraft.server.v1_9_R1.Block; import net.minecraft.server.v1_9_R1.BlockPosition; @@ -37,7 +35,10 @@ import net.minecraft.server.v1_9_R1.TileEntityChest; import net.minecraft.server.v1_9_R1.World; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; + public class AnySilentChest implements IAnySilentChest { + @Override public boolean isAnyChestNeeded(Player p, int x, int y, int z) { // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest EntityPlayer player = ((CraftPlayer) p).getHandle(); @@ -86,6 +87,7 @@ private boolean hasOcelotOnTop(World world, int x, int y, int z) { return false; } + @Override public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { EntityPlayer player = ((CraftPlayer) p).getHandle(); World world = player.world; diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/InventoryAccess.java index 9c23aa33..cdc25904 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/InventoryAccess.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/InventoryAccess.java @@ -25,12 +25,13 @@ import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.IInventoryAccess; -//Volatile -import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; - +// Volatile import net.minecraft.server.v1_9_R1.IInventory; +import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; + public class InventoryAccess implements IInventoryAccess { + @Override public boolean check(Inventory inventory, HumanEntity player) { IInventory inv = grabInventory(inventory); diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java index 4a6673d9..f78104b6 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java @@ -23,104 +23,16 @@ import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; -//Volatile -import org.bukkit.craftbukkit.v1_9_R1.CraftServer; - +// Volatile import net.minecraft.server.v1_9_R1.EntityPlayer; import net.minecraft.server.v1_9_R1.MinecraftServer; import net.minecraft.server.v1_9_R1.PlayerInteractManager; +import org.bukkit.craftbukkit.v1_9_R1.CraftServer; + public class PlayerDataManager implements IPlayerDataManager { -// public Player loadPlayer(String name) { -// try { -// UUID uuid = matchUser(name); -// if (uuid == null) { -// return null; -// } -// -// // Default player folder -// File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"); -// if (!playerfolder.exists()) { -// return null; -// } -// -// OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); -// if (player == null) { -// return null; -// } -// GameProfile profile = new GameProfile(uuid, player.getName()); -// MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); -// // Create an entity to load the player data -// EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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) { -// e.printStackTrace(); -// } -// -// return null; -// } -// -// private static UUID matchUser(String search) { -// UUID found = null; -// -// String lowerSearch = search.toLowerCase(); -// int delta = 2147483647; -// -// OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers(); -// for (OfflinePlayer player : offlinePlayers) { -// String name = player.getName(); -// -// if (name == null){ -// continue; -// } -// if (name.equalsIgnoreCase(search)){ -// return player.getUniqueId(); -// } -// if (name.toLowerCase().startsWith(lowerSearch)) { -// int curDelta = name.length() - lowerSearch.length(); -// if (curDelta < delta) { -// found = player.getUniqueId(); -// delta = curDelta; -// } -// if (curDelta == 0) { -// break; -// } -// } -// } -// -// return found; -// } -// -// public Player loadPlayer(UUID uuid) { -// OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); -// if (player == null || !player.hasPlayedBefore()) { -// return null; -// } -// GameProfile profile = new GameProfile(uuid, player.getName()); -// MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); -// // Create an entity to load the player data -// EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(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; -// } -// return null; -// } + @Override public Player loadPlayer(OfflinePlayer offline) { if (offline == null || !offline.hasPlayedBefore()) { return null; @@ -141,6 +53,7 @@ public Player loadPlayer(OfflinePlayer offline) { return null; } + @Override public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SilentContainerChest.java index 9caebedf..6453bc2f 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SilentContainerChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SilentContainerChest.java @@ -16,7 +16,7 @@ package com.lishid.openinv.internal.v1_9_R1; -//Volatile +// Volatile import net.minecraft.server.v1_9_R1.ContainerChest; import net.minecraft.server.v1_9_R1.EntityHuman; import net.minecraft.server.v1_9_R1.IInventory; @@ -35,4 +35,4 @@ public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) { public void b(EntityHuman paramEntityHuman) { // Don't send close signal twice, might screw up } -} \ No newline at end of file +} diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java index 62574ca5..0bec3304 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java @@ -27,17 +27,17 @@ import com.lishid.openinv.internal.ISpecialEnderChest; -//Volatile -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; - +// Volatile import net.minecraft.server.v1_9_R1.EntityHuman; import net.minecraft.server.v1_9_R1.IInventory; import net.minecraft.server.v1_9_R1.InventoryEnderChest; import net.minecraft.server.v1_9_R1.InventorySubcontainer; import net.minecraft.server.v1_9_R1.ItemStack; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; + public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public List transaction = new ArrayList(); public boolean playerOnline = false; @@ -54,15 +54,18 @@ public SpecialEnderChest(Player p, Boolean online) { this.items = enderChest.getContents(); } + @Override public Inventory getBukkitInventory() { return inventory; } + @Override public boolean inventoryRemovalCheck() { owner.saveData(); return transaction.isEmpty() && !playerOnline; } + @Override public void setPlayerOnline(Player p) { if (!playerOnline) { try { @@ -77,6 +80,7 @@ public void setPlayerOnline(Player p) { } } + @Override public boolean setPlayerOffline() { playerOnline = false; return inventoryRemovalCheck(); diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java index cc144a33..31dcb011 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java @@ -24,15 +24,15 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory; -//Volatile -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; - +// Volatile import net.minecraft.server.v1_9_R1.EntityHuman; import net.minecraft.server.v1_9_R1.ItemStack; import net.minecraft.server.v1_9_R1.PlayerInventory; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; + public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { CraftPlayer owner; public boolean playerOnline = false; @@ -298,4 +298,4 @@ public String getName() { public boolean a(EntityHuman entityhuman) { return true; } -} \ No newline at end of file +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index cf89c4c5..32f59f16 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,39 +1,39 @@ -name: OpenInv -main: com.lishid.openinv.OpenInv -version: 2.3.0 -author: lishid -authors: [Jikoo] -description: > - This plugin allows you to open a player's inventory as a chest and interact with it in real time. -commands: - openinv: - aliases: [oi, inv, open] - description: Open a player's inventory - permission: OpenInv.openinv - usage: | - / - Open last person's inventory - / - Open a player's inventory - openender: - aliases: [oe] - description: Opens the enderchest of a player - permission: OpenInv.openender - usage: | - / - Opens a player's enderchest - searchinv: - aliases: [si] - description: Search and list players having a specific item - permission: OpenInv.search - usage: | - / [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered. - silentchest: - aliases: [sc, silent] - description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound. - permission: OpenInv.silent - usage: | - / [Check] - Checks whether silent chest is enabled - anychest: - aliases: [ac] - description: Toggle anychest function, which allows opening of blocked chests. - permission: OpenInv.anychest - usage: | - / [Check] - Checks whether anychest is enabled +name: OpenInv +main: com.lishid.openinv.OpenInv +version: 2.3.0 +author: lishid +authors: [Jikoo] +description: > + This plugin allows you to open a player's inventory as a chest and interact with it in real time. +commands: + openinv: + aliases: [oi, inv, open] + description: Open a player's inventory + permission: OpenInv.openinv + usage: | + / - Open last person's inventory + / - Open a player's inventory + openender: + aliases: [oe] + description: Opens the enderchest of a player + permission: OpenInv.openender + usage: | + / - Opens a player's enderchest + searchinv: + aliases: [si] + description: Search and list players having a specific item + permission: OpenInv.search + usage: | + / [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered. + silentchest: + aliases: [sc, silent] + description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound. + permission: OpenInv.silent + usage: | + / [Check] - Checks whether silent chest is enabled + anychest: + aliases: [ac] + description: Toggle anychest function, which allows opening of blocked chests. + permission: OpenInv.anychest + usage: | + / [Check] - Checks whether anychest is enabled