Compare commits

...

49 Commits
3.2.0 ... 4.0.0

Author SHA1 Message Date
Jikoo
393fe1d837 Bump version to 4.0.0 for release 2019-05-05 16:55:12 -04:00
Jikoo
f80df9d83b Copy pasted javadocs are super great 2019-05-05 16:49:41 -04:00
Jikoo
5c006f8ebd QOL: Warn users when plugin is running on an unsupported version 2019-05-05 15:43:41 -04:00
Jikoo
57097e626e Reduce duplicate code in core plugin 2019-05-05 15:39:54 -04:00
Jikoo
0f266c8a64 Custom inventory titles for 1.14 2019-05-05 15:15:17 -04:00
Jikoo
185f037254 Revert API changes, fix SpecialPlayerInventory implementation 2019-05-05 12:40:47 -04:00
Jikoo
e4d0020296 Update to 1.14 (#101) 2019-04-28 20:37:45 -04:00
Jikoo
9e37cbbca8 Prepare for 1.14
To continue providing renamed ender chests/player inventories we can no longer just provide an Inventory, a full InventoryView is required. To avoid confusion the old method has been removed entirely, leading to a major API revision bump.
2019-04-28 20:37:05 -04:00
Jikoo
adc35e9ad5 Correct players not being properly released 2019-04-28 12:11:59 -04:00
Jikoo
a469c732cc Store UUID instead of name for faster re-open lookups 2019-04-28 11:03:00 -04:00
Jikoo
c5c1f47167 Hacky workaround for Java 9 reflection changes (#93) 2019-04-12 20:56:05 -04:00
Jikoo
dc59356f76 Bump version to 3.3.8-SNAPSHOT for development 2019-01-18 18:36:28 -05:00
Jikoo
d497772ad7 Bump version to 3.3.7 for release 2019-01-18 18:35:50 -05:00
Jikoo
4f4d46974a Support 1.13.2 (#94) 2019-01-15 20:01:41 -05:00
Jikoo
96c38895e2 Bump version to 3.3.7-SNAPSHOT for development 2018-08-26 14:47:13 -04:00
Jikoo
5753648d77 Bump version to 3.3.6 for release 2018-08-26 14:46:33 -04:00
Jikoo
3725711b94 Support Spigot 1.13.1 2018-08-26 14:43:21 -04:00
Jikoo
c22e18c096 Correct unnecessary AnyContainer usage 2018-08-26 14:37:29 -04:00
Jikoo
6bff759d72 Bump version to 3.3.6-SNAPSHOT for development 2018-08-13 21:31:46 -04:00
Jikoo
582c7201dd Bump version to 3.3.5 for release 2018-08-13 21:31:17 -04:00
Jikoo
59a8ed70bb Correct double chest logic for Silent/AnyContainer in 1.13 2018-08-09 18:50:24 -04:00
Jikoo
27812c133d Bump version to 3.3.5-SNAPSHOT for development 2018-07-22 09:45:01 -04:00
Jikoo
165f3fb00e Bump version to 3.3.4 for release 2018-07-22 09:44:27 -04:00
Jikoo
60dcb64558 Bump version for alpha release 2018-07-15 12:05:52 -04:00
Jikoo
077b34d304 Support 1.13-pre7 2018-07-15 12:01:45 -04:00
Jikoo
8ce6e2f8d3 Reverse order of wildcard permission check, respect explicit values (#85) 2018-05-26 06:58:56 -04:00
Jikoo
f5dce23f18 Bump version to 3.3.4-SNAPSHOT for development 2018-02-07 18:36:15 -05:00
Jikoo
669cfd72aa Bump version to 3.3.3 for release 2018-02-07 18:35:39 -05:00
Jikoo
9e66885690 First load should not "update" nonexistent config, just use a default 2018-02-07 18:17:33 -05:00
Jikoo
a802769265 Sneaky tabs, trying to slip in there. 2018-02-04 10:35:35 -05:00
Jikoo
50c45b6616 Cleaned up code, updated copyright at long last. 2018-02-04 10:29:09 -05:00
Jikoo
eaf01fa32c Don't cache simultaneously added players forever 2017-11-19 14:46:52 -05:00
Jikoo
4abaa6ea51 Backport spectate abuse to 1.8-1.10 to support PaperSpigot
This may break functionality on C(K)auldron and other server implementations with different remapping names.
2017-11-08 19:07:23 -05:00
Jikoo
7c621bf899 Bump version to 3.3.3-SNAPSHOT for development 2017-11-08 17:53:16 -05:00
Jikoo
f5c682ff2b Bump version to 3.3.2 for release 2017-11-08 17:52:41 -05:00
Jikoo
e652b43670 Classic mistake, changed my mind and only changed part of the code.
Also the actual mistake. Never forget. (#81)
2017-11-08 17:40:01 -05:00
Jikoo
f07cef5621 Bump version to 3.3.2-SNAPSHOT for development 2017-11-07 18:18:33 -05:00
Jikoo
ded6421e33 Bump version to 3.3.1 for release 2017-11-07 18:17:12 -05:00
Jikoo
cbb2b4d232 Lowercase permissions can wait for a major version bump
I don't want to double our permissions checks for backwards compatibility.
2017-11-07 18:16:38 -05:00
Jikoo
48c61eeb82 Support lowercase permissions for consistency. 2017-11-06 19:23:26 -05:00
Jikoo
e3d1af010b Add permissions to alter the default state of Any/SilentChest (#76) 2017-11-05 20:00:22 -05:00
Jikoo
2195677651 Actually fix CME (#71) 2017-08-06 16:35:18 -04:00
Jikoo
c72af5dbac Bump version to 3.3.1-SNAPSHOT for development 2017-07-05 05:53:38 -04:00
Jikoo
931cdb6fb1 Bump version to 3.3.0 for release 2017-07-05 05:52:33 -04:00
Jikoo
9db18613a1 Abuse spectator mode for SilentContainer (#64, #68)
Potentially causes issues with Cauldron and similar mods that use different mapping names.
2017-07-04 13:22:03 -04:00
Jikoo
784935a975 Synchronize cache (for real), updated dependencies
Closes #69
2017-07-03 18:06:18 -04:00
Jikoo
d9abe76531 Bump version to 3.2.2-SNAPSHOT for development 2017-06-09 20:21:30 -04:00
Jikoo
ca85a392aa Correct field name for list of inventory contents (#66) 2017-06-09 20:15:51 -04:00
Jikoo
307f47e4d3 Bump version to 3.2.1-SNAPSHOT for development 2017-06-08 18:44:10 -04:00
197 changed files with 8228 additions and 3805 deletions

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@
**/.project **/.project
**/.classpath **/.classpath
**/.idea **/.idea
**/.iml
**/target **/target
**/bin **/bin
**/out **/out

View File

@@ -7,12 +7,12 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
- Cross-world support! Don't grant `OpenInv.crossworld` - Cross-world support! Don't grant `OpenInv.crossworld`
- No self-opening! Don't grant `OpenInv.openself` - No self-opening! Don't grant `OpenInv.openself`
- Drop items as the player! Place items in the unused slots to the right of the armor to drop them - Drop items as the player! Place items in the unused slots to the right of the armor to drop them
- **OpenEnder**: Open anyone's inventory, even if they're offline. - **OpenEnder**: Open anyone's ender chest, even if they're offline.
- Read-only mode! No edits allowed! Don't grant `OpenInv.editender` - Read-only mode! No edits allowed! Don't grant `OpenInv.editender`
- Cross-world support! Don't grant `OpenInv.crossworld` - Cross-world support! Don't grant `OpenInv.crossworld`
- No opening others! Don't grant `OpenInv.openenderall` - No opening others! Don't grant `OpenInv.openenderall`
- **SilentChest**: Open containers without displaying an animation or making sound. - **SilentContainer**: Open containers without displaying an animation or making sound.
- **AnyChest**: Open containers, even if blocked by ocelots or blocks. - **AnyContainer**: Open containers, even if blocked by ocelots or blocks.
## Commands ## Commands
<table width=100%> <table width=100%>
@@ -42,14 +42,19 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
<td>Lists all online players that have a certain item in their ender chest.</td> <td>Lists all online players that have a certain item in their ender chest.</td>
</tr> </tr>
<tr> <tr>
<td>/anychest [check]</td> <td>/searchenchant &lt[enchantment] [MinLevel]&gt</td>
<td>ac</td> <td>searchenchants</td>
<td>Check or toggle the AnyChest function, allowing opening blocked containers.</td> <td>Lists all online players with a specific enchantment.</td>
</tr> </tr>
<tr> <tr>
<td>/silentchest [check]</td> <td>/anycontainer [check]</td>
<td>sc</td> <td>ac, anychest</td>
<td>Check or toggle the SilentChest function, allowing opening containers silently.</td> <td>Check or toggle the AnyContainer function, allowing opening blocked containers.</td>
</tr>
<tr>
<td>/silentcontainer [check]</td>
<td>sc, silentchest</td>
<td>Check or toggle the SilentContainer function, allowing opening containers silently.</td>
</tr> </tr>
</table> </table>
@@ -103,37 +108,49 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
<td>OpenInv.search</td> <td>OpenInv.search</td>
<td>Required to use /searchinv and /searchender.</td> <td>Required to use /searchinv and /searchender.</td>
</tr> </tr>
<tr>
<td>OpenInv.searchenchant</td>
<td>Required to use /searchenchant.</td>
</tr>
<tr> <tr>
<td>OpenInv.anychest</td> <td>OpenInv.anychest</td>
<td>Required to use /anychest.</td> <td>Required to use /anychest.</td>
</tr> </tr>
<tr>
<td>OpenInv.any.default</td>
<td>Cause AnyContainer to be enabled by default.</td>
</tr>
<tr> <tr>
<td>OpenInv.silent</td> <td>OpenInv.silent</td>
<td>Required to use /silentchest.</td> <td>Required to use /silentcontainer.</td>
</tr>
<tr>
<td>OpenInv.silent.default</td>
<td>Cause SilentContainer to be enabled by default.</td>
</tr> </tr>
</table> </table>
## For Developers ## For Developers
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin. To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT` Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
To compile for a specific version or set of versions, you'll need to use a profile. Provided profiles are `latest`, `modern` (versions 1.8+), and `all`. Select an existing profile using the `-P` argument (ex: `mvn clean package -am -P all`) or make your own. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html). To compile for a specific version or set of versions, you'll need to use a profile. Provided profiles are `latest`, `recent` (last 2 major Minecraft versions), and `all`. Select an existing profile using the `-P` argument (ex: `mvn clean package -am -P all`) or make your own. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
The final file is target/OpenInv.jar The final file is target/OpenInv.jar
## License ## License
``` ```
Copyright (C) 2011-2014 lishid. All rights reserved. Copyright (C) 2011-2018 lishid. All rights reserved.
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3. the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
``` ```

View File

@@ -1,11 +1,27 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvapi</artifactId> <artifactId>openinvapi</artifactId>

View File

@@ -1,15 +1,32 @@
package com.lishid.openinv; /*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
import javax.annotation.Nullable; package com.lishid.openinv;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialInventory;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* Interface defining behavior for the OpenInv plugin. * Interface defining behavior for the OpenInv plugin.
@@ -26,53 +43,23 @@ public interface IOpenInv {
* *
* @return false unless configured otherwise * @return false unless configured otherwise
*/ */
public boolean disableSaving(); boolean disableSaving();
/** /**
* Gets the active ISilentContainer implementation. May return null if the server version is * Gets the active ISilentContainer implementation.
* unsupported.
* *
* @return the ISilentContainer * @return the ISilentContainer
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public IAnySilentContainer getAnySilentContainer(); @NotNull IAnySilentContainer getAnySilentContainer();
/** /**
* Gets an ISpecialEnderChest for the given Player. Returns null if the ISpecialEnderChest could * Gets the active IInventoryAccess implementation.
* not be instantiated.
*
* @deprecated Use {@link IOpenInv#getSpecialEnderChest(Player, boolean)}
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialEnderChest
* @throws IllegalStateException if the server version is unsupported
*/
@Deprecated
@Nullable
public ISpecialEnderChest getEnderChest(Player player, boolean online);
/**
* Gets an ISpecialPlayerInventory for the given Player. Returns null if the
* ISpecialPlayerInventory could not be instantiated.
*
* @deprecated Use {@link IOpenInv#getSpecialInventory(Player, boolean)}
* @param player the Player
* @param online true if the Player is currently online
* @return the ISpecialPlayerInventory
* @throws IllegalStateException if the server version is unsupported
*/
@Deprecated
@Nullable
public ISpecialPlayerInventory getInventory(Player player, boolean online);
/**
* Gets the active IInventoryAccess implementation. May return null if the server version is
* unsupported.
* *
* @return the IInventoryAccess * @return the IInventoryAccess
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public IInventoryAccess getInventoryAccess(); @NotNull IInventoryAccess getInventoryAccess();
/** /**
* Gets the provided player's AnyChest setting. * Gets the provided player's AnyChest setting.
@@ -81,7 +68,7 @@ public interface IOpenInv {
* @return true if AnyChest is enabled * @return true if AnyChest is enabled
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public boolean getPlayerAnyChestStatus(OfflinePlayer player); boolean getPlayerAnyChestStatus(@NotNull OfflinePlayer player);
/** /**
* Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value * Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value
@@ -91,16 +78,16 @@ public interface IOpenInv {
* @return the identifier * @return the identifier
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public String getPlayerID(OfflinePlayer offline); @NotNull String getPlayerID(@NotNull OfflinePlayer offline);
/** /**
* Gets a player's SilentChest setting. * Gets a player's SilentChest setting.
* *
* @param player the OfflinePlayer * @param offline the OfflinePlayer
* @return true if SilentChest is enabled * @return true if SilentChest is enabled
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public boolean getPlayerSilentChestStatus(OfflinePlayer player); boolean getPlayerSilentChestStatus(@NotNull OfflinePlayer offline);
/** /**
* Gets an ISpecialEnderChest for the given Player. * Gets an ISpecialEnderChest for the given Player.
@@ -108,10 +95,10 @@ public interface IOpenInv {
* @param player the Player * @param player the Player
* @param online true if the Player is currently online * @param online true if the Player is currently online
* @return the ISpecialEnderChest * @return the ISpecialEnderChest
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
* @throws InstantiationException if the ISpecialEnderChest could not be instantiated * @throws InstantiationException if the ISpecialEnderChest could not be instantiated
*/ */
public ISpecialEnderChest getSpecialEnderChest(Player player, boolean online) throws InstantiationException; @NotNull ISpecialEnderChest getSpecialEnderChest(@NotNull Player player, boolean online) throws InstantiationException;
/** /**
* Gets an ISpecialPlayerInventory for the given Player. * Gets an ISpecialPlayerInventory for the given Player.
@@ -119,17 +106,17 @@ public interface IOpenInv {
* @param player the Player * @param player the Player
* @param online true if the Player is currently online * @param online true if the Player is currently online
* @return the ISpecialPlayerInventory * @return the ISpecialPlayerInventory
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
* @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated * @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated
*/ */
public ISpecialPlayerInventory getSpecialInventory(Player player, boolean online) throws InstantiationException; @NotNull ISpecialPlayerInventory getSpecialInventory(@NotNull Player player, boolean online) throws InstantiationException;
/** /**
* Checks if the server version is supported by OpenInv. * Checks if the server version is supported by OpenInv.
* *
* @return true if the server version is supported * @return true if the server version is supported
*/ */
public boolean isSupportedVersion(); boolean isSupportedVersion();
/** /**
* Load a Player from an OfflinePlayer. May return null under some circumstances. * Load a Player from an OfflinePlayer. May return null under some circumstances.
@@ -138,8 +125,7 @@ public interface IOpenInv {
* @return the Player, or null * @return the Player, or null
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
@Nullable @Nullable Player loadPlayer(@NotNull final OfflinePlayer offline);
public Player loadPlayer(final OfflinePlayer offline);
/** /**
* Get an OfflinePlayer by name. * Get an OfflinePlayer by name.
@@ -151,8 +137,16 @@ public interface IOpenInv {
* @param name the name of the Player * @param name the name of the Player
* @return the OfflinePlayer with the closest matching name or null if no players have ever logged in * @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
*/ */
@Nullable @Nullable OfflinePlayer matchPlayer(@NotNull String name);
public OfflinePlayer matchPlayer(String name);
/**
* Open an ISpecialInventory for a Player.
*
* @param player the Player
* @param inventory the ISpecialInventory
* @return the InventoryView for the opened ISpecialInventory
*/
@Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
/** /**
* Check the configuration value for whether or not OpenInv displays a notification to the user * Check the configuration value for whether or not OpenInv displays a notification to the user
@@ -160,7 +154,7 @@ public interface IOpenInv {
* *
* @return true unless configured otherwise * @return true unless configured otherwise
*/ */
public boolean notifyAnyChest(); boolean notifyAnyChest();
/** /**
* Check the configuration value for whether or not OpenInv displays a notification to the user * Check the configuration value for whether or not OpenInv displays a notification to the user
@@ -168,7 +162,7 @@ public interface IOpenInv {
* *
* @return true unless configured otherwise * @return true unless configured otherwise
*/ */
public boolean notifySilentChest(); boolean notifySilentChest();
/** /**
* Mark a Player as no longer in use by a Plugin to allow OpenInv to remove it from the cache * Mark a Player as no longer in use by a Plugin to allow OpenInv to remove it from the cache
@@ -178,7 +172,7 @@ public interface IOpenInv {
* @param plugin the Plugin no longer holding a reference to the Player * @param plugin the Plugin no longer holding a reference to the Player
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public void releasePlayer(Player player, Plugin plugin); void releasePlayer(@NotNull Player player, @NotNull Plugin plugin);
/** /**
* Mark a Player as in use by a Plugin to prevent it from being removed from the cache. Used to * Mark a Player as in use by a Plugin to prevent it from being removed from the cache. Used to
@@ -203,32 +197,32 @@ public interface IOpenInv {
* @param plugin the Plugin holding the reference to the Player * @param plugin the Plugin holding the reference to the Player
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public void retainPlayer(Player player, Plugin plugin); void retainPlayer(@NotNull Player player, @NotNull Plugin plugin);
/** /**
* Sets a player's AnyChest setting. * Sets a player's AnyChest setting.
* *
* @param player the OfflinePlayer * @param offline the OfflinePlayer
* @param status the status * @param status the status
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status); void setPlayerAnyChestStatus(@NotNull OfflinePlayer offline, boolean status);
/** /**
* Sets a player's SilentChest setting. * Sets a player's SilentChest setting.
* *
* @param player the OfflinePlayer * @param offline the OfflinePlayer
* @param status the status * @param status the status
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status); void setPlayerSilentChestStatus(@NotNull OfflinePlayer offline, boolean status);
/** /**
* Forcibly unload a cached Player's data. * Forcibly unload a cached Player's data.
* *
* @param player the OfflinePlayer to unload * @param offline the OfflinePlayer to unload
* @throws IllegalStateException if the server version is unsupported * @throws IllegalStateException if the server version is unsupported
*/ */
public void unload(OfflinePlayer player); void unload(@NotNull OfflinePlayer offline);
} }

View File

@@ -1,37 +1,61 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal; package com.lishid.openinv.internal;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public interface IAnySilentContainer { public interface IAnySilentContainer {
/**
* Checks if the given block is a container which can be unblocked or silenced.
*
* @param block the BlockState
* @return true if the Block is a supported container
*/
public boolean isAnySilentContainer(Block block);
/**
* Checks if the container at the given coordinates is blocked.
*
* @param player the Player opening the container
* @param block the Block
* @return true if the container is blocked
*/
public boolean isAnyContainerNeeded(Player player, Block block);
/** /**
* Opens the container at the given coordinates for the Player. If you do not want blocked * Opens the container at the given coordinates for the Player. If you do not want blocked
* containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)} * containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)}
* first. * first.
* *
* @param player * @param player the Player opening the container
* @param silentchest whether the container's noise is to be silenced * @param silent whether the container's noise is to be silenced
* @param block the Block * @param block the Block
* @return true if the container can be opened * @return true if the container can be opened
*/ */
public boolean activateContainer(Player player, boolean silentchest, Block block); boolean activateContainer(@NotNull Player player, boolean silent, @NotNull Block block);
/**
* Closes the Player's currently open container silently, if necessary.
*
* @param player the Player closing a container
*/
void deactivateContainer(@NotNull Player player);
/**
* Checks if the container at the given coordinates is blocked.
*
* @param player the Player opening the container
* @param block the Block
* @return true if the container is blocked
*/
boolean isAnyContainerNeeded(@NotNull Player player, @NotNull Block block);
/**
* Checks if the given block is a container which can be unblocked or silenced.
*
* @param block the BlockState
* @return true if the Block is a supported container
*/
boolean isAnySilentContainer(@NotNull Block block);
} }

View File

@@ -1,13 +1,13 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
@@ -16,9 +16,9 @@
package com.lishid.openinv.internal; package com.lishid.openinv.internal;
import javax.annotation.Nullable;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface IInventoryAccess { public interface IInventoryAccess {
@@ -29,8 +29,7 @@ public interface IInventoryAccess {
* @param inventory the Inventory * @param inventory the Inventory
* @return the ISpecialEnderChest or null * @return the ISpecialEnderChest or null
*/ */
@Nullable @Nullable ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory);
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory);
/** /**
* Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
@@ -39,8 +38,7 @@ public interface IInventoryAccess {
* @param inventory the Inventory * @param inventory the Inventory
* @return the ISpecialPlayerInventory or null * @return the ISpecialPlayerInventory or null
*/ */
@Nullable @Nullable ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory);
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory);
/** /**
* Check if an Inventory is an ISpecialEnderChest implementation. * Check if an Inventory is an ISpecialEnderChest implementation.
@@ -48,7 +46,7 @@ public interface IInventoryAccess {
* @param inventory the Inventory * @param inventory the Inventory
* @return true if the Inventory is backed by an ISpecialEnderChest * @return true if the Inventory is backed by an ISpecialEnderChest
*/ */
public boolean isSpecialEnderChest(Inventory inventory); boolean isSpecialEnderChest(@NotNull Inventory inventory);
/** /**
* Check if an Inventory is an ISpecialPlayerInventory implementation. * Check if an Inventory is an ISpecialPlayerInventory implementation.
@@ -56,6 +54,6 @@ public interface IInventoryAccess {
* @param inventory the Inventory * @param inventory the Inventory
* @return true if the Inventory is backed by an ISpecialPlayerInventory * @return true if the Inventory is backed by an ISpecialPlayerInventory
*/ */
public boolean isSpecialPlayerInventory(Inventory inventory); boolean isSpecialPlayerInventory(@NotNull Inventory inventory);
} }

View File

@@ -1,50 +1,21 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal; package com.lishid.openinv.internal;
import org.bukkit.entity.Player; public interface ISpecialEnderChest extends ISpecialInventory {
import org.bukkit.inventory.Inventory;
public interface ISpecialEnderChest {
/**
* Gets the Inventory associated with this ISpecialEnderChest.
*
* @return the Inventory
*/
public Inventory getBukkitInventory();
/**
* Sets the Player associated with this ISpecialEnderChest online.
*
* @param player the Player coming online
*/
public void setPlayerOnline(Player player);
/**
* Sets the Player associated with this ISpecialEnderChest offline.
*/
public void setPlayerOffline();
/**
* Gets whether or not this ISpecialEnderChest is in use.
*
* @return true if the ISpecialEnderChest is in use
*/
public boolean isInUse();
} }

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2011-2019 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public interface ISpecialInventory {
/**
* Gets the Inventory associated with this ISpecialInventory.
*
* @return the Inventory
*/
@NotNull Inventory getBukkitInventory();
/**
* Sets the Player associated with this ISpecialInventory online.
*
* @param player the Player coming online
*/
void setPlayerOnline(@NotNull Player player);
/**
* Sets the Player associated with this ISpecialInventory offline.
*/
void setPlayerOffline();
/**
* Gets whether or not this ISpecialInventory is in use.
*
* @return true if the ISpecialInventory is in use
*/
boolean isInUse();
}

View File

@@ -1,50 +1,21 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal; package com.lishid.openinv.internal;
import org.bukkit.entity.Player; public interface ISpecialPlayerInventory extends ISpecialInventory {
import org.bukkit.inventory.Inventory;
public interface ISpecialPlayerInventory {
/**
* Gets the Inventory associated with this ISpecialPlayerInventory.
*
* @return the Inventory
*/
public Inventory getBukkitInventory();
/**
* Sets the Player associated with this ISpecialPlayerInventory online.
*
* @param player the Player coming online
*/
public void setPlayerOnline(Player player);
/**
* Sets the Player associated with this ISpecialPlayerInventory offline.
*/
public void setPlayerOffline();
/**
* Gets whether or not this ISpecialPlayerInventory is in use.
*
* @return true if the ISpecialPlayerInventory is in use
*/
public boolean isInUse();
} }

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvassembly</artifactId> <artifactId>openinvassembly</artifactId>

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
@@ -22,7 +38,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvapi</artifactId> <artifactId>openinvapi</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,9 +17,11 @@
package com.lishid.openinv.internal; package com.lishid.openinv.internal;
import java.util.Collection; import java.util.Collection;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface IPlayerDataManager { public interface IPlayerDataManager {
@@ -27,33 +29,43 @@ public interface IPlayerDataManager {
* Loads a Player for an OfflinePlayer. * Loads a Player for an OfflinePlayer.
* </p> * </p>
* This method is potentially blocking, and should not be called on the main thread. * This method is potentially blocking, and should not be called on the main thread.
* *
* @param offline * @param offline the OfflinePlayer
* @return * @return the Player loaded
*/ */
public Player loadPlayer(OfflinePlayer offline); @Nullable Player loadPlayer(@NotNull OfflinePlayer offline);
/** /**
* Gets a unique identifying string for an OfflinePlayer. * Gets a unique identifying string for an OfflinePlayer.
* *
* @param player * @param offline the OfflinePlayer
* @return * @return the unique identifier
*/ */
public String getPlayerDataID(OfflinePlayer player); @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline);
/** /**
* Gets an OfflinePlayer by the given unique identifier. * Gets an OfflinePlayer by the given unique identifier.
* *
* @param identifier the unique identifier * @param identifier the unique identifier
* @return the OfflinePlayer, or null if no exact match was found * @return the OfflinePlayer, or null if no exact match was found
*/ */
public OfflinePlayer getPlayerByID(String identifier); @Nullable OfflinePlayer getPlayerByID(@NotNull String identifier);
/** /**
* Gets a Collection of all Players currently online. * Gets a Collection of all Players currently online.
* *
* @return the Collection of Players * @return the Collection of Players
*/ */
public Collection<? extends Player> getOnlinePlayers(); @NotNull Collection<? extends Player> getOnlinePlayers();
/**
* Opens an ISpecialInventory for a Player.
*
* @param player the Player opening the ISpecialInventory
* @param inventory the Inventory
*`
* @return the InventoryView opened
*/
InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory);
} }

View File

@@ -1,16 +1,33 @@
package com.lishid.openinv.util; /*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
import java.util.Comparator; package com.lishid.openinv.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap; import com.google.common.collect.TreeMultimap;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/** /**
* A minimal thread-safe time-based cache implementation backed by a HashMap and TreeMultimap. * A minimal thread-safe time-based cache implementation backed by a HashMap and TreeMultimap.
* *
* @author Jikoo * @author Jikoo
*/ */
public class Cache<K, V> { public class Cache<K, V> {
@@ -22,24 +39,24 @@ public class Cache<K, V> {
/** /**
* Constructs a Cache with the specified retention duration, in use function, and post-removal function. * Constructs a Cache with the specified retention duration, in use function, and post-removal function.
* *
* @param retention duration after which keys are automatically invalidated if not in use * @param retention duration after which keys are automatically invalidated if not in use
* @param inUseCheck Function used to check if a key is considered in use * @param inUseCheck Function used to check if a key is considered in use
* @param postRemoval Function used to perform any operations required when a key is invalidated * @param postRemoval Function used to perform any operations required when a key is invalidated
*/ */
public Cache(long retention, Function<V> inUseCheck, Function<V> postRemoval) { public Cache(final long retention, final Function<V> inUseCheck, final Function<V> postRemoval) {
this.internal = new HashMap<K, V>(); this.internal = new HashMap<K, V>();
this.expiry = TreeMultimap.create(new Comparator<Long>() { this.expiry = TreeMultimap.create(new Comparator<Long>() {
@Override @Override
public int compare(Long long1, Long long2) { public int compare(final Long long1, final Long long2) {
return long1.compareTo(long2); return long1.compareTo(long2);
} }
}, },
new Comparator<K>() { new Comparator<K>() {
@Override @Override
public int compare(K k1, K k2) { public int compare(final K k1, final K k2) {
return 0; return k1 == k2 || k1 != null && k1.equals(k2) ? 0 : 1;
} }
}); });
@@ -51,70 +68,70 @@ public class Cache<K, V> {
/** /**
* Set a key and value pair. Keys are unique. Using an existing key will cause the old value to * Set a key and value pair. Keys are unique. Using an existing key will cause the old value to
* be overwritten and the expiration timer to be reset. * be overwritten and the expiration timer to be reset.
* *
* @param key key with which the specified value is to be associated * @param key key with which the specified value is to be associated
* @param value value to be associated with the specified key * @param value value to be associated with the specified key
*/ */
public void put(K key, V value) { public void put(final K key, final V value) {
// Invalidate key - runs lazy check and ensures value won't be cleaned up early // Invalidate key - runs lazy check and ensures value won't be cleaned up early
invalidate(key); this.invalidate(key);
synchronized (internal) { synchronized (this.internal) {
internal.put(key, value); this.internal.put(key, value);
expiry.put(System.currentTimeMillis() + retention, key); this.expiry.put(System.currentTimeMillis() + this.retention, key);
} }
} }
/** /**
* Returns the value to which the specified key is mapped, or null if no value is mapped for the key. * Returns the value to which the specified key is mapped, or null if no value is mapped for the key.
* *
* @param key the key whose associated value is to be returned * @param key the key whose associated value is to be returned
* @return the value to which the specified key is mapped, or null if no value is mapped for the key * @return the value to which the specified key is mapped, or null if no value is mapped for the key
*/ */
public V get(K key) { public V get(final K key) {
synchronized (internal) { // Run lazy check to clean cache
// Run lazy check to clean cache this.lazyCheck();
lazyCheck();
return internal.get(key); synchronized (this.internal) {
return this.internal.get(key);
} }
} }
/** /**
* Returns true if the specified key is mapped to a value. * Returns true if the specified key is mapped to a value.
* *
* @param key key to check if a mapping exists for * @param key key to check if a mapping exists for
* @return true if a mapping exists for the specified key * @return true if a mapping exists for the specified key
*/ */
public boolean containsKey(K key) { public boolean containsKey(final K key) {
synchronized (internal) { // Run lazy check to clean cache
// Run lazy check to clean cache this.lazyCheck();
lazyCheck();
return internal.containsKey(key); synchronized (this.internal) {
return this.internal.containsKey(key);
} }
} }
/** /**
* Forcibly invalidates a key, even if it is considered to be in use. * Forcibly invalidates a key, even if it is considered to be in use.
* *
* @param key key to invalidate * @param key key to invalidate
*/ */
public void invalidate(K key) { public void invalidate(final K key) {
synchronized (internal) { // Run lazy check to clean cache
// Run lazy check to clean cache this.lazyCheck();
lazyCheck();
if (!internal.containsKey(key)) { synchronized (this.internal) {
if (!this.internal.containsKey(key)) {
// Value either not present or cleaned by lazy check. Either way, we're good // Value either not present or cleaned by lazy check. Either way, we're good
return; return;
} }
// Remove stored object // Remove stored object
internal.remove(key); this.internal.remove(key);
// Remove expiration entry - prevents more work later, plus prevents issues with values invalidating early // Remove expiration entry - prevents more work later, plus prevents issues with values invalidating early
for (Iterator<Map.Entry<Long, K>> iterator = expiry.entries().iterator(); iterator.hasNext();) { for (Iterator<Map.Entry<Long, K>> iterator = this.expiry.entries().iterator(); iterator.hasNext();) {
if (key.equals(iterator.next().getValue())) { if (key.equals(iterator.next().getValue())) {
iterator.remove(); iterator.remove();
break; break;
@@ -127,12 +144,12 @@ public class Cache<K, V> {
* Forcibly invalidates all keys, even if they are considered to be in use. * Forcibly invalidates all keys, even if they are considered to be in use.
*/ */
public void invalidateAll() { public void invalidateAll() {
synchronized (internal) { synchronized (this.internal) {
for (V value : internal.values()) { for (V value : this.internal.values()) {
postRemoval.run(value); this.postRemoval.run(value);
} }
expiry.clear(); this.expiry.clear();
internal.clear(); this.internal.clear();
} }
} }
@@ -142,28 +159,36 @@ public class Cache<K, V> {
*/ */
private void lazyCheck() { private void lazyCheck() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long nextExpiry = now + retention; synchronized (this.internal) {
for (Iterator<Map.Entry<Long, K>> iterator = expiry.entries().iterator(); iterator.hasNext();) { List<K> inUse = new ArrayList<K>();
Map.Entry<Long, K> entry = iterator.next(); for (Iterator<Map.Entry<Long, K>> iterator = this.expiry.entries().iterator(); iterator
.hasNext();) {
Map.Entry<Long, K> entry = iterator.next();
if (entry.getKey() > now) { if (entry.getKey() > now) {
break; break;
}
iterator.remove();
if (this.inUseCheck.run(this.internal.get(entry.getValue()))) {
inUse.add(entry.getValue());
continue;
}
V value = this.internal.remove(entry.getValue());
if (value == null) {
continue;
}
this.postRemoval.run(value);
} }
iterator.remove(); long nextExpiry = now + this.retention;
for (K value : inUse) {
if (inUseCheck.run(internal.get(entry.getValue()))) { this.expiry.put(nextExpiry, value);
expiry.put(nextExpiry, entry.getValue());
continue;
} }
V value = internal.remove(entry.getValue());
if (value == null) {
continue;
}
postRemoval.run(value);
} }
} }

View File

@@ -1,8 +1,24 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.util; package com.lishid.openinv.util;
/** /**
* Abstraction for some simple cache calls. * Abstraction for some simple cache calls.
* *
* @author Jikoo * @author Jikoo
*/ */
public abstract class Function<V> { public abstract class Function<V> {

View File

@@ -1,13 +1,13 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
@@ -16,16 +16,14 @@
package com.lishid.openinv.util; package com.lishid.openinv.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import com.lishid.openinv.internal.IInventoryAccess; import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.IPlayerDataManager; import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@@ -63,13 +61,14 @@ public class InternalAccessor {
this.version = packageName.substring(packageName.lastIndexOf('.') + 1); this.version = packageName.substring(packageName.lastIndexOf('.') + 1);
try { try {
// TODO: implement support for CraftMagicNumbers#getMappingsVersion
Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialPlayerInventory"); Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialPlayerInventory");
Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest"); Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest");
this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager"); this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager");
this.inventoryAccess = this.createObject(IInventoryAccess.class, "InventoryAccess"); this.inventoryAccess = this.createObject(IInventoryAccess.class, "InventoryAccess");
this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer"); this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer");
this.supported = true; this.supported = true;
} catch (Exception e) {} } catch (Exception ignored) {}
} }
private <T> T createObject(final Class<? extends T> assignableClass, final String className, private <T> T createObject(final Class<? extends T> assignableClass, final String className,
@@ -108,9 +107,7 @@ public class InternalAccessor {
for (Object object : params) { for (Object object : params) {
builder.append(object.getClass().getName()).append(", "); builder.append(object.getClass().getName()).append(", ");
} }
if (params.length > 0) { builder.delete(builder.length() - 2, builder.length());
builder.delete(builder.length() - 2, builder.length());
}
String message = builder.append(']').toString(); String message = builder.append(']').toString();
this.plugin.getLogger().warning(message); this.plugin.getLogger().warning(message);

View File

@@ -1,38 +1,69 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.util; package com.lishid.openinv.util;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
public enum Permissions { public enum Permissions {
OPENINV("OpenInv.openinv"), OPENINV("openinv"),
OVERRIDE("OpenInv.override"), OVERRIDE("override"),
EXEMPT("OpenInv.exempt"), EXEMPT("exempt"),
CROSSWORLD("OpenInv.crossworld"), CROSSWORLD("crossworld"),
SILENT("OpenInv.silent"), SILENT("silent"),
ANYCHEST("OpenInv.anychest"), SILENT_DEFAULT("silent.default"),
ENDERCHEST("OpenInv.openender"), ANYCHEST("anychest"),
ENDERCHEST_ALL("OpenInv.openenderall"), ANY_DEFAULT("any.default"),
SEARCH("OpenInv.search"), ENDERCHEST("openender"),
EDITINV("OpenInv.editinv"), ENDERCHEST_ALL("openenderall"),
EDITENDER("OpenInv.editender"), SEARCH("search"),
OPENSELF("OpenInv.openself"); EDITINV("editinv"),
EDITENDER("editender"),
OPENSELF("openself");
private final String permission; private final String permission;
private Permissions(String permission) { Permissions(String permission) {
this.permission = permission; this.permission = "OpenInv." + permission;
} }
public boolean hasPermission(Permissible permissible) { public boolean hasPermission(Permissible permissible) {
String[] parts = permission.split("\\.");
String perm = ""; boolean hasPermission = permissible.hasPermission(permission);
for (int i = 0; i < parts.length; i++) { if (hasPermission || permissible.isPermissionSet(permission)) {
if (permissible.hasPermission(perm + "*")) { return hasPermission;
return true;
}
perm += parts[i] + ".";
} }
return permissible.hasPermission(permission);
StringBuilder permissionDestroyer = new StringBuilder(permission);
for (int lastPeriod = permissionDestroyer.lastIndexOf("."); lastPeriod > 0;
lastPeriod = permissionDestroyer.lastIndexOf(".")) {
permissionDestroyer.delete(lastPeriod + 1, permissionDestroyer.length()).append('*');
hasPermission = permissible.hasPermission(permissionDestroyer.toString());
if (hasPermission || permissible.isPermissionSet(permissionDestroyer.toString())) {
return hasPermission;
}
permissionDestroyer.delete(lastPeriod, permissionDestroyer.length());
}
return permissible.hasPermission("*");
} }
} }

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_4_5</artifactId> <artifactId>openinvadapter1_4_5</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,11 +17,6 @@
package com.lishid.openinv.internal.v1_4_5; package com.lishid.openinv.internal.v1_4_5;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_5.AxisAlignedBB; import net.minecraft.server.v1_4_5.AxisAlignedBB;
import net.minecraft.server.v1_4_5.BlockEnderChest; import net.minecraft.server.v1_4_5.BlockEnderChest;
import net.minecraft.server.v1_4_5.Container; import net.minecraft.server.v1_4_5.Container;
@@ -34,43 +29,46 @@ import net.minecraft.server.v1_4_5.Packet100OpenWindow;
import net.minecraft.server.v1_4_5.TileEntityChest; import net.minecraft.server.v1_4_5.TileEntityChest;
import net.minecraft.server.v1_4_5.TileEntityEnderChest; import net.minecraft.server.v1_4_5.TileEntityEnderChest;
import net.minecraft.server.v1_4_5.World; import net.minecraft.server.v1_4_5.World;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_4_5.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_4_5.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override @Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) { public boolean isAnySilentContainer(@NotNull Block bukkitBlock) {
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest; return bukkitBlock.getType() == Material.ENDER_CHEST || bukkitBlock.getState() instanceof org.bukkit.block.Chest;
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) { public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull Block bukkitBlock) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = PlayerDataManager.getHandle(p); World world = PlayerDataManager.getHandle(bukkitPlayer).world;
World world = player.world;
if (block instanceof BlockEnderChest) { if (bukkitBlock instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots. // Ender chests are not blocked by ocelots.
return world.t(block.getX(), block.getY() + 1, block.getZ()); return world.t(bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
// If block or ocelot on top // If block or ocelot on top
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) { if (isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ())) {
return true; return true;
} }
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
// If block next to chest is chest and has a block or ocelot on top // If block next to chest is chest and has a block or ocelot on top
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() + 1);
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if(world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() - 1);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() + 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() - 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
return false; return false;
@@ -93,18 +91,18 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is API-only // Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
return true; return true;
} }
World world = player.world; World world = player.world;
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ()); Object tile = world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (tile == null) { if (tile == null) {
return false; return false;
@@ -123,20 +121,20 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
IInventory inventory = (IInventory) tile; IInventory inventory = (IInventory) tile;
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1));
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1), inventory);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()));
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()), inventory);
} }
// AnyChest only // AnyChest only
if (!silentchest) { if (!silent) {
player.openContainer(inventory); player.openContainer(inventory);
return true; return true;
} }
@@ -160,9 +158,12 @@ public class AnySilentContainer implements IAnySilentContainer {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container."); bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false; return false;
} }
} }
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_4_5.IInventory; import net.minecraft.server.v1_4_5.IInventory;
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,44 +1,43 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_4_5; package com.lishid.openinv.internal.v1_4_5;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_5.EntityPlayer; import net.minecraft.server.v1_4_5.EntityPlayer;
import net.minecraft.server.v1_4_5.ItemInWorldManager; import net.minecraft.server.v1_4_5.ItemInWorldManager;
import net.minecraft.server.v1_4_5.MinecraftServer; import net.minecraft.server.v1_4_5.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_4_5.CraftServer; import org.bukkit.craftbukkit.v1_4_5.CraftServer;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure the player has data // Ensure the player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -49,7 +48,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new ItemInWorldManager(server.getWorldServer(0))); new ItemInWorldManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -59,12 +58,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getName(); return offline.getName();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
// Ensure player is a real player, otherwise return null // Ensure player is a real player, otherwise return null
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
@@ -74,7 +73,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Arrays.asList(Bukkit.getOnlinePlayers()); return Arrays.asList(Bukkit.getOnlinePlayers());
} }
@@ -98,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -22,9 +22,9 @@ import net.minecraft.server.v1_4_5.IInventory;
import net.minecraft.server.v1_4_5.ItemStack; import net.minecraft.server.v1_4_5.ItemStack;
import net.minecraft.server.v1_4_5.PlayerInventory; import net.minecraft.server.v1_4_5.PlayerInventory;
public class SilentContainerChest extends ContainerChest { class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2) { SilentContainerChest(IInventory i1, IInventory i2) {
super(i1, i2); super(i1, i2);
// Send close signal // Send close signal
i2.f(); i2.f();

View File

@@ -1,54 +1,52 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_4_5; package com.lishid.openinv.internal.v1_4_5;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_4_5.EntityPlayer; import net.minecraft.server.v1_4_5.EntityPlayer;
import net.minecraft.server.v1_4_5.IInventory; import net.minecraft.server.v1_4_5.IInventory;
import net.minecraft.server.v1_4_5.InventoryEnderChest; import net.minecraft.server.v1_4_5.InventoryEnderChest;
import net.minecraft.server.v1_4_5.InventorySubcontainer; import net.minecraft.server.v1_4_5.InventorySubcontainer;
import net.minecraft.server.v1_4_5.ItemStack; 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.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>(); private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private boolean playerOnline = false; private boolean playerOnline;
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity(); this.owner = nmsPlayer.getBukkitEntity();
@@ -56,12 +54,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
@@ -70,7 +68,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); field.set(playerEnderChest, this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,20 +17,18 @@
package com.lishid.openinv.internal.v1_4_5; package com.lishid.openinv.internal.v1_4_5;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_4_5.ItemStack; import net.minecraft.server.v1_4_5.ItemStack;
import net.minecraft.server.v1_4_5.PlayerInventory; import net.minecraft.server.v1_4_5.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -40,12 +38,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = PlayerDataManager.getHandle(player); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_4_6</artifactId> <artifactId>openinvadapter1_4_6</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,11 +17,6 @@
package com.lishid.openinv.internal.v1_4_6; package com.lishid.openinv.internal.v1_4_6;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_6.AxisAlignedBB; import net.minecraft.server.v1_4_6.AxisAlignedBB;
import net.minecraft.server.v1_4_6.BlockEnderChest; import net.minecraft.server.v1_4_6.BlockEnderChest;
import net.minecraft.server.v1_4_6.Container; import net.minecraft.server.v1_4_6.Container;
@@ -34,43 +29,46 @@ import net.minecraft.server.v1_4_6.Packet100OpenWindow;
import net.minecraft.server.v1_4_6.TileEntityChest; import net.minecraft.server.v1_4_6.TileEntityChest;
import net.minecraft.server.v1_4_6.TileEntityEnderChest; import net.minecraft.server.v1_4_6.TileEntityEnderChest;
import net.minecraft.server.v1_4_6.World; import net.minecraft.server.v1_4_6.World;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_4_6.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_4_6.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override @Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) { public boolean isAnySilentContainer(@NotNull Block bukkitBlock) {
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest; return bukkitBlock.getType() == Material.ENDER_CHEST || bukkitBlock.getState() instanceof org.bukkit.block.Chest;
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) { public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull Block bukkitBlock) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = PlayerDataManager.getHandle(p); World world = PlayerDataManager.getHandle(bukkitPlayer).world;
World world = player.world;
if (block instanceof BlockEnderChest) { if (bukkitBlock instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots. // Ender chests are not blocked by ocelots.
return world.t(block.getX(), block.getY() + 1, block.getZ()); return world.t(bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
// If block or ocelot on top // If block or ocelot on top
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) { if (isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ())) {
return true; return true;
} }
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
// If block next to chest is chest and has a block or ocelot on top // If block next to chest is chest and has a block or ocelot on top
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() + 1);
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if(world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() - 1);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() + 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() - 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
return false; return false;
@@ -93,18 +91,18 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is API-only // Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
return true; return true;
} }
World world = player.world; World world = player.world;
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ()); Object tile = world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (tile == null) { if (tile == null) {
return false; return false;
@@ -123,20 +121,20 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
IInventory inventory = (IInventory) tile; IInventory inventory = (IInventory) tile;
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1));
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1), inventory);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()));
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()), inventory);
} }
// AnyChest only // AnyChest only
if (!silentchest) { if (!silent) {
player.openContainer(inventory); player.openContainer(inventory);
return true; return true;
} }
@@ -160,9 +158,12 @@ public class AnySilentContainer implements IAnySilentContainer {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container."); bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false; return false;
} }
} }
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_4_6.IInventory; import net.minecraft.server.v1_4_6.IInventory;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,44 +1,43 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_4_6; package com.lishid.openinv.internal.v1_4_6;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_6.EntityPlayer; import net.minecraft.server.v1_4_6.EntityPlayer;
import net.minecraft.server.v1_4_6.MinecraftServer; import net.minecraft.server.v1_4_6.MinecraftServer;
import net.minecraft.server.v1_4_6.PlayerInteractManager; import net.minecraft.server.v1_4_6.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_4_6.CraftServer; import org.bukkit.craftbukkit.v1_4_6.CraftServer;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure the player has data // Ensure the player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -49,7 +48,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -59,12 +58,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getName(); return offline.getName();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
// Ensure player is a real player, otherwise return null // Ensure player is a real player, otherwise return null
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
@@ -74,7 +73,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Arrays.asList(Bukkit.getOnlinePlayers()); return Arrays.asList(Bukkit.getOnlinePlayers());
} }
@@ -98,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -22,9 +22,9 @@ import net.minecraft.server.v1_4_6.IInventory;
import net.minecraft.server.v1_4_6.ItemStack; import net.minecraft.server.v1_4_6.ItemStack;
import net.minecraft.server.v1_4_6.PlayerInventory; import net.minecraft.server.v1_4_6.PlayerInventory;
public class SilentContainerChest extends ContainerChest { class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2) { SilentContainerChest(IInventory i1, IInventory i2) {
super(i1, i2); super(i1, i2);
// Send close signal // Send close signal
i2.f(); i2.f();

View File

@@ -1,54 +1,52 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_4_6; package com.lishid.openinv.internal.v1_4_6;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_4_6.EntityPlayer; import net.minecraft.server.v1_4_6.EntityPlayer;
import net.minecraft.server.v1_4_6.IInventory; import net.minecraft.server.v1_4_6.IInventory;
import net.minecraft.server.v1_4_6.InventoryEnderChest; import net.minecraft.server.v1_4_6.InventoryEnderChest;
import net.minecraft.server.v1_4_6.InventorySubcontainer; import net.minecraft.server.v1_4_6.InventorySubcontainer;
import net.minecraft.server.v1_4_6.ItemStack; 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.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>(); private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private boolean playerOnline = false; private boolean playerOnline;
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(((CraftPlayer) player).getHandle().getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
((CraftPlayer) player).getHandle().getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity(); this.owner = nmsPlayer.getBukkitEntity();
@@ -56,12 +54,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
@@ -70,7 +68,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); field.set(playerEnderChest, this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,20 +17,18 @@
package com.lishid.openinv.internal.v1_4_6; package com.lishid.openinv.internal.v1_4_6;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_4_6.ItemStack; import net.minecraft.server.v1_4_6.ItemStack;
import net.minecraft.server.v1_4_6.PlayerInventory; import net.minecraft.server.v1_4_6.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -40,12 +38,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = PlayerDataManager.getHandle(player); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;

View File

@@ -1,11 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?> <!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId> <artifactId>openinvparent</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
@@ -18,7 +33,7 @@
<profile> <profile>
<id>latest</id> <id>latest</id>
<modules> <modules>
<module>v1_12_R1</module> <module>v1_14_R1</module>
</modules> </modules>
</profile> </profile>
@@ -26,8 +41,8 @@
<id>recent</id> <id>recent</id>
<!-- The recent profile is for the most recent 2 versions. --> <!-- The recent profile is for the most recent 2 versions. -->
<modules> <modules>
<module>v1_11_R1</module> <module>v1_13_R2</module>
<module>v1_12_R1</module> <module>v1_14_R1</module>
</modules> </modules>
</profile> </profile>
@@ -44,7 +59,6 @@
<module>v1_6_R1</module> <module>v1_6_R1</module>
<module>v1_6_R2</module> <module>v1_6_R2</module>
<module>v1_6_R3</module> <module>v1_6_R3</module>
<!-- TODO: Recompile CB for 1_7_R1 through 1_7_R4, currently using whatever jars worked -->
<module>v1_7_R1</module> <module>v1_7_R1</module>
<module>v1_7_R2</module> <module>v1_7_R2</module>
<module>v1_7_R3</module> <module>v1_7_R3</module>
@@ -57,9 +71,12 @@
<module>v1_10_R1</module> <module>v1_10_R1</module>
<module>v1_11_R1</module> <module>v1_11_R1</module>
<module>v1_12_R1</module> <module>v1_12_R1</module>
<module>v1_13_R1</module>
<module>v1_13_R2</module>
<module>v1_14_R1</module>
</modules> </modules>
</profile> </profile>
</profiles> </profiles>
</project> </project>

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_10_R1</artifactId> <artifactId>openinvadapter1_10_R1</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,45 +17,55 @@
package com.lishid.openinv.internal.v1_10_R1; package com.lishid.openinv.internal.v1_10_R1;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import java.lang.reflect.Field;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_10_R1.AxisAlignedBB; import net.minecraft.server.v1_10_R1.AxisAlignedBB;
import net.minecraft.server.v1_10_R1.Block; import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockChest; import net.minecraft.server.v1_10_R1.BlockChest;
import net.minecraft.server.v1_10_R1.BlockEnderChest; import net.minecraft.server.v1_10_R1.BlockEnderChest;
import net.minecraft.server.v1_10_R1.BlockPosition; import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.Container;
import net.minecraft.server.v1_10_R1.Entity; import net.minecraft.server.v1_10_R1.Entity;
import net.minecraft.server.v1_10_R1.EntityOcelot; import net.minecraft.server.v1_10_R1.EntityOcelot;
import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.EnumDirection; import net.minecraft.server.v1_10_R1.EnumDirection;
import net.minecraft.server.v1_10_R1.EnumGamemode;
import net.minecraft.server.v1_10_R1.ITileInventory; import net.minecraft.server.v1_10_R1.ITileInventory;
import net.minecraft.server.v1_10_R1.InventoryEnderChest; import net.minecraft.server.v1_10_R1.InventoryEnderChest;
import net.minecraft.server.v1_10_R1.InventoryLargeChest; import net.minecraft.server.v1_10_R1.InventoryLargeChest;
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow; import net.minecraft.server.v1_10_R1.PlayerInteractManager;
import net.minecraft.server.v1_10_R1.StatisticList; import net.minecraft.server.v1_10_R1.StatisticList;
import net.minecraft.server.v1_10_R1.TileEntity; import net.minecraft.server.v1_10_R1.TileEntity;
import net.minecraft.server.v1_10_R1.TileEntityChest; import net.minecraft.server.v1_10_R1.TileEntityChest;
import net.minecraft.server.v1_10_R1.TileEntityEnderChest; import net.minecraft.server.v1_10_R1.TileEntityEnderChest;
import net.minecraft.server.v1_10_R1.World; import net.minecraft.server.v1_10_R1.World;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override private Field playerInteractManagerGamemode;
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest; public AnySilentContainer() {
try {
this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
this.playerInteractManagerGamemode.setAccessible(true);
} catch (Exception e) {
System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
e.printStackTrace();
}
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) { public boolean isAnySilentContainer(@NotNull org.bukkit.block.Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); return bukkitBlock.getType() == Material.ENDER_CHEST || bukkitBlock.getState() instanceof org.bukkit.block.Chest;
World world = player.world; }
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
@Override
public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull org.bukkit.block.Block bukkitBlock) {
World world = PlayerDataManager.getHandle(bukkitPlayer).world;
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
Block block = world.getType(blockPosition).getBlock(); Block block = world.getType(blockPosition).getBlock();
if (block instanceof BlockEnderChest) { if (block instanceof BlockEnderChest) {
@@ -110,19 +120,19 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull org.bukkit.block.Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is pretty much API-only // Silent ender chest is pretty much API-only
if (silentchest && b.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
player.b(StatisticList.X); player.b(StatisticList.X);
return true; return true;
} }
World world = player.world; World world = player.world;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ()); BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
Object tile = world.getTileEntity(blockPosition); Object tile = world.getTileEntity(blockPosition);
if (tile == null) { if (tile == null) {
@@ -144,7 +154,6 @@ public class AnySilentContainer implements IAnySilentContainer {
ITileInventory tileInventory = (ITileInventory) tile; ITileInventory tileInventory = (ITileInventory) tile;
Block block = world.getType(blockPosition).getBlock(); Block block = world.getType(blockPosition).getBlock();
Container container = null;
if (block instanceof BlockChest) { if (block instanceof BlockChest) {
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) { for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
@@ -176,38 +185,63 @@ public class AnySilentContainer implements IAnySilentContainer {
} else if (blockChest.g == BlockChest.Type.TRAP) { } else if (blockChest.g == BlockChest.Type.TRAP) {
player.b(StatisticList.W); player.b(StatisticList.W);
} }
if (silentchest) {
container = new SilentContainerChest(player.inventory, tileInventory, player);
}
} }
// AnyChest only - SilentChest not active or container unsupported // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silentchest || container == null) { if (!silent || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory); player.openContainer(tileInventory);
return true; return true;
} }
// SilentChest // SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
break;
default:
return;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try { try {
// Call InventoryOpenEvent if (!this.playerInteractManagerGamemode.isAccessible()) {
container = CraftEventFactory.callInventoryOpenEvent(player, container, false); // Just in case, ensure accessible.
if (container == null) { this.playerInteractManagerGamemode.setAccessible(true);
return false;
} }
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
// Open window
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize()));
player.activeContainer = container;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false;
} }
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_10_R1.IInventory; import net.minecraft.server.v1_10_R1.IInventory;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,46 +1,44 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_10_R1; package com.lishid.openinv.internal.v1_10_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import com.mojang.authlib.GameProfile;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.MinecraftServer; import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.PlayerInteractManager; import net.minecraft.server.v1_10_R1.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer; import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure player has data // Ensure player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -51,7 +49,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -61,12 +59,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getUniqueId().toString(); return offline.getUniqueId().toString();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
try { try {
UUID uuid = UUID.fromString(identifier); UUID uuid = UUID.fromString(identifier);
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
@@ -82,7 +80,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Bukkit.getOnlinePlayers(); return Bukkit.getOnlinePlayers();
} }
@@ -106,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,45 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_10_R1;
import net.minecraft.server.v1_10_R1.ContainerChest;
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.IInventory;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) {
super(i1, i2, e1);
// Send close signal
i2.closeContainer(e1);
}
@Override
public void b(EntityHuman entityHuman) {
// Don't send close signal twice, might screw up
PlayerInventory playerinventory = entityHuman.inventory;
if (playerinventory.getCarried() != null) {
ItemStack carried = playerinventory.getCarried();
playerinventory.setCarried(null);
entityHuman.drop(carried, false);
}
}
}

View File

@@ -1,47 +1,45 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_10_R1; package com.lishid.openinv.internal.v1_10_R1;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.IInventory; import net.minecraft.server.v1_10_R1.IInventory;
import net.minecraft.server.v1_10_R1.InventoryEnderChest; import net.minecraft.server.v1_10_R1.InventoryEnderChest;
import net.minecraft.server.v1_10_R1.InventorySubcontainer; import net.minecraft.server.v1_10_R1.InventorySubcontainer;
import net.minecraft.server.v1_10_R1.ItemStack; import net.minecraft.server.v1_10_R1.ItemStack;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(), PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = nmsPlayer.getBukkitEntity(); this.bukkitOwner = nmsPlayer.getBukkitEntity();
@@ -69,18 +67,18 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity(); this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemArrays(nmsPlayer.getEnderChest(), this.items); setItemArrays(nmsPlayer.getEnderChest(), this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

View File

@@ -1,40 +1,37 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_10_R1; package com.lishid.openinv.internal.v1_10_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_10_R1.EntityHuman; import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.ItemStack; import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.PlayerInventory; import net.minecraft.server.v1_10_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final ItemStack[] extra = new ItemStack[4]; private final ItemStack[] extra = new ItemStack[4];
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -80,12 +77,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = PlayerDataManager.getHandle(player); this.player = PlayerDataManager.getHandle(player);
setItemArrays(this.player.inventory, items, armor, extraSlots); setItemArrays(this.player.inventory, items, armor, extraSlots);
@@ -286,6 +283,11 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName(); return player.getName();
} }
@Override
public boolean hasCustomName() {
return true;
}
@Override @Override
public boolean a(EntityHuman entityhuman) { public boolean a(EntityHuman entityhuman) {
return true; return true;

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_11_R1</artifactId> <artifactId>openinvadapter1_11_R1</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,55 +17,63 @@
package com.lishid.openinv.internal.v1_11_R1; package com.lishid.openinv.internal.v1_11_R1;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import java.lang.reflect.Field;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import net.minecraft.server.v1_11_R1.AxisAlignedBB; import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.Block; import net.minecraft.server.v1_11_R1.Block;
import net.minecraft.server.v1_11_R1.BlockChest; import net.minecraft.server.v1_11_R1.BlockChest;
import net.minecraft.server.v1_11_R1.BlockEnderChest; import net.minecraft.server.v1_11_R1.BlockEnderChest;
import net.minecraft.server.v1_11_R1.BlockPosition; import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.BlockShulkerBox; import net.minecraft.server.v1_11_R1.BlockShulkerBox;
import net.minecraft.server.v1_11_R1.Container;
import net.minecraft.server.v1_11_R1.Entity; import net.minecraft.server.v1_11_R1.Entity;
import net.minecraft.server.v1_11_R1.EntityOcelot; import net.minecraft.server.v1_11_R1.EntityOcelot;
import net.minecraft.server.v1_11_R1.EntityPlayer; import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.EnumDirection; import net.minecraft.server.v1_11_R1.EnumDirection;
import net.minecraft.server.v1_11_R1.EnumGamemode;
import net.minecraft.server.v1_11_R1.IBlockData; import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.ITileInventory; import net.minecraft.server.v1_11_R1.ITileInventory;
import net.minecraft.server.v1_11_R1.InventoryEnderChest; import net.minecraft.server.v1_11_R1.InventoryEnderChest;
import net.minecraft.server.v1_11_R1.InventoryLargeChest; import net.minecraft.server.v1_11_R1.InventoryLargeChest;
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow; import net.minecraft.server.v1_11_R1.PlayerInteractManager;
import net.minecraft.server.v1_11_R1.StatisticList; import net.minecraft.server.v1_11_R1.StatisticList;
import net.minecraft.server.v1_11_R1.TileEntity; import net.minecraft.server.v1_11_R1.TileEntity;
import net.minecraft.server.v1_11_R1.TileEntityChest; import net.minecraft.server.v1_11_R1.TileEntityChest;
import net.minecraft.server.v1_11_R1.TileEntityEnderChest; import net.minecraft.server.v1_11_R1.TileEntityEnderChest;
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox; import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
import net.minecraft.server.v1_11_R1.World; import net.minecraft.server.v1_11_R1.World;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory; import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
private Field playerInteractManagerGamemode;
public AnySilentContainer() {
try {
this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
this.playerInteractManagerGamemode.setAccessible(true);
} catch (Exception e) {
System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
e.printStackTrace();
}
}
@Override @Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) { public boolean isAnySilentContainer(@NotNull org.bukkit.block.Block bukkitBlock) {
if (block.getType() == Material.ENDER_CHEST) { if (bukkitBlock.getType() == Material.ENDER_CHEST) {
return true; return true;
} }
BlockState state = block.getState(); BlockState state = bukkitBlock.getState();
return state instanceof org.bukkit.block.Chest || state instanceof org.bukkit.block.ShulkerBox; return state instanceof org.bukkit.block.Chest || state instanceof org.bukkit.block.ShulkerBox;
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) { public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull org.bukkit.block.Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world; World world = PlayerDataManager.getHandle(bukkitPlayer).world;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ()); BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = world.getType(blockPosition); IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock(); Block block = blockData.getBlock();
@@ -152,19 +160,19 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull org.bukkit.block.Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is pretty much API-only // Silent ender chest is pretty much API-only
if (silentchest && b.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
player.b(StatisticList.getStatistic("stat.enderchestOpened")); player.b(StatisticList.getStatistic("stat.enderchestOpened"));
return true; return true;
} }
final World world = player.world; final World world = player.world;
final BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ()); final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
final Object tile = world.getTileEntity(blockPosition); final Object tile = world.getTileEntity(blockPosition);
if (tile == null) { if (tile == null) {
@@ -186,7 +194,6 @@ public class AnySilentContainer implements IAnySilentContainer {
ITileInventory tileInventory = (ITileInventory) tile; ITileInventory tileInventory = (ITileInventory) tile;
Block block = world.getType(blockPosition).getBlock(); Block block = world.getType(blockPosition).getBlock();
Container container = null;
if (block instanceof BlockChest) { if (block instanceof BlockChest) {
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) { for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
@@ -218,68 +225,68 @@ public class AnySilentContainer implements IAnySilentContainer {
} else if (blockChest.g == BlockChest.Type.TRAP) { } else if (blockChest.g == BlockChest.Type.TRAP) {
player.b(StatisticList.getStatistic("stat.trappedChestTriggered")); player.b(StatisticList.getStatistic("stat.trappedChestTriggered"));
} }
if (silentchest) {
container = new SilentContainerChest(player.inventory, tileInventory, player);
}
} }
if (block instanceof BlockShulkerBox) { if (block instanceof BlockShulkerBox) {
player.b(StatisticList.getStatistic("stat.shulkerBoxOpened")); player.b(StatisticList.getStatistic("stat.shulkerBoxOpened"));
if (silentchest && tileInventory instanceof TileEntityShulkerBox) {
// Set value to current + 1. Ensures consistency later when resetting.
SilentContainerShulkerBox.setOpenValue((TileEntityShulkerBox) tileInventory,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tileInventory) + 1);
container = new SilentContainerShulkerBox(player.inventory, tileInventory, player);
}
} }
// AnyChest only - SilentChest not active or container unsupported // AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silentchest || container == null) { if (!silent || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory); player.openContainer(tileInventory);
return true; return true;
} }
// SilentChest // SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
case SHULKER_BOX:
break;
default:
return;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try { try {
// Call InventoryOpenEvent if (!this.playerInteractManagerGamemode.isAccessible()) {
container = CraftEventFactory.callInventoryOpenEvent(player, container, false); // Just in case, ensure accessible.
if (container == null) { this.playerInteractManagerGamemode.setAccessible(true);
return false;
} }
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
// Open window
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize()));
player.activeContainer = container;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
// Special handling for shulker boxes - reset value for viewers to what it was initially.
if (tile instanceof TileEntityShulkerBox) {
new BukkitRunnable() {
@Override
public void run() {
// TODO hacky
Object tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return;
}
TileEntityShulkerBox box = (TileEntityShulkerBox) tile;
// Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more.
SilentContainerShulkerBox.setOpenValue(box,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) - 2);
}
}.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2);
}
return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false;
} }
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_11_R1.IInventory; import net.minecraft.server.v1_11_R1.IInventory;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,46 +1,44 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_11_R1; package com.lishid.openinv.internal.v1_11_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import com.mojang.authlib.GameProfile;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_11_R1.EntityPlayer; import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.MinecraftServer; import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.PlayerInteractManager; import net.minecraft.server.v1_11_R1.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_11_R1.CraftServer; import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure player has data // Ensure player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -51,7 +49,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -61,12 +59,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getUniqueId().toString(); return offline.getUniqueId().toString();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
try { try {
UUID uuid = UUID.fromString(identifier); UUID uuid = UUID.fromString(identifier);
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
@@ -82,7 +80,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Bukkit.getOnlinePlayers(); return Bukkit.getOnlinePlayers();
} }
@@ -106,4 +104,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,46 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import net.minecraft.server.v1_11_R1.ContainerChest;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest {
public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
// Send close signal
iInventory.closeContainer(entityHuman);
}
@Override
public void b(EntityHuman entityHuman) {
// Don't send close signal twice, might screw up
PlayerInventory playerinventory = entityHuman.inventory;
if (playerinventory.getCarried() != ItemStack.a) {
ItemStack carried = playerinventory.getCarried();
playerinventory.setCarried(ItemStack.a);
entityHuman.drop(carried, false);
}
}
}

View File

@@ -1,56 +0,0 @@
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
import net.minecraft.server.v1_11_R1.ContainerShulkerBox;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.PlayerInventory;
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
public class SilentContainerShulkerBox extends ContainerShulkerBox {
private static Field fieldShulkerActionData;
public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
}
@Override
public void b(EntityHuman entityHuman) {
PlayerInventory playerinventory = entityHuman.inventory;
if (!playerinventory.getCarried().isEmpty()) {
entityHuman.drop(playerinventory.getCarried(), false);
playerinventory.setCarried(ItemStack.a);
}
}
private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
if (fieldShulkerActionData == null) {
fieldShulkerActionData = TileEntityShulkerBox.class.getDeclaredField("h");
fieldShulkerActionData.setAccessible(true);
}
return fieldShulkerActionData;
}
public static void setOpenValue(TileEntityShulkerBox tileShulkerBox, Object value) {
try {
exposeOpenStatus().set(tileShulkerBox, value);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Integer getOpenValue(TileEntityShulkerBox tileShulkerBox) {
try {
return (Integer) exposeOpenStatus().get(tileShulkerBox);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
}

View File

@@ -1,48 +1,46 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_11_R1; package com.lishid.openinv.internal.v1_11_R1;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_11_R1.EntityPlayer; import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.IInventory; import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.InventoryEnderChest; import net.minecraft.server.v1_11_R1.InventoryEnderChest;
import net.minecraft.server.v1_11_R1.InventorySubcontainer; import net.minecraft.server.v1_11_R1.InventorySubcontainer;
import net.minecraft.server.v1_11_R1.ItemStack; import net.minecraft.server.v1_11_R1.ItemStack;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(), PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = nmsPlayer.getBukkitEntity(); this.bukkitOwner = nmsPlayer.getBukkitEntity();
@@ -70,18 +68,18 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity(); this.bukkitOwner = nmsPlayer.getBukkitEntity();
setItemLists(nmsPlayer.getEnderChest(), this.items); setItemLists(nmsPlayer.getEnderChest(), this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

View File

@@ -1,42 +1,39 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_11_R1; package com.lishid.openinv.internal.v1_11_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.Arrays;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_11_R1.ContainerUtil; import net.minecraft.server.v1_11_R1.ContainerUtil;
import net.minecraft.server.v1_11_R1.EntityHuman; import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.ItemStack; import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.NonNullList; import net.minecraft.server.v1_11_R1.NonNullList;
import net.minecraft.server.v1_11_R1.PlayerInventory; import net.minecraft.server.v1_11_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -70,7 +67,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
field = PlayerInventory.class.getDeclaredField("g"); field = PlayerInventory.class.getDeclaredField("g");
field.setAccessible(true); field.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots })); field.set(inventory, Arrays.asList(items, armor, extraSlots));
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
// Unable to set final fields to item arrays, we're screwed. Noisily fail. // Unable to set final fields to item arrays, we're screwed. Noisily fail.
e.printStackTrace(); e.printStackTrace();
@@ -82,14 +79,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = PlayerDataManager.getHandle(player);; this.player = PlayerDataManager.getHandle(player);
setItemArrays(this.player.inventory, items, armor, extraSlots); setItemArrays(this.player.inventory, items, armor, extraSlots);
playerOnline = true; playerOnline = true;
} }
@@ -157,7 +154,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return ItemStack.a; return ItemStack.a;
} }
return list == null || list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j); return list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
} }
@Override @Override
@@ -182,7 +179,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return ItemStack.a; return ItemStack.a;
} }
if (list != null && !list.get(i).isEmpty()) { if (!list.get(i).isEmpty()) {
ItemStack itemstack = list.get(i); ItemStack itemstack = list.get(i);
list.set(i, ItemStack.a); list.set(i, ItemStack.a);
@@ -215,9 +212,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return; return;
} }
if (list != null) { list.set(i, itemstack);
list.set(i, itemstack);
}
} }
private int getReversedItemSlotNum(int i) { private int getReversedItemSlotNum(int i) {
@@ -251,6 +246,11 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return player.getName(); return player.getName();
} }
@Override
public boolean hasCustomName() {
return true;
}
@Override @Override
public boolean a(EntityHuman entityhuman) { public boolean a(EntityHuman entityhuman) {
return true; return true;

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_12_R1</artifactId> <artifactId>openinvadapter1_12_R1</artifactId>
@@ -21,8 +37,21 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View File

@@ -1,208 +1,80 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. This program is free software: you can * Copyright (C) 2011-2018 lishid. All rights reserved.
* 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 * This program is free software: you can redistribute it and/or modify
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * it under the terms of the GNU General Public License as published by
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should * the Free Software Foundation, version 3.
* have received a copy of the GNU General Public License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. * 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 <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_12_R1; package com.lishid.openinv.internal.v1_12_R1;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import java.lang.reflect.Field;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import net.minecraft.server.v1_12_R1.AxisAlignedBB; import net.minecraft.server.v1_12_R1.AxisAlignedBB;
import net.minecraft.server.v1_12_R1.Block; import net.minecraft.server.v1_12_R1.Block;
import net.minecraft.server.v1_12_R1.BlockChest; import net.minecraft.server.v1_12_R1.BlockChest;
import net.minecraft.server.v1_12_R1.BlockEnderChest; import net.minecraft.server.v1_12_R1.BlockEnderChest;
import net.minecraft.server.v1_12_R1.BlockPosition; import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.BlockShulkerBox; import net.minecraft.server.v1_12_R1.BlockShulkerBox;
import net.minecraft.server.v1_12_R1.Container;
import net.minecraft.server.v1_12_R1.Entity; import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityOcelot; import net.minecraft.server.v1_12_R1.EntityOcelot;
import net.minecraft.server.v1_12_R1.EntityPlayer; import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.EnumDirection; import net.minecraft.server.v1_12_R1.EnumDirection;
import net.minecraft.server.v1_12_R1.EnumGamemode;
import net.minecraft.server.v1_12_R1.IBlockData; import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.ITileInventory; import net.minecraft.server.v1_12_R1.ITileInventory;
import net.minecraft.server.v1_12_R1.InventoryEnderChest; import net.minecraft.server.v1_12_R1.InventoryEnderChest;
import net.minecraft.server.v1_12_R1.InventoryLargeChest; import net.minecraft.server.v1_12_R1.InventoryLargeChest;
import net.minecraft.server.v1_12_R1.PacketPlayOutOpenWindow; import net.minecraft.server.v1_12_R1.PlayerInteractManager;
import net.minecraft.server.v1_12_R1.TileEntity; import net.minecraft.server.v1_12_R1.TileEntity;
import net.minecraft.server.v1_12_R1.TileEntityChest; import net.minecraft.server.v1_12_R1.TileEntityChest;
import net.minecraft.server.v1_12_R1.TileEntityEnderChest; import net.minecraft.server.v1_12_R1.TileEntityEnderChest;
import net.minecraft.server.v1_12_R1.TileEntityShulkerBox; import net.minecraft.server.v1_12_R1.TileEntityShulkerBox;
import net.minecraft.server.v1_12_R1.World; import net.minecraft.server.v1_12_R1.World;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory; import org.bukkit.Statistic;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override private Field playerInteractManagerGamemode;
public boolean activateContainer(final Player bukkitPlayer, final boolean silentchest,
final org.bukkit.block.Block bukkitBlock) {
// Silent ender chest is API-only public AnySilentContainer() {
if (silentchest && bukkitBlock.getType() == Material.ENDER_CHEST) {
bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
final World world = player.world;
final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
final Object tile = world.getTileEntity(blockPosition);
if (tile == null) {
return false;
}
if (tile instanceof TileEntityEnderChest) {
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
InventoryEnderChest enderChest = player.getEnderChest();
enderChest.a((TileEntityEnderChest) tile);
player.openContainer(enderChest);
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
if (!(tile instanceof ITileInventory)) {
return false;
}
ITileInventory tileInventory = (ITileInventory) tile;
Block block = world.getType(blockPosition).getBlock();
Container container = null;
if (block instanceof BlockChest) {
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
Block localBlock = world.getType(localBlockPosition).getBlock();
if (localBlock != block) {
continue;
}
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
if (!(localTileEntity instanceof TileEntityChest)) {
continue;
}
if (localEnumDirection == EnumDirection.WEST
|| localEnumDirection == EnumDirection.NORTH) {
tileInventory = new InventoryLargeChest("container.chestDouble",
(TileEntityChest) localTileEntity, tileInventory);
} else {
tileInventory = new InventoryLargeChest("container.chestDouble", tileInventory,
(TileEntityChest) localTileEntity);
}
break;
}
BlockChest blockChest = (BlockChest) block;
if (blockChest.g == BlockChest.Type.BASIC) {
bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
} else if (blockChest.g == BlockChest.Type.TRAP) {
bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
}
if (silentchest) {
container = new SilentContainerChest(player.inventory, tileInventory, player);
}
}
if (block instanceof BlockShulkerBox) {
bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
if (silentchest && tileInventory instanceof TileEntityShulkerBox) {
// Set value to current + 1. Ensures consistency later when resetting.
SilentContainerShulkerBox.setOpenValue((TileEntityShulkerBox) tileInventory,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tileInventory)
+ 1);
container = new SilentContainerShulkerBox(player.inventory, tileInventory, player);
}
}
// AnyChest only - SilentChest not active or container unsupported
if (!silentchest || container == null) {
player.openContainer(tileInventory);
return true;
}
// SilentChest
try { try {
// Call InventoryOpenEvent this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
container = CraftEventFactory.callInventoryOpenEvent(player, container, false); this.playerInteractManagerGamemode.setAccessible(true);
if (container == null) { } catch (NoSuchFieldException | SecurityException e) {
return false; System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
}
// Open window
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(
new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(),
tileInventory.getScoreboardDisplayName(), tileInventory.getSize()));
player.activeContainer = container;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
// Special handling for shulker boxes - reset value for viewers to what it was initially.
if (tile instanceof TileEntityShulkerBox) {
new BukkitRunnable() {
@Override
public void run() {
// TODO hacky
Object tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return;
}
TileEntityShulkerBox box = (TileEntityShulkerBox) tile;
// Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more.
SilentContainerShulkerBox.setOpenValue(box,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile)
- 2);
}
}.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2);
}
return true;
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false;
} }
} }
private boolean hasOcelotOnTop(final World world, final BlockPosition blockPosition) {
for (Entity localEntity : world.a(EntityOcelot.class,
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
blockPosition.getZ() + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
@Override @Override
public boolean isAnyContainerNeeded(final Player p, final org.bukkit.block.Block b) { public boolean isAnySilentContainer(@NotNull final org.bukkit.block.Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); if (bukkitBlock.getType() == Material.ENDER_CHEST) {
World world = player.world; return true;
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ()); }
BlockState state = bukkitBlock.getState();
return state instanceof org.bukkit.block.Chest
|| state instanceof org.bukkit.block.ShulkerBox;
}
@Override
public boolean isAnyContainerNeeded(@NotNull final Player p, @NotNull final org.bukkit.block.Block bukkitBlock) {
World world = PlayerDataManager.getHandle(p).world;
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = world.getType(blockPosition); IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock(); Block block = blockData.getBlock();
@@ -242,23 +114,8 @@ public class AnySilentContainer implements IAnySilentContainer {
return false; return false;
} }
@Override
public boolean isAnySilentContainer(final org.bukkit.block.Block block) {
if (block.getType() == Material.ENDER_CHEST) {
return true;
}
BlockState state = block.getState();
return state instanceof org.bukkit.block.Chest
|| state instanceof org.bukkit.block.ShulkerBox;
}
private boolean isBlockedChest(final World world, final BlockPosition blockPosition) {
// For reference, loot at net.minecraft.server.BlockChest
return world.getType(blockPosition.up()).l() || this.hasOcelotOnTop(world, blockPosition);
}
private boolean isBlockedShulkerBox(final World world, final BlockPosition blockPosition, private boolean isBlockedShulkerBox(final World world, final BlockPosition blockPosition,
final IBlockData blockData) { final IBlockData blockData) {
// For reference, look at net.minecraft.server.BlockShulkerBox // For reference, look at net.minecraft.server.BlockShulkerBox
TileEntity tile = world.getTileEntity(blockPosition); TileEntity tile = world.getTileEntity(blockPosition);
@@ -279,4 +136,156 @@ public class AnySilentContainer implements IAnySilentContainer {
return false; return false;
} }
private boolean isBlockedChest(final World world, final BlockPosition blockPosition) {
// For reference, loot at net.minecraft.server.BlockChest
return world.getType(blockPosition.up()).l() || this.hasOcelotOnTop(world, blockPosition);
}
private boolean hasOcelotOnTop(final World world, final BlockPosition blockPosition) {
for (Entity localEntity : world.a(EntityOcelot.class,
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
blockPosition.getZ() + 1))) {
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
if (localEntityOcelot.isSitting()) {
return true;
}
}
return false;
}
@Override
public boolean activateContainer(@NotNull final Player bukkitPlayer, final boolean silentchest,
@NotNull final org.bukkit.block.Block bukkitBlock) {
// Silent ender chest is API-only
if (silentchest && bukkitBlock.getType() == Material.ENDER_CHEST) {
bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
final World world = player.world;
final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
final Object tile = world.getTileEntity(blockPosition);
if (tile == null) {
return false;
}
if (tile instanceof TileEntityEnderChest) {
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
InventoryEnderChest enderChest = player.getEnderChest();
enderChest.a((TileEntityEnderChest) tile);
player.openContainer(enderChest);
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
if (!(tile instanceof ITileInventory)) {
return false;
}
ITileInventory tileInventory = (ITileInventory) tile;
Block block = world.getType(blockPosition).getBlock();
if (block instanceof BlockChest) {
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
Block localBlock = world.getType(localBlockPosition).getBlock();
if (localBlock != block) {
continue;
}
TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
if (!(localTileEntity instanceof TileEntityChest)) {
continue;
}
if (localEnumDirection == EnumDirection.WEST
|| localEnumDirection == EnumDirection.NORTH) {
tileInventory = new InventoryLargeChest("container.chestDouble",
(TileEntityChest) localTileEntity, tileInventory);
} else {
tileInventory = new InventoryLargeChest("container.chestDouble", tileInventory,
(TileEntityChest) localTileEntity);
}
break;
}
BlockChest blockChest = (BlockChest) block;
if (blockChest.g == BlockChest.Type.BASIC) {
bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
} else if (blockChest.g == BlockChest.Type.TRAP) {
bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
}
}
if (block instanceof BlockShulkerBox) {
bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
}
// AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory);
return true;
}
// SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
case SHULKER_BOX:
break;
default:
return;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try {
if (!this.playerInteractManagerGamemode.isAccessible()) {
// Just in case, ensure accessible.
this.playerInteractManagerGamemode.setAccessible(true);
}
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
} }

View File

@@ -1,11 +1,17 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. This program is free software: you can * Copyright (C) 2011-2018 lishid. All rights reserved.
* 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 * This program is free software: you can redistribute it and/or modify
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * it under the terms of the GNU General Public License as published by
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should * the Free Software Foundation, version 3.
* have received a copy of the GNU General Public License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. * 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 <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_12_R1; package com.lishid.openinv.internal.v1_12_R1;
@@ -14,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_12_R1.IInventory; import net.minecraft.server.v1_12_R1.IInventory;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(final Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull final Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -39,7 +43,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(final Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull final Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -54,7 +58,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(final Inventory inventory) { public boolean isSpecialEnderChest(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -63,7 +67,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialPlayerInventory(final Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }

View File

@@ -1,33 +1,37 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. This program is free software: you can * Copyright (C) 2011-2018 lishid. All rights reserved.
* 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 * This program is free software: you can redistribute it and/or modify
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * it under the terms of the GNU General Public License as published by
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should * the Free Software Foundation, version 3.
* have received a copy of the GNU General Public License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. * 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 <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_12_R1; package com.lishid.openinv.internal.v1_12_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import com.mojang.authlib.GameProfile;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.mojang.authlib.GameProfile;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_12_R1.EntityPlayer; import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.MinecraftServer; import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.PlayerInteractManager; import net.minecraft.server.v1_12_R1.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer; import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@@ -53,12 +57,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Bukkit.getOnlinePlayers(); return Bukkit.getOnlinePlayers();
} }
@Override @Override
public OfflinePlayer getPlayerByID(final String identifier) { public OfflinePlayer getPlayerByID(@NotNull final String identifier) {
try { try {
UUID uuid = UUID.fromString(identifier); UUID uuid = UUID.fromString(identifier);
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
@@ -73,15 +77,15 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
} }
@Override @NotNull @Override
public String getPlayerDataID(final OfflinePlayer player) { public String getPlayerDataID(@NotNull final OfflinePlayer offline) {
return player.getUniqueId().toString(); return offline.getUniqueId().toString();
} }
@Override @Override
public Player loadPlayer(final OfflinePlayer offline) { public Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data // Ensure player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -92,7 +96,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = entity == null ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -101,4 +105,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return target; return target;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,40 +0,0 @@
/*
* 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
* <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_12_R1;
import net.minecraft.server.v1_12_R1.ContainerChest;
import net.minecraft.server.v1_12_R1.EntityHuman;
import net.minecraft.server.v1_12_R1.IInventory;
import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest {
public SilentContainerChest(final PlayerInventory playerInventory, final IInventory iInventory,
final EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
// Send close signal
iInventory.closeContainer(entityHuman);
}
@Override
public void b(final EntityHuman entityHuman) {
// Don't send close signal twice, might screw up
PlayerInventory playerinventory = entityHuman.inventory;
if (playerinventory.getCarried() != ItemStack.a) {
ItemStack carried = playerinventory.getCarried();
playerinventory.setCarried(ItemStack.a);
entityHuman.drop(carried, false);
}
}
}

View File

@@ -1,57 +0,0 @@
package com.lishid.openinv.internal.v1_12_R1;
import java.lang.reflect.Field;
import net.minecraft.server.v1_12_R1.ContainerShulkerBox;
import net.minecraft.server.v1_12_R1.EntityHuman;
import net.minecraft.server.v1_12_R1.IInventory;
import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.PlayerInventory;
import net.minecraft.server.v1_12_R1.TileEntityShulkerBox;
public class SilentContainerShulkerBox extends ContainerShulkerBox {
private static Field fieldShulkerActionData;
private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
if (SilentContainerShulkerBox.fieldShulkerActionData == null) {
SilentContainerShulkerBox.fieldShulkerActionData = TileEntityShulkerBox.class
.getDeclaredField("h");
SilentContainerShulkerBox.fieldShulkerActionData.setAccessible(true);
}
return SilentContainerShulkerBox.fieldShulkerActionData;
}
public static Integer getOpenValue(final TileEntityShulkerBox tileShulkerBox) {
try {
return (Integer) SilentContainerShulkerBox.exposeOpenStatus().get(tileShulkerBox);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
public static void setOpenValue(final TileEntityShulkerBox tileShulkerBox, final Object value) {
try {
SilentContainerShulkerBox.exposeOpenStatus().set(tileShulkerBox, value);
} catch (Exception e) {
e.printStackTrace();
}
}
public SilentContainerShulkerBox(final PlayerInventory playerInventory,
final IInventory iInventory, final EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
}
@Override
public void b(final EntityHuman entityHuman) {
PlayerInventory playerinventory = entityHuman.inventory;
if (!playerinventory.getCarried().isEmpty()) {
entityHuman.drop(playerinventory.getCarried(), false);
playerinventory.setCarried(ItemStack.a);
}
}
}

View File

@@ -1,43 +1,47 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. This program is free software: you can * Copyright (C) 2011-2018 lishid. All rights reserved.
* 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 * This program is free software: you can redistribute it and/or modify
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * it under the terms of the GNU General Public License as published by
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should * the Free Software Foundation, version 3.
* have received a copy of the GNU General Public License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. * 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 <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_12_R1; package com.lishid.openinv.internal.v1_12_R1;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_12_R1.EntityPlayer; import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.IInventory; import net.minecraft.server.v1_12_R1.IInventory;
import net.minecraft.server.v1_12_R1.InventoryEnderChest; import net.minecraft.server.v1_12_R1.InventoryEnderChest;
import net.minecraft.server.v1_12_R1.InventorySubcontainer; import net.minecraft.server.v1_12_R1.InventorySubcontainer;
import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.ItemStack;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer public class SpecialEnderChest extends InventorySubcontainer
implements IInventory, ISpecialEnderChest { implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialEnderChest(final Player player, final Boolean online) { public SpecialEnderChest(final Player player, final Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(), PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.bukkitOwner = nmsPlayer.getBukkitEntity(); this.bukkitOwner = nmsPlayer.getBukkitEntity();
@@ -45,8 +49,8 @@ public class SpecialEnderChest extends InventorySubcontainer
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return this.inventory; return inventory;
} }
@Override @Override
@@ -64,13 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer
Field field = InventorySubcontainer.class.getField("items"); Field field = InventorySubcontainer.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(subcontainer, list); field.set(subcontainer, list);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException | SecurityException | IllegalArgumentException
e.printStackTrace(); | IllegalAccessException e) {
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -81,13 +80,13 @@ public class SpecialEnderChest extends InventorySubcontainer
} }
@Override @Override
public void setPlayerOnline(final Player player) { public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) { if (!this.playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity(); this.bukkitOwner = nmsPlayer.getBukkitEntity();
this.setItemLists(nmsPlayer.getEnderChest(), this.items); this.setItemLists(nmsPlayer.getEnderChest(), this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
this.playerOnline = true; this.playerOnline = true;
} }
} }

View File

@@ -1,36 +1,39 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. This program is free software: you can * Copyright (C) 2011-2018 lishid. All rights reserved.
* 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 * This program is free software: you can redistribute it and/or modify
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * it under the terms of the GNU General Public License as published by
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should * the Free Software Foundation, version 3.
* have received a copy of the GNU General Public License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. * 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 <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_12_R1; package com.lishid.openinv.internal.v1_12_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.Arrays;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_12_R1.ContainerUtil; import net.minecraft.server.v1_12_R1.ContainerUtil;
import net.minecraft.server.v1_12_R1.EntityHuman; import net.minecraft.server.v1_12_R1.EntityHuman;
import net.minecraft.server.v1_12_R1.ItemStack; import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.NonNullList; import net.minecraft.server.v1_12_R1.NonNullList;
import net.minecraft.server.v1_12_R1.PlayerInventory; import net.minecraft.server.v1_12_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) { public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -45,8 +48,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return this.inventory; return inventory;
} }
@Override @Override
@@ -82,6 +85,11 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return this.player.getName(); return this.player.getName();
} }
@Override
public boolean hasCustomName() {
return true;
}
private int getReversedArmorSlotNum(final int i) { private int getReversedArmorSlotNum(final int i) {
if (i == 0) { if (i == 0) {
return 3; return 3;
@@ -138,9 +146,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return; return;
} }
if (list != null) { list.set(i, itemstack);
list.set(i, itemstack);
}
} }
private void setItemArrays(final PlayerInventory inventory, final NonNullList<ItemStack> items, private void setItemArrays(final PlayerInventory inventory, final NonNullList<ItemStack> items,
@@ -150,32 +156,28 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
Field modifiers = Field.class.getDeclaredField("modifiers"); Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true); modifiers.setAccessible(true);
// Access and replace main inventory array // Access and replace main inventory list
Field field = PlayerInventory.class.getField("items"); Field field = PlayerInventory.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, items); field.set(inventory, items);
// Access and replace armor inventory array // Access and replace armor inventory list
field = PlayerInventory.class.getField("armor"); field = PlayerInventory.class.getField("armor");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, armor); field.set(inventory, armor);
// Access and replace offhand inventory array // Access and replace offhand inventory list
field = PlayerInventory.class.getField("extraSlots"); field = PlayerInventory.class.getField("extraSlots");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, extraSlots); field.set(inventory, extraSlots);
// Access and replace array containing all inventory arrays // Access and replace list containing all inventory lists
field = PlayerInventory.class.getDeclaredField("g"); field = PlayerInventory.class.getDeclaredField("f");
field.setAccessible(true); field.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots })); field.set(inventory, Arrays.asList(items, armor, extraSlots));
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
// Unable to set final fields to item arrays, we're screwed. Noisily fail. // Unable to set final fields to item lists, we're screwed. Noisily fail.
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@@ -186,10 +188,9 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public void setPlayerOnline(final Player player) { public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) { if (!this.playerOnline) {
this.player = PlayerDataManager.getHandle(player); this.player = PlayerDataManager.getHandle(player);
;
this.setItemArrays(this.player.inventory, this.items, this.armor, this.extraSlots); this.setItemArrays(this.player.inventory, this.items, this.armor, this.extraSlots);
this.playerOnline = true; this.playerOnline = true;
} }
@@ -217,7 +218,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return ItemStack.a; return ItemStack.a;
} }
return list == null || list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j); return list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
} }
@Override @Override
@@ -242,7 +243,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
return ItemStack.a; return ItemStack.a;
} }
if (list != null && !list.get(i).isEmpty()) { if (!list.get(i).isEmpty()) {
ItemStack itemstack = list.get(i); ItemStack itemstack = list.get(i);
list.set(i, ItemStack.a); list.set(i, ItemStack.a);

57
internal/v1_13_R1/pom.xml Normal file
View File

@@ -0,0 +1,57 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>4.0.0</version>
</parent>
<artifactId>openinvadapter1_13_R1</artifactId>
<name>OpenInvAdapter1_13_R1</name>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,297 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R1;
import com.lishid.openinv.internal.IAnySilentContainer;
import java.lang.reflect.Field;
import net.minecraft.server.v1_13_R1.AxisAlignedBB;
import net.minecraft.server.v1_13_R1.Block;
import net.minecraft.server.v1_13_R1.BlockChest;
import net.minecraft.server.v1_13_R1.BlockChestTrapped;
import net.minecraft.server.v1_13_R1.BlockEnderChest;
import net.minecraft.server.v1_13_R1.BlockPosition;
import net.minecraft.server.v1_13_R1.BlockPropertyChestType;
import net.minecraft.server.v1_13_R1.BlockShulkerBox;
import net.minecraft.server.v1_13_R1.ChatMessage;
import net.minecraft.server.v1_13_R1.Entity;
import net.minecraft.server.v1_13_R1.EntityOcelot;
import net.minecraft.server.v1_13_R1.EntityPlayer;
import net.minecraft.server.v1_13_R1.EnumDirection;
import net.minecraft.server.v1_13_R1.EnumGamemode;
import net.minecraft.server.v1_13_R1.IBlockData;
import net.minecraft.server.v1_13_R1.ITileInventory;
import net.minecraft.server.v1_13_R1.InventoryEnderChest;
import net.minecraft.server.v1_13_R1.InventoryLargeChest;
import net.minecraft.server.v1_13_R1.PlayerInteractManager;
import net.minecraft.server.v1_13_R1.TileEntity;
import net.minecraft.server.v1_13_R1.TileEntityChest;
import net.minecraft.server.v1_13_R1.TileEntityEnderChest;
import net.minecraft.server.v1_13_R1.TileEntityShulkerBox;
import net.minecraft.server.v1_13_R1.VoxelShapes;
import net.minecraft.server.v1_13_R1.World;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer {
private Field playerInteractManagerGamemode;
public AnySilentContainer() {
try {
this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
this.playerInteractManagerGamemode.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
e.printStackTrace();
}
}
@Override
public boolean isAnySilentContainer(@NotNull final org.bukkit.block.Block bukkitBlock) {
if (bukkitBlock.getType() == Material.ENDER_CHEST) {
return true;
}
BlockState state = bukkitBlock.getState();
return state instanceof org.bukkit.block.Chest
|| state instanceof org.bukkit.block.ShulkerBox;
}
@Override
public boolean isAnyContainerNeeded(@NotNull final Player bukkitPlayer, @NotNull final org.bukkit.block.Block bukkitBlock) {
World world = PlayerDataManager.getHandle(bukkitPlayer).world;
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock();
if (block instanceof BlockShulkerBox) {
return this.isBlockedShulkerBox(world, blockPosition, blockData);
}
if (block instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots.
return world.getType(blockPosition.up()).isOccluding();
}
// Check if chest is blocked or has an ocelot on top
if (this.isBlockedChest(world, blockPosition)) {
return true;
}
// Check for matching adjacent chests that are blocked or have an ocelot on top
BlockPropertyChestType chestType = blockData.get(BlockChest.b);
if (chestType == BlockPropertyChestType.SINGLE) {
return false;
}
BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.k(blockData));
IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
if (adjacentBlockData.getBlock() == block) {
BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
&& adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
return this.isBlockedChest(world, adjacentBlockPosition);
}
}
return false;
}
private boolean isBlockedShulkerBox(final World world, final BlockPosition blockPosition,
final IBlockData blockData) {
// For reference, look at net.minecraft.server.BlockShulkerBox
TileEntity tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return false;
}
EnumDirection enumDirection = blockData.get(BlockShulkerBox.a);
if (((TileEntityShulkerBox) tile).r() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
AxisAlignedBB axisAlignedBB = VoxelShapes.b().a()
.b(0.5F * enumDirection.getAdjacentX(), 0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(), enumDirection.getAdjacentZ());
return !world.getCubes(null, axisAlignedBB.a(blockPosition.shift(enumDirection)));
}
return false;
}
private boolean isBlockedChest(final World world, final BlockPosition blockPosition) {
// For reference, loot at net.minecraft.server.BlockChest
return world.getType(blockPosition.up()).isOccluding() || this.hasOcelotOnTop(world, blockPosition);
}
private boolean hasOcelotOnTop(final World world, final BlockPosition blockPosition) {
for (Entity entity : world.a(EntityOcelot.class,
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
blockPosition.getZ() + 1))) {
EntityOcelot entityOcelot = (EntityOcelot) entity;
if (entityOcelot.isSitting()) {
return true;
}
}
return false;
}
@Override
public boolean activateContainer(@NotNull final Player bukkitPlayer, final boolean silentsilent,
@NotNull final org.bukkit.block.Block bukkitBlock) {
// Silent ender chest is API-only
if (silentsilent && bukkitBlock.getType() == Material.ENDER_CHEST) {
bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
EntityPlayer player = com.lishid.openinv.internal.v1_13_R1.PlayerDataManager.getHandle(bukkitPlayer);
final World world = player.world;
final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
final Object tile = world.getTileEntity(blockPosition);
if (tile == null) {
return false;
}
if (tile instanceof TileEntityEnderChest) {
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
InventoryEnderChest enderChest = player.getEnderChest();
enderChest.a((TileEntityEnderChest) tile);
player.openContainer(enderChest);
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
if (!(tile instanceof ITileInventory)) {
return false;
}
ITileInventory tileInventory = (ITileInventory) tile;
IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock();
if (block instanceof BlockChest) {
BlockPropertyChestType chestType = blockData.get(BlockChest.b);
if (chestType != BlockPropertyChestType.SINGLE) {
BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.k(blockData));
IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
if (adjacentBlockData.getBlock() == block) {
BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
&& adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
TileEntity adjacentTile = world.getTileEntity(adjacentBlockPosition);
if (adjacentTile instanceof TileEntityChest) {
ITileInventory rightChest = chestType == BlockPropertyChestType.RIGHT ? tileInventory : (ITileInventory) adjacentTile;
ITileInventory leftChest = chestType == BlockPropertyChestType.RIGHT ? (ITileInventory) adjacentTile : tileInventory;
tileInventory = new InventoryLargeChest(new ChatMessage("container.chestDouble"), rightChest, leftChest);
}
}
}
}
if (block instanceof BlockChestTrapped) {
bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
} else {
bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
}
}
if (block instanceof BlockShulkerBox) {
bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
}
// AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silentsilent || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory);
return true;
}
// SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
case SHULKER_BOX:
break;
default:
return;
}
EntityPlayer player = com.lishid.openinv.internal.v1_13_R1.PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try {
if (!this.playerInteractManagerGamemode.isAccessible()) {
// Just in case, ensure accessible.
this.playerInteractManagerGamemode.setAccessible(true);
}
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R1;
import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor;
import net.minecraft.server.v1_13_R1.IInventory;
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess {
@Override
public ISpecialEnderChest getSpecialEnderChest(@NotNull final Inventory inventory) {
IInventory inv;
if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory();
} else {
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
}
if (inv instanceof com.lishid.openinv.internal.v1_13_R1.SpecialEnderChest) {
return (com.lishid.openinv.internal.v1_13_R1.SpecialEnderChest) inv;
}
return null;
}
@Override
public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull final Inventory inventory) {
IInventory inv;
if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory();
} else {
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
}
if (inv instanceof com.lishid.openinv.internal.v1_13_R1.SpecialPlayerInventory) {
return (com.lishid.openinv.internal.v1_13_R1.SpecialPlayerInventory) inv;
}
return null;
}
@Override
public boolean isSpecialEnderChest(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
}
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
inventory) instanceof ISpecialEnderChest;
}
@Override
public boolean isSpecialPlayerInventory(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
}
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
inventory) instanceof ISpecialPlayerInventory;
}
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import com.mojang.authlib.GameProfile;
import java.util.Collection;
import java.util.UUID;
import net.minecraft.server.v1_13_R1.EntityPlayer;
import net.minecraft.server.v1_13_R1.MinecraftServer;
import net.minecraft.server.v1_13_R1.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_13_R1.CraftServer;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager {
public static EntityPlayer getHandle(final Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
@Override
public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Bukkit.getOnlinePlayers();
}
@Override
public OfflinePlayer getPlayerByID(@NotNull final String identifier) {
try {
UUID uuid = UUID.fromString(identifier);
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
// Ensure player is a real player, otherwise return null
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
return null;
}
return player;
} catch (IllegalArgumentException e) {
// Not a UUID
return null;
}
}
@Override
public @NotNull String getPlayerDataID(@NotNull final OfflinePlayer offline) {
return offline.getUniqueId().toString();
}
@Override
public Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data
if (!offline.hasPlayedBefore()) {
return null;
}
// Create a profile and entity to load the player data
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity
Player target = entity.getBukkitEntity();
if (target != null) {
// Load data
target.loadData();
}
// Return the entity
return target;
}
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R1;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import net.minecraft.server.v1_13_R1.EntityPlayer;
import net.minecraft.server.v1_13_R1.IInventory;
import net.minecraft.server.v1_13_R1.InventoryEnderChest;
import net.minecraft.server.v1_13_R1.InventorySubcontainer;
import net.minecraft.server.v1_13_R1.ItemStack;
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer
implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline;
public SpecialEnderChest(final Player player, final Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getDisplayName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize(), player);
this.playerOnline = online;
this.enderChest = PlayerDataManager.getHandle(player).getEnderChest();
this.setItemLists(this, this.enderChest.getContents());
}
@Override
public @NotNull Inventory getBukkitInventory() {
return inventory;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
private void setItemLists(final InventorySubcontainer subcontainer, final List<ItemStack> list) {
try {
// Prepare to remove final modifier
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
// Access and replace main inventory array
Field field = InventorySubcontainer.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(subcontainer, list);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException
| IllegalAccessException e) {
e.printStackTrace();
}
}
@Override
public void setPlayerOffline() {
this.playerOnline = false;
}
@Override
public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) {
try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.bukkitOwner = nmsPlayer.getBukkitEntity();
this.setItemLists(nmsPlayer.getEnderChest(), this.items);
} catch (Exception ignored) {}
this.playerOnline = true;
}
}
@Override
public void update() {
super.update();
this.enderChest.update();
}
}

View File

@@ -0,0 +1,255 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import net.minecraft.server.v1_13_R1.ChatMessage;
import net.minecraft.server.v1_13_R1.ContainerUtil;
import net.minecraft.server.v1_13_R1.EntityHuman;
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
import net.minecraft.server.v1_13_R1.ItemStack;
import net.minecraft.server.v1_13_R1.NonNullList;
import net.minecraft.server.v1_13_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline;
public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.setItemArrays(this, this.player.inventory.items, this.player.inventory.armor,
this.player.inventory.extraSlots);
}
@Override
public boolean a(final EntityHuman entityhuman) {
return true;
}
@Override
public @NotNull Inventory getBukkitInventory() {
return inventory;
}
@Override
public ItemStack getItem(int i) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list.get(i);
}
@Override
public IChatBaseComponent getDisplayName() {
return new ChatMessage(this.player.getName());
}
@Override
public boolean hasCustomName() {
return true;
}
private int getReversedArmorSlotNum(final int i) {
if (i == 0) {
return 3;
}
if (i == 1) {
return 2;
}
if (i == 2) {
return 1;
}
if (i == 3) {
return 0;
}
return i;
}
private int getReversedItemSlotNum(final int i) {
if (i >= 27) {
return i - 27;
}
return i + 9;
}
@Override
public int getSize() {
return super.getSize() + 4;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public void setItem(int i, final ItemStack itemstack) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
this.player.drop(itemstack, true);
return;
}
list.set(i, itemstack);
}
private void setItemArrays(final PlayerInventory inventory, final NonNullList<ItemStack> items,
final NonNullList<ItemStack> armor, final NonNullList<ItemStack> extraSlots) {
try {
// Prepare to remove final modifier
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
// Access and replace main inventory list
Field field = PlayerInventory.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, items);
// Access and replace armor inventory list
field = PlayerInventory.class.getField("armor");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, armor);
// Access and replace offhand inventory list
field = PlayerInventory.class.getField("extraSlots");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, extraSlots);
// Access and replace list containing all inventory lists
field = PlayerInventory.class.getDeclaredField("f");
field.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, Arrays.asList(items, armor, extraSlots));
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
// Unable to set final fields to item lists, we're screwed. Noisily fail.
e.printStackTrace();
}
}
@Override
public void setPlayerOffline() {
this.playerOnline = false;
}
@Override
public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) {
this.player = PlayerDataManager.getHandle(player);
this.setItemArrays(this.player.inventory, this.items, this.armor, this.extraSlots);
this.playerOnline = true;
}
}
@Override
public ItemStack splitStack(int i, final int j) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
}
@Override
public ItemStack splitWithoutUpdate(int i) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
if (!list.get(i).isEmpty()) {
ItemStack itemstack = list.get(i);
list.set(i, ItemStack.a);
return itemstack;
}
return ItemStack.a;
}
}

57
internal/v1_13_R2/pom.xml Normal file
View File

@@ -0,0 +1,57 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>4.0.0</version>
</parent>
<artifactId>openinvadapter1_13_R2</artifactId>
<name>OpenInvAdapter1_13_R2</name>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,309 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R2;
import com.lishid.openinv.internal.IAnySilentContainer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.minecraft.server.v1_13_R2.AxisAlignedBB;
import net.minecraft.server.v1_13_R2.Block;
import net.minecraft.server.v1_13_R2.BlockChest;
import net.minecraft.server.v1_13_R2.BlockChestTrapped;
import net.minecraft.server.v1_13_R2.BlockEnderChest;
import net.minecraft.server.v1_13_R2.BlockPosition;
import net.minecraft.server.v1_13_R2.BlockPropertyChestType;
import net.minecraft.server.v1_13_R2.BlockShulkerBox;
import net.minecraft.server.v1_13_R2.ChatMessage;
import net.minecraft.server.v1_13_R2.Entity;
import net.minecraft.server.v1_13_R2.EntityOcelot;
import net.minecraft.server.v1_13_R2.EntityPlayer;
import net.minecraft.server.v1_13_R2.EnumDirection;
import net.minecraft.server.v1_13_R2.EnumGamemode;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.ITileInventory;
import net.minecraft.server.v1_13_R2.InventoryEnderChest;
import net.minecraft.server.v1_13_R2.InventoryLargeChest;
import net.minecraft.server.v1_13_R2.PlayerInteractManager;
import net.minecraft.server.v1_13_R2.TileEntity;
import net.minecraft.server.v1_13_R2.TileEntityChest;
import net.minecraft.server.v1_13_R2.TileEntityEnderChest;
import net.minecraft.server.v1_13_R2.TileEntityShulkerBox;
import net.minecraft.server.v1_13_R2.VoxelShape;
import net.minecraft.server.v1_13_R2.VoxelShapes;
import net.minecraft.server.v1_13_R2.World;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer {
private Field playerInteractManagerGamemode;
public AnySilentContainer() {
try {
this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
this.playerInteractManagerGamemode.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
e.printStackTrace();
}
}
@Override
public boolean isAnySilentContainer(@NotNull final org.bukkit.block.Block bukkitBlock) {
if (bukkitBlock.getType() == Material.ENDER_CHEST) {
return true;
}
BlockState state = bukkitBlock.getState();
return state instanceof org.bukkit.block.Chest
|| state instanceof org.bukkit.block.ShulkerBox;
}
@Override
public boolean isAnyContainerNeeded(@NotNull final Player bukkitPlayer, @NotNull final org.bukkit.block.Block bukkitBlock) {
World world = PlayerDataManager.getHandle(bukkitPlayer).world;
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock();
if (block instanceof BlockShulkerBox) {
return this.isBlockedShulkerBox(world, blockPosition, blockData);
}
if (block instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots.
return world.getType(blockPosition.up()).isOccluding();
}
// Check if chest is blocked or has an ocelot on top
if (this.isBlockedChest(world, blockPosition)) {
return true;
}
// Check for matching adjacent chests that are blocked or have an ocelot on top
BlockPropertyChestType chestType = blockData.get(BlockChest.b);
if (chestType == BlockPropertyChestType.SINGLE) {
return false;
}
BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.k(blockData));
IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
if (adjacentBlockData.getBlock() == block) {
BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
&& adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
return this.isBlockedChest(world, adjacentBlockPosition);
}
}
return false;
}
private boolean isBlockedShulkerBox(final World world, final BlockPosition blockPosition,
final IBlockData blockData) {
// For reference, look at net.minecraft.server.BlockShulkerBox
TileEntity tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return false;
}
EnumDirection enumDirection = blockData.get(BlockShulkerBox.a);
if (((TileEntityShulkerBox) tile).r() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
AxisAlignedBB axisAlignedBB;
try {
Method method = VoxelShape.class.getMethod("a");
axisAlignedBB = (AxisAlignedBB) method.invoke(VoxelShapes.b());
} catch (NoSuchMethodException e) {
axisAlignedBB = VoxelShapes.b().getBoundingBox();
} catch (InvocationTargetException | IllegalAccessException e) {
return false;
}
axisAlignedBB = axisAlignedBB
.b(0.5F * enumDirection.getAdjacentX(), 0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(), enumDirection.getAdjacentZ());
return !world.getCubes(null, axisAlignedBB.a(blockPosition.shift(enumDirection)));
}
return false;
}
private boolean isBlockedChest(final World world, final BlockPosition blockPosition) {
// For reference, loot at net.minecraft.server.BlockChest
return world.getType(blockPosition.up()).isOccluding() || this.hasOcelotOnTop(world, blockPosition);
}
private boolean hasOcelotOnTop(final World world, final BlockPosition blockPosition) {
for (Entity entity : world.a(EntityOcelot.class,
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
blockPosition.getZ() + 1))) {
EntityOcelot entityOcelot = (EntityOcelot) entity;
if (entityOcelot.isSitting()) {
return true;
}
}
return false;
}
@Override
public boolean activateContainer(@NotNull final Player bukkitPlayer, final boolean silent,
@NotNull final org.bukkit.block.Block bukkitBlock) {
// Silent ender chest is API-only
if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
final World world = player.world;
final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
final Object tile = world.getTileEntity(blockPosition);
if (tile == null) {
return false;
}
if (tile instanceof TileEntityEnderChest) {
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
InventoryEnderChest enderChest = player.getEnderChest();
enderChest.a((TileEntityEnderChest) tile);
player.openContainer(enderChest);
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
if (!(tile instanceof ITileInventory)) {
return false;
}
ITileInventory tileInventory = (ITileInventory) tile;
IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock();
if (block instanceof BlockChest) {
BlockPropertyChestType chestType = blockData.get(BlockChest.b);
if (chestType != BlockPropertyChestType.SINGLE) {
BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.k(blockData));
IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
if (adjacentBlockData.getBlock() == block) {
BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
&& adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
TileEntity adjacentTile = world.getTileEntity(adjacentBlockPosition);
if (adjacentTile instanceof TileEntityChest) {
ITileInventory rightChest = chestType == BlockPropertyChestType.RIGHT ? tileInventory : (ITileInventory) adjacentTile;
ITileInventory leftChest = chestType == BlockPropertyChestType.RIGHT ? (ITileInventory) adjacentTile : tileInventory;
tileInventory = new InventoryLargeChest(new ChatMessage("container.chestDouble"), rightChest, leftChest);
}
}
}
}
if (block instanceof BlockChestTrapped) {
bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
} else {
bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
}
}
if (block instanceof BlockShulkerBox) {
bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
}
// AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silent || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory);
return true;
}
// SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
case SHULKER_BOX:
break;
default:
return;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try {
if (!this.playerInteractManagerGamemode.isAccessible()) {
// Just in case, ensure accessible.
this.playerInteractManagerGamemode.setAccessible(true);
}
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R2;
import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor;
import net.minecraft.server.v1_13_R2.IInventory;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess {
@Override
public ISpecialEnderChest getSpecialEnderChest(@NotNull final Inventory inventory) {
IInventory inv;
if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory();
} else {
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
}
if (inv instanceof SpecialEnderChest) {
return (SpecialEnderChest) inv;
}
return null;
}
@Override
public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull final Inventory inventory) {
IInventory inv;
if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory();
} else {
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
}
if (inv instanceof SpecialPlayerInventory) {
return (SpecialPlayerInventory) inv;
}
return null;
}
@Override
public boolean isSpecialEnderChest(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
}
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
inventory) instanceof ISpecialEnderChest;
}
@Override
public boolean isSpecialPlayerInventory(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
}
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
inventory) instanceof ISpecialPlayerInventory;
}
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R2;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import com.mojang.authlib.GameProfile;
import java.util.Collection;
import java.util.UUID;
import net.minecraft.server.v1_13_R2.DimensionManager;
import net.minecraft.server.v1_13_R2.EntityPlayer;
import net.minecraft.server.v1_13_R2.MinecraftServer;
import net.minecraft.server.v1_13_R2.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager {
public static EntityPlayer getHandle(final Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
@Override
public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Bukkit.getOnlinePlayers();
}
@Override
public OfflinePlayer getPlayerByID(@NotNull final String identifier) {
try {
UUID uuid = UUID.fromString(identifier);
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
// Ensure player is a real player, otherwise return null
if (!player.hasPlayedBefore() && !player.isOnline()) {
return null;
}
return player;
} catch (IllegalArgumentException e) {
// Not a UUID
return null;
}
}
@Override
public @NotNull String getPlayerDataID(@NotNull final OfflinePlayer offline) {
return offline.getUniqueId().toString();
}
@Override
public Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data
if (!offline.hasPlayedBefore()) {
return null;
}
// Create a profile and entity to load the player data
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
// Get the bukkit entity
Player target = entity.getBukkitEntity();
if (target != null) {
// Load data
target.loadData();
}
// Return the entity
return target;
}
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
}

View File

@@ -0,0 +1,266 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R2;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.server.v1_13_R2.AutoRecipeOutput;
import net.minecraft.server.v1_13_R2.AutoRecipeStackManager;
import net.minecraft.server.v1_13_R2.ContainerUtil;
import net.minecraft.server.v1_13_R2.EntityHuman;
import net.minecraft.server.v1_13_R2.EntityPlayer;
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.IInventory;
import net.minecraft.server.v1_13_R2.IInventoryListener;
import net.minecraft.server.v1_13_R2.InventoryEnderChest;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.NonNullList;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest implements IInventory, ISpecialEnderChest, AutoRecipeOutput {
private EntityPlayer owner;
private final IChatBaseComponent displayName;
private final CraftInventory inventory;
private NonNullList<ItemStack> items;
private boolean playerOnline;
public SpecialEnderChest(final Player player, final Boolean online) {
this.owner = PlayerDataManager.getHandle(player);
this.displayName = this.owner.getEnderChest().getDisplayName();
this.inventory = new CraftInventory(this);
this.items = this.owner.getEnderChest().items;
this.playerOnline = online;
}
@Override
public @NotNull Inventory getBukkitInventory() {
return this.inventory;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public void setPlayerOffline() {
this.playerOnline = false;
}
@Override
public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) {
try {
this.owner = PlayerDataManager.getHandle(player);
InventoryEnderChest enderChest = owner.getEnderChest();
for (int i = 0; i < enderChest.getSize(); ++i) {
enderChest.setItem(i, this.items.get(i));
}
this.items = enderChest.items;
} catch (Exception ignored) {}
this.playerOnline = true;
}
}
@Override
public void update() {
this.owner.getEnderChest().update();
}
public List<ItemStack> getContents() {
return this.items;
}
public void onOpen(CraftHumanEntity who) {
this.owner.getEnderChest().onOpen(who);
}
public void onClose(CraftHumanEntity who) {
this.owner.getEnderChest().onClose(who);
}
public List<HumanEntity> getViewers() {
return this.owner.getEnderChest().getViewers();
}
public void setMaxStackSize(int i) {
this.owner.getEnderChest().setMaxStackSize(i);
}
public InventoryHolder getOwner() {
return this.owner.getEnderChest().getOwner();
}
public Location getLocation() {
return null;
}
public void a(IInventoryListener iinventorylistener) {
this.owner.getEnderChest().a(iinventorylistener);
}
public void b(IInventoryListener iinventorylistener) {
this.owner.getEnderChest().b(iinventorylistener);
}
public ItemStack getItem(int i) {
return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
}
public ItemStack splitStack(int i, int j) {
ItemStack itemstack = ContainerUtil.a(this.items, i, j);
if (!itemstack.isEmpty()) {
this.update();
}
return itemstack;
}
public ItemStack a(ItemStack itemstack) {
ItemStack itemstack1 = itemstack.cloneItemStack();
for (int i = 0; i < this.getSize(); ++i) {
ItemStack itemstack2 = this.getItem(i);
if (itemstack2.isEmpty()) {
this.setItem(i, itemstack1);
this.update();
return ItemStack.a;
}
if (ItemStack.c(itemstack2, itemstack1)) {
int j = Math.min(this.getMaxStackSize(), itemstack2.getMaxStackSize());
int k = Math.min(itemstack1.getCount(), j - itemstack2.getCount());
if (k > 0) {
itemstack2.add(k);
itemstack1.subtract(k);
if (itemstack1.isEmpty()) {
this.update();
return ItemStack.a;
}
}
}
}
if (itemstack1.getCount() != itemstack.getCount()) {
this.update();
}
return itemstack1;
}
public ItemStack splitWithoutUpdate(int i) {
ItemStack itemstack = this.items.get(i);
if (itemstack.isEmpty()) {
return ItemStack.a;
} else {
this.items.set(i, ItemStack.a);
return itemstack;
}
}
public void setItem(int i, ItemStack itemstack) {
this.items.set(i, itemstack);
if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) {
itemstack.setCount(this.getMaxStackSize());
}
this.update();
}
public int getSize() {
return this.owner.getEnderChest().getSize();
}
public boolean P_() {
for (ItemStack itemstack : this.items) {
if (!itemstack.isEmpty()) {
return false;
}
}
return true;
}
public IChatBaseComponent getDisplayName() {
return this.displayName;
}
@Nullable
public IChatBaseComponent getCustomName() {
return this.displayName;
}
public boolean hasCustomName() {
return false;
}
public void a(@Nullable IChatBaseComponent ichatbasecomponent) {
// Ignored - name is always player's name.
}
public int getMaxStackSize() {
return 64;
}
public boolean a(EntityHuman entityhuman) {
return true;
}
public void startOpen(EntityHuman entityhuman) {
}
public void closeContainer(EntityHuman entityhuman) {
}
public boolean b(int i, ItemStack itemstack) {
return true;
}
public int getProperty(int i) {
return 0;
}
public void setProperty(int i, int j) {
}
public int h() {
return 0;
}
public void clear() {
this.items.clear();
}
public void a(AutoRecipeStackManager autorecipestackmanager) {
for (ItemStack itemstack : this.items) {
autorecipestackmanager.b(itemstack);
}
}
}

View File

@@ -0,0 +1,719 @@
/*
* Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_13_R2;
import com.google.common.collect.ImmutableList;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import net.minecraft.server.v1_13_R2.AutoRecipeStackManager;
import net.minecraft.server.v1_13_R2.ChatMessage;
import net.minecraft.server.v1_13_R2.ContainerUtil;
import net.minecraft.server.v1_13_R2.CrashReport;
import net.minecraft.server.v1_13_R2.CrashReportSystemDetails;
import net.minecraft.server.v1_13_R2.EntityHuman;
import net.minecraft.server.v1_13_R2.EntityPlayer;
import net.minecraft.server.v1_13_R2.IBlockData;
import net.minecraft.server.v1_13_R2.IChatBaseComponent;
import net.minecraft.server.v1_13_R2.Item;
import net.minecraft.server.v1_13_R2.ItemArmor;
import net.minecraft.server.v1_13_R2.ItemStack;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.NBTTagList;
import net.minecraft.server.v1_13_R2.NonNullList;
import net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot;
import net.minecraft.server.v1_13_R2.PlayerInventory;
import net.minecraft.server.v1_13_R2.ReportedException;
import net.minecraft.server.v1_13_R2.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline;
private NonNullList<ItemStack> items, armor, extraSlots;
private final List<NonNullList<ItemStack>> f;
public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer));
this.playerOnline = online;
this.items = this.player.inventory.items;
this.armor = this.player.inventory.armor;
this.extraSlots = this.player.inventory.extraSlots;
this.f = ImmutableList.of(this.items, this.armor, this.extraSlots);
}
@Override
public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) {
EntityPlayer entityPlayer = PlayerDataManager.getHandle(player);
entityPlayer.inventory.transaction.addAll(this.transaction);
this.player = entityPlayer;
this.player.inventory.a(this);
this.items = this.player.inventory.items;
this.armor = this.player.inventory.armor;
this.extraSlots = this.player.inventory.extraSlots;
this.playerOnline = true;
}
}
@Override
public boolean a(final EntityHuman entityhuman) {
return true;
}
@Override
public @NotNull Inventory getBukkitInventory() {
return inventory;
}
@Override
public ItemStack getItem(int i) {
List<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list.get(i);
}
@Override
public IChatBaseComponent getDisplayName() {
return new ChatMessage(this.player.getName());
}
@Override
public boolean hasCustomName() {
return false;
}
private int getReversedArmorSlotNum(final int i) {
if (i == 0) {
return 3;
}
if (i == 1) {
return 2;
}
if (i == 2) {
return 1;
}
if (i == 3) {
return 0;
}
return i;
}
private int getReversedItemSlotNum(final int i) {
if (i >= 27) {
return i - 27;
}
return i + 9;
}
@Override
public int getSize() {
return super.getSize() + 4;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public void setItem(int i, final ItemStack itemstack) {
List<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
this.player.drop(itemstack, true);
return;
}
list.set(i, itemstack);
}
@Override
public void setPlayerOffline() {
this.playerOnline = false;
}
@Override
public ItemStack splitStack(int i, final int j) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
}
@Override
public ItemStack splitWithoutUpdate(int i) {
NonNullList<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
if (!list.get(i).isEmpty()) {
ItemStack itemstack = list.get(i);
list.set(i, ItemStack.a);
return itemstack;
}
return ItemStack.a;
}
public List<ItemStack> getContents() {
List<ItemStack> combined = new ArrayList<>(this.items.size() + this.armor.size() + this.extraSlots.size());
for (List<ItemStack> sub : this.f) {
combined.addAll(sub);
}
return combined;
}
public List<ItemStack> getArmorContents() {
return this.armor;
}
public void onOpen(CraftHumanEntity who) {
this.transaction.add(who);
}
public void onClose(CraftHumanEntity who) {
this.transaction.remove(who);
}
public List<HumanEntity> getViewers() {
return this.transaction;
}
public InventoryHolder getOwner() {
return this.player.getBukkitEntity();
}
public Location getLocation() {
return this.player.getBukkitEntity().getLocation();
}
public ItemStack getItemInHand() {
return e(this.itemInHandIndex) ? this.items.get(this.itemInHandIndex) : ItemStack.a;
}
public static int getHotbarSize() {
return 9;
}
private boolean a(ItemStack itemstack, ItemStack itemstack1) {
return !itemstack.isEmpty() && this.b(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < itemstack.getMaxStackSize() && itemstack.getCount() < this.getMaxStackSize();
}
private boolean b(ItemStack itemstack, ItemStack itemstack1) {
return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
}
public int canHold(ItemStack itemstack) {
int remains = itemstack.getCount();
for(int i = 0; i < this.items.size(); ++i) {
ItemStack itemstack1 = this.getItem(i);
if (itemstack1.isEmpty()) {
return itemstack.getCount();
}
if (!this.a(itemstack, itemstack1)) {
remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount();
}
if (remains <= 0) {
return itemstack.getCount();
}
}
return itemstack.getCount() - remains;
}
public int getFirstEmptySlotIndex() {
for(int i = 0; i < this.items.size(); ++i) {
if (this.items.get(i).isEmpty()) {
return i;
}
}
return -1;
}
public void d(int i) {
this.itemInHandIndex = this.l();
ItemStack itemstack = this.items.get(this.itemInHandIndex);
this.items.set(this.itemInHandIndex, this.items.get(i));
this.items.set(i, itemstack);
}
public static boolean e(int i) {
return i >= 0 && i < 9;
}
public int c(ItemStack itemstack) {
for(int i = 0; i < this.items.size(); ++i) {
ItemStack itemstack1 = this.items.get(i);
if (!this.items.get(i).isEmpty() && this.b(itemstack, this.items.get(i)) && !this.items.get(i).f() && !itemstack1.hasEnchantments() && !itemstack1.hasName()) {
return i;
}
}
return -1;
}
public int l() {
int i;
int j;
for(j = 0; j < 9; ++j) {
i = (this.itemInHandIndex + j) % 9;
if (this.items.get(i).isEmpty()) {
return i;
}
}
for(j = 0; j < 9; ++j) {
i = (this.itemInHandIndex + j) % 9;
if (!this.items.get(i).hasEnchantments()) {
return i;
}
}
return this.itemInHandIndex;
}
public int a(Predicate<ItemStack> predicate, int i) {
int j = 0;
int k;
for(k = 0; k < this.getSize(); ++k) {
ItemStack itemstack = this.getItem(k);
if (!itemstack.isEmpty() && predicate.test(itemstack)) {
int l = i <= 0 ? itemstack.getCount() : Math.min(i - j, itemstack.getCount());
j += l;
if (i != 0) {
itemstack.subtract(l);
if (itemstack.isEmpty()) {
this.setItem(k, ItemStack.a);
}
if (i > 0 && j >= i) {
return j;
}
}
}
}
if (!this.getCarried().isEmpty() && predicate.test(this.getCarried())) {
k = i <= 0 ? this.getCarried().getCount() : Math.min(i - j, this.getCarried().getCount());
j += k;
if (i != 0) {
this.getCarried().subtract(k);
if (this.getCarried().isEmpty()) {
this.setCarried(ItemStack.a);
}
if (i > 0 && j >= i) {
return j;
}
}
}
return j;
}
private int i(ItemStack itemstack) {
int i = this.firstPartial(itemstack);
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
return i == -1 ? itemstack.getCount() : this.d(i, itemstack);
}
private int d(int i, ItemStack itemstack) {
Item item = itemstack.getItem();
int j = itemstack.getCount();
ItemStack itemstack1 = this.getItem(i);
if (itemstack1.isEmpty()) {
itemstack1 = new ItemStack(item, 0);
if (itemstack.hasTag()) {
itemstack1.setTag(itemstack.getTag().clone());
}
this.setItem(i, itemstack1);
}
int k = j;
if (j > itemstack1.getMaxStackSize() - itemstack1.getCount()) {
k = itemstack1.getMaxStackSize() - itemstack1.getCount();
}
if (k > this.getMaxStackSize() - itemstack1.getCount()) {
k = this.getMaxStackSize() - itemstack1.getCount();
}
if (k == 0) {
return j;
} else {
j -= k;
itemstack1.add(k);
itemstack1.d(5);
return j;
}
}
public int firstPartial(ItemStack itemstack) {
if (this.a(this.getItem(this.itemInHandIndex), itemstack)) {
return this.itemInHandIndex;
} else if (this.a(this.getItem(40), itemstack)) {
return 40;
} else {
for(int i = 0; i < this.items.size(); ++i) {
if (this.a(this.items.get(i), itemstack)) {
return i;
}
}
return -1;
}
}
public void p() {
for (NonNullList<ItemStack> itemStacks : this.f) {
for (int i = 0; i < itemStacks.size(); ++i) {
if (!itemStacks.get(i).isEmpty()) {
itemStacks.get(i).a(this.player.world, this.player, i, this.itemInHandIndex == i);
}
}
}
}
public boolean pickup(ItemStack itemstack) {
return this.c(-1, itemstack);
}
public boolean c(int i, ItemStack itemstack) {
if (itemstack.isEmpty()) {
return false;
} else {
try {
if (itemstack.f()) {
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
if (i >= 0) {
this.items.set(i, itemstack.cloneItemStack());
this.items.get(i).d(5);
itemstack.setCount(0);
return true;
} else if (this.player.abilities.canInstantlyBuild) {
itemstack.setCount(0);
return true;
} else {
return false;
}
} else {
int j;
do {
j = itemstack.getCount();
if (i == -1) {
itemstack.setCount(this.i(itemstack));
} else {
itemstack.setCount(this.d(i, itemstack));
}
} while(!itemstack.isEmpty() && itemstack.getCount() < j);
if (itemstack.getCount() == j && this.player.abilities.canInstantlyBuild) {
itemstack.setCount(0);
return true;
} else {
return itemstack.getCount() < j;
}
}
} catch (Throwable var6) {
CrashReport crashreport = CrashReport.a(var6, "Adding item to inventory");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Item being added");
crashreportsystemdetails.a("Item ID", Item.getId(itemstack.getItem()));
crashreportsystemdetails.a("Item data", itemstack.getDamage());
crashreportsystemdetails.a("Item name", () -> itemstack.getName().getString());
throw new ReportedException(crashreport);
}
}
}
public void a(World world, ItemStack itemstack) {
if (!world.isClientSide) {
while(!itemstack.isEmpty()) {
int i = this.firstPartial(itemstack);
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
if (i == -1) {
this.player.drop(itemstack, false);
break;
}
int j = itemstack.getMaxStackSize() - this.getItem(i).getCount();
if (this.c(i, itemstack.cloneAndSubtract(j))) {
((EntityPlayer)this.player).playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, i, this.getItem(i)));
}
}
}
}
public void f(ItemStack itemstack) {
for (NonNullList<ItemStack> nonnulllist : this.f) {
for (int i = 0; i < nonnulllist.size(); ++i) {
if (nonnulllist.get(i) == itemstack) {
nonnulllist.set(i, ItemStack.a);
break;
}
}
}
}
public float a(IBlockData iblockdata) {
return this.items.get(this.itemInHandIndex).a(iblockdata);
}
public NBTTagList a(NBTTagList nbttaglist) {
NBTTagCompound nbttagcompound;
int i;
for(i = 0; i < this.items.size(); ++i) {
if (!this.items.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) i);
this.items.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
for(i = 0; i < this.armor.size(); ++i) {
if (!this.armor.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) (i + 100));
this.armor.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
for(i = 0; i < this.extraSlots.size(); ++i) {
if (!this.extraSlots.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) (i + 150));
this.extraSlots.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
return nbttaglist;
}
public void b(NBTTagList nbttaglist) {
this.items.clear();
this.armor.clear();
this.extraSlots.clear();
for(int i = 0; i < nbttaglist.size(); ++i) {
NBTTagCompound nbttagcompound = nbttaglist.getCompound(i);
int j = nbttagcompound.getByte("Slot") & 255;
ItemStack itemstack = ItemStack.a(nbttagcompound);
if (!itemstack.isEmpty()) {
if (j < this.items.size()) {
this.items.set(j, itemstack);
} else if (j >= 100 && j < this.armor.size() + 100) {
this.armor.set(j - 100, itemstack);
} else if (j >= 150 && j < this.extraSlots.size() + 150) {
this.extraSlots.set(j - 150, itemstack);
}
}
}
}
public boolean P_() {
Iterator iterator = this.items.iterator();
ItemStack itemstack;
while(iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
iterator = this.armor.iterator();
while(iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
iterator = this.extraSlots.iterator();
while(iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
return true;
}
@Nullable
public IChatBaseComponent getCustomName() {
return null;
}
public boolean b(IBlockData iblockdata) {
return this.getItem(this.itemInHandIndex).b(iblockdata);
}
public void a(float f) {
if (f > 0.0F) {
f /= 4.0F;
if (f < 1.0F) {
f = 1.0F;
}
for (ItemStack itemstack : this.armor) {
if (itemstack.getItem() instanceof ItemArmor) {
itemstack.damage((int) f, this.player);
}
}
}
}
public void dropContents() {
for (NonNullList<ItemStack> itemStacks : this.f) {
for (int i = 0; i < itemStacks.size(); ++i) {
ItemStack itemstack = itemStacks.get(i);
if (!itemstack.isEmpty()) {
itemStacks.set(i, ItemStack.a);
this.player.a(itemstack, true, false);
}
}
}
}
public boolean h(ItemStack itemstack) {
return this.f.stream().flatMap(NonNullList::stream).anyMatch(itemStack1 -> !itemStack1.isEmpty() && itemStack1.doMaterialsMatch(itemstack));
}
public void a(PlayerInventory playerinventory) {
for (int i = 0; i < playerinventory.getSize(); ++i) {
this.setItem(i, playerinventory.getItem(i));
}
this.itemInHandIndex = playerinventory.itemInHandIndex;
}
public void clear() {
this.f.forEach(NonNullList::clear);
}
public void a(AutoRecipeStackManager autorecipestackmanager) {
for (ItemStack itemstack : this.items) {
autorecipestackmanager.a(itemstack);
}
}
}

59
internal/v1_14_R1/pom.xml Normal file
View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2011-2019 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>4.0.0</version>
</parent>
<artifactId>openinvadapter1_14_R1</artifactId>
<name>OpenInvAdapter1_14_R1</name>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,320 @@
/*
* Copyright (C) 2011-2019 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_14_R1;
import com.lishid.openinv.internal.IAnySilentContainer;
import java.lang.reflect.Field;
import javax.annotation.Nullable;
import net.minecraft.server.v1_14_R1.AxisAlignedBB;
import net.minecraft.server.v1_14_R1.Block;
import net.minecraft.server.v1_14_R1.BlockChest;
import net.minecraft.server.v1_14_R1.BlockChestTrapped;
import net.minecraft.server.v1_14_R1.BlockEnderChest;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.BlockPropertyChestType;
import net.minecraft.server.v1_14_R1.BlockShulkerBox;
import net.minecraft.server.v1_14_R1.ChatMessage;
import net.minecraft.server.v1_14_R1.Container;
import net.minecraft.server.v1_14_R1.ContainerChest;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityCat;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.EnumDirection;
import net.minecraft.server.v1_14_R1.EnumGamemode;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.ITileInventory;
import net.minecraft.server.v1_14_R1.InventoryEnderChest;
import net.minecraft.server.v1_14_R1.InventoryLargeChest;
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
import net.minecraft.server.v1_14_R1.PlayerInventory;
import net.minecraft.server.v1_14_R1.TileEntity;
import net.minecraft.server.v1_14_R1.TileEntityChest;
import net.minecraft.server.v1_14_R1.TileEntityEnderChest;
import net.minecraft.server.v1_14_R1.TileEntityShulkerBox;
import net.minecraft.server.v1_14_R1.TileInventory;
import net.minecraft.server.v1_14_R1.VoxelShapes;
import net.minecraft.server.v1_14_R1.World;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer {
private Field playerInteractManagerGamemode;
public AnySilentContainer() {
try {
this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
this.playerInteractManagerGamemode.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
e.printStackTrace();
}
}
@Override
public boolean isAnySilentContainer(@NotNull final org.bukkit.block.Block bukkitBlock) {
if (bukkitBlock.getType() == Material.ENDER_CHEST) {
return true;
}
BlockState state = bukkitBlock.getState();
return state instanceof org.bukkit.block.Chest
|| state instanceof org.bukkit.block.ShulkerBox;
}
@Override
public boolean isAnyContainerNeeded(@NotNull final Player p, @NotNull final org.bukkit.block.Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p);
World world = player.world;
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock();
if (block instanceof BlockShulkerBox) {
return this.isBlockedShulkerBox(world, blockPosition, blockData);
}
if (block instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots.
return world.getType(blockPosition.up()).isOccluding(world, blockPosition);
}
// Check if chest is blocked or has an ocelot on top
if (this.isBlockedChest(world, blockPosition)) {
return true;
}
// Check for matching adjacent chests that are blocked or have an ocelot on top
BlockPropertyChestType chestType = blockData.get(BlockChest.b);
if (chestType == BlockPropertyChestType.SINGLE) {
return false;
}
BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.j(blockData));
IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
if (adjacentBlockData.getBlock() == block) {
BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
&& adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
return this.isBlockedChest(world, adjacentBlockPosition);
}
}
return false;
}
private boolean isBlockedShulkerBox(final World world, final BlockPosition blockPosition,
final IBlockData blockData) {
// For reference, look at net.minecraft.server.BlockShulkerBox
TileEntity tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return false;
}
EnumDirection enumDirection = blockData.get(BlockShulkerBox.a);
if (((TileEntityShulkerBox) tile).s() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
AxisAlignedBB axisAlignedBB = VoxelShapes.b().getBoundingBox()
.b(0.5F * enumDirection.getAdjacentX(), 0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(), enumDirection.getAdjacentZ());
return !world.getCubes(null, axisAlignedBB.a(blockPosition.shift(enumDirection)));
}
return false;
}
private boolean isBlockedChest(final World world, final BlockPosition blockPosition) {
// For reference, loot at net.minecraft.server.BlockChest
return world.getType(blockPosition.up()).isOccluding(world, blockPosition) || this.hasOcelotOnTop(world, blockPosition);
}
private boolean hasOcelotOnTop(final World world, final BlockPosition blockPosition) {
for (Entity entity : world.a(EntityCat.class,
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
blockPosition.getZ() + 1))) {
EntityCat entityCat = (EntityCat) entity;
if (entityCat.isSitting()) {
return true;
}
}
return false;
}
@Override
public boolean activateContainer(@NotNull final Player bukkitPlayer, final boolean silentchest,
@NotNull final org.bukkit.block.Block bukkitBlock) {
// Silent ender chest is API-only
if (silentchest && bukkitBlock.getType() == Material.ENDER_CHEST) {
bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
final World world = player.world;
final BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
final Object tile = world.getTileEntity(blockPosition);
if (tile == null) {
return false;
}
if (tile instanceof TileEntityEnderChest) {
// Anychest ender chest. See net.minecraft.server.BlockEnderChest
InventoryEnderChest enderChest = player.getEnderChest();
enderChest.a((TileEntityEnderChest) tile);
player.openContainer(new TileInventory((containerCounter, playerInventory, ignored) ->
ContainerChest.a(containerCounter, playerInventory, enderChest), BlockEnderChest.d));
bukkitPlayer.incrementStatistic(Statistic.ENDERCHEST_OPENED);
return true;
}
if (!(tile instanceof ITileInventory)) {
return false;
}
ITileInventory tileInventory = (ITileInventory) tile;
IBlockData blockData = world.getType(blockPosition);
Block block = blockData.getBlock();
if (block instanceof BlockChest) {
BlockPropertyChestType chestType = blockData.get(BlockChest.b);
if (chestType != BlockPropertyChestType.SINGLE) {
BlockPosition adjacentBlockPosition = blockPosition.shift(BlockChest.j(blockData));
IBlockData adjacentBlockData = world.getType(adjacentBlockPosition);
if (adjacentBlockData.getBlock() == block) {
BlockPropertyChestType adjacentChestType = adjacentBlockData.get(BlockChest.b);
if (adjacentChestType != BlockPropertyChestType.SINGLE && chestType != adjacentChestType
&& adjacentBlockData.get(BlockChest.FACING) == blockData.get(BlockChest.FACING)) {
TileEntity adjacentTile = world.getTileEntity(adjacentBlockPosition);
if (adjacentTile instanceof TileEntityChest && tileInventory instanceof TileEntityChest) {
TileEntityChest rightChest = chestType == BlockPropertyChestType.RIGHT ? ((TileEntityChest) tileInventory) : (TileEntityChest) adjacentTile;
TileEntityChest leftChest = chestType == BlockPropertyChestType.RIGHT ? (TileEntityChest) adjacentTile : ((TileEntityChest) tileInventory);
tileInventory = new ITileInventory() {
@Nullable
public Container createMenu(int containerCounter, PlayerInventory playerInventory, EntityHuman entityHuman) {
if (leftChest.e(entityHuman) && rightChest.e(entityHuman)) {
leftChest.d(playerInventory.player);
rightChest.d(playerInventory.player);
return ContainerChest.b(containerCounter, playerInventory, new InventoryLargeChest(rightChest, leftChest));
} else {
return null;
}
}
public IChatBaseComponent getScoreboardDisplayName() {
return new ChatMessage("container.chestDouble");
}
};
}
}
}
}
if (block instanceof BlockChestTrapped) {
bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
} else {
bukkitPlayer.incrementStatistic(Statistic.CHEST_OPENED);
}
}
if (block instanceof BlockShulkerBox) {
bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
}
// AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory);
return true;
}
// SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
case SHULKER_BOX:
break;
default:
return;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try {
if (!this.playerInteractManagerGamemode.isAccessible()) {
// Just in case, ensure accessible.
this.playerInteractManagerGamemode.setAccessible(true);
}
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2011-2019 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_14_R1;
import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor;
import net.minecraft.server.v1_14_R1.IInventory;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess {
@Override
public ISpecialEnderChest getSpecialEnderChest(@NotNull final Inventory inventory) {
IInventory inv;
if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory();
} else {
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
}
if (inv instanceof SpecialEnderChest) {
return (SpecialEnderChest) inv;
}
return null;
}
@Override
public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull final Inventory inventory) {
IInventory inv;
if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory();
} else {
inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
}
if (inv instanceof SpecialPlayerInventory) {
return (SpecialPlayerInventory) inv;
}
return null;
}
@Override
public boolean isSpecialEnderChest(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
}
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
inventory) instanceof ISpecialEnderChest;
}
@Override
public boolean isSpecialPlayerInventory(@NotNull final Inventory inventory) {
if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
}
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
inventory) instanceof ISpecialPlayerInventory;
}
}

View File

@@ -0,0 +1,183 @@
/*
* Copyright (C) 2011-2019 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_14_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import com.mojang.authlib.GameProfile;
import java.util.Collection;
import java.util.UUID;
import net.minecraft.server.v1_14_R1.ChatComponentText;
import net.minecraft.server.v1_14_R1.Container;
import net.minecraft.server.v1_14_R1.Containers;
import net.minecraft.server.v1_14_R1.DimensionManager;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.MinecraftServer;
import net.minecraft.server.v1_14_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
import net.minecraft.server.v1_14_R1.PlayerInventory;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager {
public static EntityPlayer getHandle(final Player player) {
if (player instanceof CraftPlayer) {
return ((CraftPlayer) player).getHandle();
}
Server server = player.getServer();
EntityPlayer nmsPlayer = null;
if (server instanceof CraftServer) {
nmsPlayer = ((CraftServer) server).getHandle().getPlayer(player.getName());
}
if (nmsPlayer == null) {
// Could use reflection to examine fields, but it's honestly not worth the bother.
throw new RuntimeException("Unable to fetch EntityPlayer from provided Player implementation");
}
return nmsPlayer;
}
@Override
public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Bukkit.getOnlinePlayers();
}
@Override
public OfflinePlayer getPlayerByID(@NotNull final String identifier) {
try {
UUID uuid = UUID.fromString(identifier);
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
// Ensure player is a real player, otherwise return null
if (!player.hasPlayedBefore() && !player.isOnline()) {
return null;
}
return player;
} catch (IllegalArgumentException e) {
// Not a UUID
return null;
}
}
@Override
public @NotNull String getPlayerDataID(@NotNull final OfflinePlayer offline) {
return offline.getUniqueId().toString();
}
@Override
public Player loadPlayer(@NotNull final OfflinePlayer offline) {
// Ensure player has data
if (!offline.hasPlayedBefore()) {
return null;
}
// Create a profile and entity to load the player data
GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(DimensionManager.OVERWORLD), profile,
new PlayerInteractManager(server.getWorldServer(DimensionManager.OVERWORLD)));
// Get the bukkit entity
Player target = entity.getBukkitEntity();
if (target != null) {
// Load data
target.loadData();
}
// Return the entity
return target;
}
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
EntityPlayer nmsPlayer = getHandle(player);
if (nmsPlayer == null || nmsPlayer.playerConnection == null) {
return null;
}
String title;
if (inventory instanceof SpecialEnderChest) {
HumanEntity owner = (HumanEntity) ((SpecialEnderChest) inventory).getBukkitOwner();
title = (owner.getName() != null ? owner.getName() : owner.getUniqueId().toString()) + "'s Ender Chest";
} else if (inventory instanceof SpecialPlayerInventory) {
EntityHuman owner = ((PlayerInventory) inventory).player;
title = (owner.getName() != null ? owner.getName() : owner.getUniqueID().toString()) + "'s Inventory";
} else {
return player.openInventory(inventory.getBukkitInventory());
}
Container container = new CraftContainer(new InventoryView() {
@Override
public @NotNull Inventory getTopInventory() {
return inventory.getBukkitInventory();
}
@Override
public @NotNull Inventory getBottomInventory() {
return player.getInventory();
}
@Override
public @NotNull HumanEntity getPlayer() {
return player;
}
@Override
public @NotNull InventoryType getType() {
return inventory.getBukkitInventory().getType();
}
@Override
public @NotNull String getTitle() {
return title;
}
}, nmsPlayer, nmsPlayer.nextContainerCounter()) {
@Override
public Containers<?> getType() {
return inventory instanceof SpecialEnderChest ? Containers.GENERIC_9X3 : Containers.GENERIC_9X5;
}
};
container.setTitle(new ChatComponentText(title));
container = CraftEventFactory.callInventoryOpenEvent(nmsPlayer, container);
if (container == null) {
return null;
}
nmsPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, container.getType(),
new ChatComponentText(container.getBukkitView().getTitle())));
nmsPlayer.activeContainer = container;
container.addSlotListener(nmsPlayer);
return container.getBukkitView();
}
}

View File

@@ -0,0 +1,255 @@
/*
* Copyright (C) 2011-2019 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_14_R1;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.util.List;
import net.minecraft.server.v1_14_R1.AutoRecipeStackManager;
import net.minecraft.server.v1_14_R1.ContainerUtil;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.IInventoryListener;
import net.minecraft.server.v1_14_R1.InventoryEnderChest;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NonNullList;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventoryEnderChest implements ISpecialEnderChest {
private final CraftInventory inventory;
private EntityPlayer owner;
private NonNullList<ItemStack> items;
private boolean playerOnline;
public SpecialEnderChest(final Player player, final Boolean online) {
super(PlayerDataManager.getHandle(player));
this.inventory = new CraftInventory(this);
this.owner = PlayerDataManager.getHandle(player);
this.playerOnline = online;
this.items = this.owner.getEnderChest().items;
}
@Override
public @NotNull CraftInventory getBukkitInventory() {
return inventory;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public void setPlayerOffline() {
this.playerOnline = false;
}
@Override
public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) {
try {
this.owner = PlayerDataManager.getHandle(player);
InventoryEnderChest enderChest = owner.getEnderChest();
for (int i = 0; i < enderChest.getSize(); ++i) {
enderChest.setItem(i, this.items.get(i));
}
this.items = enderChest.items;
} catch (Exception ignored) {}
this.playerOnline = true;
}
}
@Override
public void update() {
this.owner.getEnderChest().update();
}
@Override
public List<ItemStack> getContents() {
return this.items;
}
@Override
public void onOpen(CraftHumanEntity who) {
this.owner.getEnderChest().onOpen(who);
}
@Override
public void onClose(CraftHumanEntity who) {
this.owner.getEnderChest().onClose(who);
}
@Override
public List<HumanEntity> getViewers() {
return this.owner.getEnderChest().getViewers();
}
@Override
public void setMaxStackSize(int i) {
this.owner.getEnderChest().setMaxStackSize(i);
}
@Override
public InventoryHolder getOwner() {
return this.owner.getEnderChest().getOwner();
}
@Override
public Location getLocation() {
return null;
}
@Override
public void a(IInventoryListener iinventorylistener) {
this.owner.getEnderChest().a(iinventorylistener);
}
@Override
public void b(IInventoryListener iinventorylistener) {
this.owner.getEnderChest().b(iinventorylistener);
}
@Override
public ItemStack getItem(int i) {
return i >= 0 && i < this.items.size() ? this.items.get(i) : ItemStack.a;
}
@Override
public ItemStack splitStack(int i, int j) {
ItemStack itemstack = ContainerUtil.a(this.items, i, j);
if (!itemstack.isEmpty()) {
this.update();
}
return itemstack;
}
@Override
public ItemStack a(ItemStack itemstack) {
ItemStack itemstack1 = itemstack.cloneItemStack();
for (int i = 0; i < this.getSize(); ++i) {
ItemStack itemstack2 = this.getItem(i);
if (itemstack2.isEmpty()) {
this.setItem(i, itemstack1);
this.update();
return ItemStack.a;
}
if (ItemStack.c(itemstack2, itemstack1)) {
int j = Math.min(this.getMaxStackSize(), itemstack2.getMaxStackSize());
int k = Math.min(itemstack1.getCount(), j - itemstack2.getCount());
if (k > 0) {
itemstack2.add(k);
itemstack1.subtract(k);
if (itemstack1.isEmpty()) {
this.update();
return ItemStack.a;
}
}
}
}
if (itemstack1.getCount() != itemstack.getCount()) {
this.update();
}
return itemstack1;
}
@Override
public ItemStack splitWithoutUpdate(int i) {
ItemStack itemstack = this.items.get(i);
if (itemstack.isEmpty()) {
return ItemStack.a;
} else {
this.items.set(i, ItemStack.a);
return itemstack;
}
}
@Override
public void setItem(int i, ItemStack itemstack) {
this.items.set(i, itemstack);
if (!itemstack.isEmpty() && itemstack.getCount() > this.getMaxStackSize()) {
itemstack.setCount(this.getMaxStackSize());
}
this.update();
}
@Override
public int getSize() {
return this.owner.getEnderChest().getSize();
}
@Override
public boolean isNotEmpty() {
for (ItemStack itemstack : this.items) {
if (!itemstack.isEmpty()) {
return false;
}
}
return true;
}
@Override
public int getMaxStackSize() {
return 64;
}
@Override
public boolean a(EntityHuman entityhuman) {
return true;
}
@Override
public void startOpen(EntityHuman entityhuman) {
}
@Override
public void closeContainer(EntityHuman entityhuman) {
}
@Override
public boolean b(int i, ItemStack itemstack) {
return true;
}
@Override
public void clear() {
this.items.clear();
}
@Override
public void a(AutoRecipeStackManager autorecipestackmanager) {
for (ItemStack itemstack : this.items) {
autorecipestackmanager.b(itemstack);
}
}
}

View File

@@ -0,0 +1,742 @@
/*
* Copyright (C) 2011-2019 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 <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_14_R1;
import com.google.common.collect.ImmutableList;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import net.minecraft.server.v1_14_R1.AutoRecipeStackManager;
import net.minecraft.server.v1_14_R1.ChatMessage;
import net.minecraft.server.v1_14_R1.ContainerUtil;
import net.minecraft.server.v1_14_R1.CrashReport;
import net.minecraft.server.v1_14_R1.CrashReportSystemDetails;
import net.minecraft.server.v1_14_R1.EntityHuman;
import net.minecraft.server.v1_14_R1.EntityPlayer;
import net.minecraft.server.v1_14_R1.EnumItemSlot;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.IChatBaseComponent;
import net.minecraft.server.v1_14_R1.Item;
import net.minecraft.server.v1_14_R1.ItemArmor;
import net.minecraft.server.v1_14_R1.ItemStack;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.NBTTagList;
import net.minecraft.server.v1_14_R1.NonNullList;
import net.minecraft.server.v1_14_R1.PacketPlayOutSetSlot;
import net.minecraft.server.v1_14_R1.PlayerInventory;
import net.minecraft.server.v1_14_R1.ReportedException;
import net.minecraft.server.v1_14_R1.World;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final CraftInventory inventory;
private boolean playerOnline;
private EntityHuman player;
private NonNullList<ItemStack> items, armor, extraSlots;
private final List<NonNullList<ItemStack>> f;
public SpecialPlayerInventory(final Player bukkitPlayer, final Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer));
this.inventory = new CraftInventory(this);
this.playerOnline = online;
this.player = super.player;
this.items = this.player.inventory.items;
this.armor = this.player.inventory.armor;
this.extraSlots = this.player.inventory.extraSlots;
this.f = ImmutableList.of(this.items, this.armor, this.extraSlots);
}
@Override
public void setPlayerOnline(@NotNull final Player player) {
if (!this.playerOnline) {
EntityPlayer entityPlayer = PlayerDataManager.getHandle(player);
entityPlayer.inventory.transaction.addAll(this.transaction);
this.player = entityPlayer;
this.player.inventory.a(this);
this.items = this.player.inventory.items;
this.armor = this.player.inventory.armor;
this.extraSlots = this.player.inventory.extraSlots;
this.playerOnline = true;
}
}
@Override
public boolean a(final EntityHuman entityhuman) {
return true;
}
@Override
public @NotNull CraftInventory getBukkitInventory() {
return this.inventory;
}
@Override
public ItemStack getItem(int i) {
List<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list.get(i);
}
@Override
public IChatBaseComponent getDisplayName() {
return new ChatMessage(this.player.getName());
}
@Override
public boolean hasCustomName() {
return false;
}
private int getReversedArmorSlotNum(final int i) {
if (i == 0) {
return 3;
}
if (i == 1) {
return 2;
}
if (i == 2) {
return 1;
}
if (i == 3) {
return 0;
}
return i;
}
private int getReversedItemSlotNum(final int i) {
if (i >= 27) {
return i - 27;
}
return i + 9;
}
@Override
public int getSize() {
return 45;
}
@Override
public boolean isInUse() {
return !this.getViewers().isEmpty();
}
@Override
public void setItem(int i, final ItemStack itemstack) {
List<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
this.player.drop(itemstack, true);
return;
}
list.set(i, itemstack);
}
@Override
public void setPlayerOffline() {
this.playerOnline = false;
}
@Override
public ItemStack splitStack(int i, final int j) {
List<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
return list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
}
@Override
public ItemStack splitWithoutUpdate(int i) {
List<ItemStack> list = this.items;
if (i >= list.size()) {
i -= list.size();
list = this.armor;
} else {
i = this.getReversedItemSlotNum(i);
}
if (i >= list.size()) {
i -= list.size();
list = this.extraSlots;
} else if (list == this.armor) {
i = this.getReversedArmorSlotNum(i);
}
if (i >= list.size()) {
return ItemStack.a;
}
if (!list.get(i).isEmpty()) {
ItemStack itemstack = list.get(i);
list.set(i, ItemStack.a);
return itemstack;
}
return ItemStack.a;
}
@Override
public List<ItemStack> getContents() {
return this.f.stream().flatMap(List::stream).collect(Collectors.toList());
}
@Override
public List<ItemStack> getArmorContents() {
return this.armor;
}
@Override
public void onOpen(CraftHumanEntity who) {
this.transaction.add(who);
}
@Override
public void onClose(CraftHumanEntity who) {
this.transaction.remove(who);
}
@Override
public List<HumanEntity> getViewers() {
return this.transaction;
}
@Override
public InventoryHolder getOwner() {
return this.player.getBukkitEntity();
}
@Override
public Location getLocation() {
return this.player.getBukkitEntity().getLocation();
}
@Override
public ItemStack getItemInHand() {
return d(this.itemInHandIndex) ? this.items.get(this.itemInHandIndex) : ItemStack.a;
}
private boolean a(ItemStack itemstack, ItemStack itemstack1) {
return !itemstack.isEmpty() && this.b(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < itemstack.getMaxStackSize() && itemstack.getCount() < this.getMaxStackSize();
}
private boolean b(ItemStack itemstack, ItemStack itemstack1) {
return itemstack.getItem() == itemstack1.getItem() && ItemStack.equals(itemstack, itemstack1);
}
@Override
public int canHold(ItemStack itemstack) {
int remains = itemstack.getCount();
for (int i = 0; i < this.items.size(); ++i) {
ItemStack itemstack1 = this.getItem(i);
if (itemstack1.isEmpty()) {
return itemstack.getCount();
}
if (!this.a(itemstack, itemstack1)) {
remains -= (itemstack1.getMaxStackSize() < this.getMaxStackSize() ? itemstack1.getMaxStackSize() : this.getMaxStackSize()) - itemstack1.getCount();
}
if (remains <= 0) {
return itemstack.getCount();
}
}
return itemstack.getCount() - remains;
}
@Override
public int getFirstEmptySlotIndex() {
for (int i = 0; i < this.items.size(); ++i) {
if (this.items.get(i).isEmpty()) {
return i;
}
}
return -1;
}
@Override
public void c(int i) {
this.itemInHandIndex = this.i();
ItemStack itemstack = this.items.get(this.itemInHandIndex);
this.items.set(this.itemInHandIndex, this.items.get(i));
this.items.set(i, itemstack);
}
@Override
public int c(ItemStack itemstack) {
for (int i = 0; i < this.items.size(); ++i) {
ItemStack itemstack1 = this.items.get(i);
if (!this.items.get(i).isEmpty() && this.b(itemstack, this.items.get(i)) && !this.items.get(i).f() && !itemstack1.hasEnchantments() && !itemstack1.hasName()) {
return i;
}
}
return -1;
}
@Override
public int i() {
int i;
int j;
for (j = 0; j < 9; ++j) {
i = (this.itemInHandIndex + j) % 9;
if (this.items.get(i).isEmpty()) {
return i;
}
}
for (j = 0; j < 9; ++j) {
i = (this.itemInHandIndex + j) % 9;
if (!this.items.get(i).hasEnchantments()) {
return i;
}
}
return this.itemInHandIndex;
}
@Override
public int a(Predicate<ItemStack> predicate, int i) {
int j = 0;
int k;
for (k = 0; k < this.getSize(); ++k) {
ItemStack itemstack = this.getItem(k);
if (!itemstack.isEmpty() && predicate.test(itemstack)) {
int l = i <= 0 ? itemstack.getCount() : Math.min(i - j, itemstack.getCount());
j += l;
if (i != 0) {
itemstack.subtract(l);
if (itemstack.isEmpty()) {
this.setItem(k, ItemStack.a);
}
if (i > 0 && j >= i) {
return j;
}
}
}
}
if (!this.getCarried().isEmpty() && predicate.test(this.getCarried())) {
k = i <= 0 ? this.getCarried().getCount() : Math.min(i - j, this.getCarried().getCount());
j += k;
if (i != 0) {
this.getCarried().subtract(k);
if (this.getCarried().isEmpty()) {
this.setCarried(ItemStack.a);
}
if (i > 0 && j >= i) {
return j;
}
}
}
return j;
}
private int i(ItemStack itemstack) {
int i = this.firstPartial(itemstack);
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
return i == -1 ? itemstack.getCount() : this.d(i, itemstack);
}
private int d(int i, ItemStack itemstack) {
Item item = itemstack.getItem();
int j = itemstack.getCount();
ItemStack itemstack1 = this.getItem(i);
if (itemstack1.isEmpty()) {
itemstack1 = new ItemStack(item, 0);
if (itemstack.hasTag()) {
itemstack1.setTag(itemstack.getTag().clone());
}
this.setItem(i, itemstack1);
}
int k = j;
if (j > itemstack1.getMaxStackSize() - itemstack1.getCount()) {
k = itemstack1.getMaxStackSize() - itemstack1.getCount();
}
if (k > this.getMaxStackSize() - itemstack1.getCount()) {
k = this.getMaxStackSize() - itemstack1.getCount();
}
if (k == 0) {
return j;
} else {
j -= k;
itemstack1.add(k);
itemstack1.d(5);
return j;
}
}
@Override
public int firstPartial(ItemStack itemstack) {
if (this.a(this.getItem(this.itemInHandIndex), itemstack)) {
return this.itemInHandIndex;
} else if (this.a(this.getItem(40), itemstack)) {
return 40;
} else {
for (int i = 0; i < this.items.size(); ++i) {
if (this.a(this.items.get(i), itemstack)) {
return i;
}
}
return -1;
}
}
@Override
public void j() {
for (List<ItemStack> itemStacks : this.f) {
for (int i = 0; i < itemStacks.size(); ++i) {
if (!itemStacks.get(i).isEmpty()) {
itemStacks.get(i).a(this.player.world, this.player, i, this.itemInHandIndex == i);
}
}
}
}
@Override
public boolean pickup(ItemStack itemstack) {
return this.c(-1, itemstack);
}
@Override
public boolean c(int i, ItemStack itemstack) {
if (itemstack.isEmpty()) {
return false;
} else {
try {
if (itemstack.f()) {
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
if (i >= 0) {
this.items.set(i, itemstack.cloneItemStack());
this.items.get(i).d(5);
itemstack.setCount(0);
return true;
} else if (this.player.abilities.canInstantlyBuild) {
itemstack.setCount(0);
return true;
} else {
return false;
}
} else {
int j;
do {
j = itemstack.getCount();
if (i == -1) {
itemstack.setCount(this.i(itemstack));
} else {
itemstack.setCount(this.d(i, itemstack));
}
} while(!itemstack.isEmpty() && itemstack.getCount() < j);
if (itemstack.getCount() == j && this.player.abilities.canInstantlyBuild) {
itemstack.setCount(0);
return true;
} else {
return itemstack.getCount() < j;
}
}
} catch (Throwable var6) {
CrashReport crashreport = CrashReport.a(var6, "Adding item to inventory");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Item being added");
crashreportsystemdetails.a("Item ID", Item.getId(itemstack.getItem()));
crashreportsystemdetails.a("Item data", itemstack.getDamage());
crashreportsystemdetails.a("Item name", () -> itemstack.getName().getString());
throw new ReportedException(crashreport);
}
}
}
@Override
public void a(World world, ItemStack itemstack) {
if (!world.isClientSide) {
while(!itemstack.isEmpty()) {
int i = this.firstPartial(itemstack);
if (i == -1) {
i = this.getFirstEmptySlotIndex();
}
if (i == -1) {
this.player.drop(itemstack, false);
break;
}
int j = itemstack.getMaxStackSize() - this.getItem(i).getCount();
if (this.c(i, itemstack.cloneAndSubtract(j))) {
((EntityPlayer)this.player).playerConnection.sendPacket(new PacketPlayOutSetSlot(-2, i, this.getItem(i)));
}
}
}
}
@Override
public void f(ItemStack itemstack) {
for (List<ItemStack> list : this.f) {
for (int i = 0; i < list.size(); ++i) {
if (list.get(i) == itemstack) {
list.set(i, ItemStack.a);
break;
}
}
}
}
@Override
public float a(IBlockData iblockdata) {
return this.items.get(this.itemInHandIndex).a(iblockdata);
}
@Override
public NBTTagList a(NBTTagList nbttaglist) {
NBTTagCompound nbttagcompound;
int i;
for (i = 0; i < this.items.size(); ++i) {
if (!this.items.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) i);
this.items.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
for (i = 0; i < this.armor.size(); ++i) {
if (!this.armor.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) (i + 100));
this.armor.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
for (i = 0; i < this.extraSlots.size(); ++i) {
if (!this.extraSlots.get(i).isEmpty()) {
nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) (i + 150));
this.extraSlots.get(i).save(nbttagcompound);
nbttaglist.add(nbttagcompound);
}
}
return nbttaglist;
}
@Override
public void b(NBTTagList nbttaglist) {
this.items.clear();
this.armor.clear();
this.extraSlots.clear();
for(int i = 0; i < nbttaglist.size(); ++i) {
NBTTagCompound nbttagcompound = nbttaglist.getCompound(i);
int j = nbttagcompound.getByte("Slot") & 255;
ItemStack itemstack = ItemStack.a(nbttagcompound);
if (!itemstack.isEmpty()) {
if (j < this.items.size()) {
this.items.set(j, itemstack);
} else if (j >= 100 && j < this.armor.size() + 100) {
this.armor.set(j - 100, itemstack);
} else if (j >= 150 && j < this.extraSlots.size() + 150) {
this.extraSlots.set(j - 150, itemstack);
}
}
}
}
@Override
public boolean isNotEmpty() {
Iterator iterator = this.items.iterator();
ItemStack itemstack;
while (iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
iterator = this.armor.iterator();
while (iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
iterator = this.extraSlots.iterator();
while (iterator.hasNext()) {
itemstack = (ItemStack)iterator.next();
if (!itemstack.isEmpty()) {
return false;
}
}
return true;
}
@Nullable
@Override
public IChatBaseComponent getCustomName() {
return null;
}
@Override
public boolean b(IBlockData iblockdata) {
return this.getItem(this.itemInHandIndex).b(iblockdata);
}
@Override
public void a(float f) {
if (f > 0.0F) {
f /= 4.0F;
if (f < 1.0F) {
f = 1.0F;
}
for (int i = 0; i < this.armor.size(); ++i) {
ItemStack itemstack = this.armor.get(0);
int index = i;
if (itemstack.getItem() instanceof ItemArmor) {
itemstack.damage((int) f, this.player, (entityhuman) -> entityhuman.c(EnumItemSlot.a(EnumItemSlot.Function.ARMOR, index)));
}
}
}
}
@Override
public void dropContents() {
for (List<ItemStack> itemStacks : this.f) {
for (int i = 0; i < itemStacks.size(); ++i) {
ItemStack itemstack = itemStacks.get(i);
if (!itemstack.isEmpty()) {
itemStacks.set(i, ItemStack.a);
this.player.a(itemstack, true, false);
}
}
}
}
@Override
public boolean h(ItemStack itemstack) {
return this.f.stream().flatMap(List::stream).anyMatch(itemStack1 -> !itemStack1.isEmpty() && itemStack1.doMaterialsMatch(itemstack));
}
@Override
public void a(PlayerInventory playerinventory) {
for (int i = 0; i < playerinventory.getSize(); ++i) {
this.setItem(i, playerinventory.getItem(i));
}
this.itemInHandIndex = playerinventory.itemInHandIndex;
}
@Override
public void clear() {
this.f.forEach(List::clear);
}
@Override
public void a(AutoRecipeStackManager autorecipestackmanager) {
for (ItemStack itemstack : this.items) {
autorecipestackmanager.a(itemstack);
}
}
}

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_4_R1</artifactId> <artifactId>openinvadapter1_4_R1</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,11 +17,6 @@
package com.lishid.openinv.internal.v1_4_R1; package com.lishid.openinv.internal.v1_4_R1;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_R1.AxisAlignedBB; import net.minecraft.server.v1_4_R1.AxisAlignedBB;
import net.minecraft.server.v1_4_R1.BlockEnderChest; import net.minecraft.server.v1_4_R1.BlockEnderChest;
import net.minecraft.server.v1_4_R1.Container; import net.minecraft.server.v1_4_R1.Container;
@@ -34,43 +29,46 @@ import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
import net.minecraft.server.v1_4_R1.TileEntityChest; import net.minecraft.server.v1_4_R1.TileEntityChest;
import net.minecraft.server.v1_4_R1.TileEntityEnderChest; import net.minecraft.server.v1_4_R1.TileEntityEnderChest;
import net.minecraft.server.v1_4_R1.World; import net.minecraft.server.v1_4_R1.World;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_4_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_4_R1.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override @Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) { public boolean isAnySilentContainer(@NotNull Block bukkitBlock) {
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest; return bukkitBlock.getType() == Material.ENDER_CHEST || bukkitBlock.getState() instanceof org.bukkit.block.Chest;
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) { public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull Block bukkitBlock) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = PlayerDataManager.getHandle(p); World world = PlayerDataManager.getHandle(bukkitPlayer).world;
World world = player.world;
if (block instanceof BlockEnderChest) { if (bukkitBlock instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots. // Ender chests are not blocked by ocelots.
return world.t(block.getX(), block.getY() + 1, block.getZ()); return world.t(bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
// If block or ocelot on top // If block or ocelot on top
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) { if (isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ())) {
return true; return true;
} }
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
// If block next to chest is chest and has a block or ocelot on top // If block next to chest is chest and has a block or ocelot on top
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() + 1);
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if(world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() - 1);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() + 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() - 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
return false; return false;
@@ -93,18 +91,18 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is API-only // Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
return true; return true;
} }
World world = player.world; World world = player.world;
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ()); Object tile = world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (tile == null) { if (tile == null) {
return false; return false;
@@ -123,20 +121,20 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
IInventory inventory = (IInventory) tile; IInventory inventory = (IInventory) tile;
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1));
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1), inventory);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()));
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()), inventory);
} }
// AnyChest only // AnyChest only
if (!silentchest) { if (!silent) {
player.openContainer(inventory); player.openContainer(inventory);
return true; return true;
} }
@@ -160,9 +158,12 @@ public class AnySilentContainer implements IAnySilentContainer {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container."); bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false; return false;
} }
} }
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_4_R1.IInventory; import net.minecraft.server.v1_4_R1.IInventory;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,45 +1,44 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_4_R1; package com.lishid.openinv.internal.v1_4_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_4_R1.EntityPlayer; import net.minecraft.server.v1_4_R1.EntityPlayer;
import net.minecraft.server.v1_4_R1.MinecraftServer; import net.minecraft.server.v1_4_R1.MinecraftServer;
import net.minecraft.server.v1_4_R1.PlayerInteractManager; import net.minecraft.server.v1_4_R1.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_4_R1.CraftServer; import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure the player has data // Ensure the player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -50,7 +49,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -60,12 +59,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getName(); return offline.getName();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
// Ensure player is a real player, otherwise return null // Ensure player is a real player, otherwise return null
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
@@ -75,7 +74,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Arrays.asList(Bukkit.getOnlinePlayers()); return Arrays.asList(Bukkit.getOnlinePlayers());
} }
@@ -99,4 +98,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -22,9 +22,9 @@ import net.minecraft.server.v1_4_R1.IInventory;
import net.minecraft.server.v1_4_R1.ItemStack; import net.minecraft.server.v1_4_R1.ItemStack;
import net.minecraft.server.v1_4_R1.PlayerInventory; import net.minecraft.server.v1_4_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest { class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2) { SilentContainerChest(IInventory i1, IInventory i2) {
super(i1, i2); super(i1, i2);
// Send close signal // Send close signal
i2.f(); i2.f();

View File

@@ -1,54 +1,52 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_4_R1; package com.lishid.openinv.internal.v1_4_R1;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_4_R1.EntityPlayer; import net.minecraft.server.v1_4_R1.EntityPlayer;
import net.minecraft.server.v1_4_R1.IInventory; import net.minecraft.server.v1_4_R1.IInventory;
import net.minecraft.server.v1_4_R1.InventoryEnderChest; import net.minecraft.server.v1_4_R1.InventoryEnderChest;
import net.minecraft.server.v1_4_R1.InventorySubcontainer; import net.minecraft.server.v1_4_R1.InventorySubcontainer;
import net.minecraft.server.v1_4_R1.ItemStack; 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.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>(); private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private boolean playerOnline = false; private boolean playerOnline;
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
public SpecialEnderChest(Player player, Boolean online) { public SpecialEnderChest(Player player, Boolean online) {
super(PlayerDataManager.getHandle(player).getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity(); this.owner = nmsPlayer.getBukkitEntity();
@@ -56,12 +54,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
@@ -70,7 +68,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); field.set(playerEnderChest, this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,20 +17,18 @@
package com.lishid.openinv.internal.v1_4_R1; package com.lishid.openinv.internal.v1_4_R1;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_4_R1.ItemStack; import net.minecraft.server.v1_4_R1.ItemStack;
import net.minecraft.server.v1_4_R1.PlayerInventory; import net.minecraft.server.v1_4_R1.PlayerInventory;
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -40,12 +38,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = PlayerDataManager.getHandle(player); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_5_R2</artifactId> <artifactId>openinvadapter1_5_R2</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,11 +17,6 @@
package com.lishid.openinv.internal.v1_5_R2; package com.lishid.openinv.internal.v1_5_R2;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_5_R2.AxisAlignedBB; import net.minecraft.server.v1_5_R2.AxisAlignedBB;
import net.minecraft.server.v1_5_R2.BlockEnderChest; import net.minecraft.server.v1_5_R2.BlockEnderChest;
import net.minecraft.server.v1_5_R2.Container; import net.minecraft.server.v1_5_R2.Container;
@@ -34,43 +29,46 @@ import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
import net.minecraft.server.v1_5_R2.TileEntityChest; import net.minecraft.server.v1_5_R2.TileEntityChest;
import net.minecraft.server.v1_5_R2.TileEntityEnderChest; import net.minecraft.server.v1_5_R2.TileEntityEnderChest;
import net.minecraft.server.v1_5_R2.World; import net.minecraft.server.v1_5_R2.World;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override @Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) { public boolean isAnySilentContainer(@NotNull Block bukkitBlock) {
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest; return bukkitBlock.getType() == Material.ENDER_CHEST || bukkitBlock.getState() instanceof org.bukkit.block.Chest;
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) { public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull Block bukkitBlock) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = PlayerDataManager.getHandle(p); World world = PlayerDataManager.getHandle(bukkitPlayer).world;
World world = player.world;
if (block instanceof BlockEnderChest) { if (bukkitBlock instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots. // Ender chests are not blocked by ocelots.
return world.t(block.getX(), block.getY() + 1, block.getZ()); return world.t(bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
// If block or ocelot on top // If block or ocelot on top
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) { if (isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ())) {
return true; return true;
} }
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
// If block next to chest is chest and has a block or ocelot on top // If block next to chest is chest and has a block or ocelot on top
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() + 1);
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if(world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() - 1);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() + 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() - 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
return false; return false;
@@ -93,18 +91,18 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is API-only // Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
return true; return true;
} }
World world = player.world; World world = player.world;
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ()); Object tile = world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (tile == null) { if (tile == null) {
return false; return false;
@@ -123,20 +121,20 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
IInventory inventory = (IInventory) tile; IInventory inventory = (IInventory) tile;
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1));
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1), inventory);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()));
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()), inventory);
} }
// AnyChest only // AnyChest only
if (!silentchest) { if (!silent) {
player.openContainer(inventory); player.openContainer(inventory);
return true; return true;
} }
@@ -160,9 +158,12 @@ public class AnySilentContainer implements IAnySilentContainer {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container."); bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false; return false;
} }
} }
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_5_R2.IInventory; import net.minecraft.server.v1_5_R2.IInventory;
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,44 +1,43 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_5_R2; package com.lishid.openinv.internal.v1_5_R2;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_5_R2.EntityPlayer; import net.minecraft.server.v1_5_R2.EntityPlayer;
import net.minecraft.server.v1_5_R2.MinecraftServer; import net.minecraft.server.v1_5_R2.MinecraftServer;
import net.minecraft.server.v1_5_R2.PlayerInteractManager; import net.minecraft.server.v1_5_R2.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_5_R2.CraftServer; import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure the player has data // Ensure the player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -49,7 +48,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -59,12 +58,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getName(); return offline.getName();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
// Ensure player is a real player, otherwise return null // Ensure player is a real player, otherwise return null
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
@@ -74,7 +73,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Arrays.asList(Bukkit.getOnlinePlayers()); return Arrays.asList(Bukkit.getOnlinePlayers());
} }
@@ -98,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -22,9 +22,9 @@ import net.minecraft.server.v1_5_R2.IInventory;
import net.minecraft.server.v1_5_R2.ItemStack; import net.minecraft.server.v1_5_R2.ItemStack;
import net.minecraft.server.v1_5_R2.PlayerInventory; import net.minecraft.server.v1_5_R2.PlayerInventory;
public class SilentContainerChest extends ContainerChest { class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2) { SilentContainerChest(IInventory i1, IInventory i2) {
super(i1, i2); super(i1, i2);
// Send close signal // Send close signal
i2.g(); i2.g();

View File

@@ -1,48 +1,45 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_5_R2; package com.lishid.openinv.internal.v1_5_R2;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_5_R2.EntityPlayer; import net.minecraft.server.v1_5_R2.EntityPlayer;
import net.minecraft.server.v1_5_R2.IInventory; import net.minecraft.server.v1_5_R2.IInventory;
import net.minecraft.server.v1_5_R2.InventoryEnderChest; import net.minecraft.server.v1_5_R2.InventoryEnderChest;
import net.minecraft.server.v1_5_R2.InventorySubcontainer; import net.minecraft.server.v1_5_R2.InventorySubcontainer;
import net.minecraft.server.v1_5_R2.ItemStack; 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.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>(); private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private boolean playerOnline = false; private boolean playerOnline;
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
@@ -50,6 +47,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
super(PlayerDataManager.getHandle(player).getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity(); this.owner = nmsPlayer.getBukkitEntity();
@@ -57,12 +55,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
@@ -71,7 +69,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); field.set(playerEnderChest, this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,20 +17,18 @@
package com.lishid.openinv.internal.v1_5_R2; package com.lishid.openinv.internal.v1_5_R2;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_5_R2.ItemStack; import net.minecraft.server.v1_5_R2.ItemStack;
import net.minecraft.server.v1_5_R2.PlayerInventory; import net.minecraft.server.v1_5_R2.PlayerInventory;
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -40,12 +38,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = PlayerDataManager.getHandle(player); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_5_R3</artifactId> <artifactId>openinvadapter1_5_R3</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,11 +17,6 @@
package com.lishid.openinv.internal.v1_5_R3; package com.lishid.openinv.internal.v1_5_R3;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_5_R3.AxisAlignedBB; import net.minecraft.server.v1_5_R3.AxisAlignedBB;
import net.minecraft.server.v1_5_R3.BlockEnderChest; import net.minecraft.server.v1_5_R3.BlockEnderChest;
import net.minecraft.server.v1_5_R3.Container; import net.minecraft.server.v1_5_R3.Container;
@@ -34,43 +29,46 @@ import net.minecraft.server.v1_5_R3.Packet100OpenWindow;
import net.minecraft.server.v1_5_R3.TileEntityChest; import net.minecraft.server.v1_5_R3.TileEntityChest;
import net.minecraft.server.v1_5_R3.TileEntityEnderChest; import net.minecraft.server.v1_5_R3.TileEntityEnderChest;
import net.minecraft.server.v1_5_R3.World; import net.minecraft.server.v1_5_R3.World;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override @Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) { public boolean isAnySilentContainer(@NotNull Block bukkitBlock) {
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest; return bukkitBlock.getType() == Material.ENDER_CHEST || bukkitBlock.getState() instanceof org.bukkit.block.Chest;
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) { public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull Block bukkitBlock) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = PlayerDataManager.getHandle(p); World world = PlayerDataManager.getHandle(bukkitPlayer).world;
World world = player.world;
if (block instanceof BlockEnderChest) { if (bukkitBlock instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots. // Ender chests are not blocked by ocelots.
return world.t(block.getX(), block.getY() + 1, block.getZ()); return world.t(bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
// If block or ocelot on top // If block or ocelot on top
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) { if (isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ())) {
return true; return true;
} }
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
// If block next to chest is chest and has a block or ocelot on top // If block next to chest is chest and has a block or ocelot on top
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() + 1);
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if(world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() - 1);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() + 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() - 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
return false; return false;
@@ -93,18 +91,18 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is API-only // Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
return true; return true;
} }
World world = player.world; World world = player.world;
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ()); Object tile = world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (tile == null) { if (tile == null) {
return false; return false;
@@ -123,20 +121,20 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
IInventory inventory = (IInventory) tile; IInventory inventory = (IInventory) tile;
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1));
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1), inventory);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()));
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()), inventory);
} }
// AnyChest only // AnyChest only
if (!silentchest) { if (!silent) {
player.openContainer(inventory); player.openContainer(inventory);
return true; return true;
} }
@@ -160,9 +158,12 @@ public class AnySilentContainer implements IAnySilentContainer {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container."); bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false; return false;
} }
} }
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_5_R3.IInventory; import net.minecraft.server.v1_5_R3.IInventory;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,44 +1,43 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_5_R3; package com.lishid.openinv.internal.v1_5_R3;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_5_R3.EntityPlayer; import net.minecraft.server.v1_5_R3.EntityPlayer;
import net.minecraft.server.v1_5_R3.MinecraftServer; import net.minecraft.server.v1_5_R3.MinecraftServer;
import net.minecraft.server.v1_5_R3.PlayerInteractManager; import net.minecraft.server.v1_5_R3.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_5_R3.CraftServer; import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure the player has data // Ensure the player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -49,7 +48,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -59,12 +58,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getName(); return offline.getName();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
// Ensure player is a real player, otherwise return null // Ensure player is a real player, otherwise return null
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
@@ -74,7 +73,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Arrays.asList(Bukkit.getOnlinePlayers()); return Arrays.asList(Bukkit.getOnlinePlayers());
} }
@@ -98,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -22,9 +22,9 @@ import net.minecraft.server.v1_5_R3.IInventory;
import net.minecraft.server.v1_5_R3.ItemStack; import net.minecraft.server.v1_5_R3.ItemStack;
import net.minecraft.server.v1_5_R3.PlayerInventory; import net.minecraft.server.v1_5_R3.PlayerInventory;
public class SilentContainerChest extends ContainerChest { public IInventory inv; class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2) { SilentContainerChest(IInventory i1, IInventory i2) {
super(i1, i2); super(i1, i2);
// Send close signal // Send close signal
i2.g(); i2.g();

View File

@@ -1,48 +1,45 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_5_R3; package com.lishid.openinv.internal.v1_5_R3;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_5_R3.EntityPlayer; import net.minecraft.server.v1_5_R3.EntityPlayer;
import net.minecraft.server.v1_5_R3.IInventory; import net.minecraft.server.v1_5_R3.IInventory;
import net.minecraft.server.v1_5_R3.InventoryEnderChest; import net.minecraft.server.v1_5_R3.InventoryEnderChest;
import net.minecraft.server.v1_5_R3.InventorySubcontainer; import net.minecraft.server.v1_5_R3.InventorySubcontainer;
import net.minecraft.server.v1_5_R3.ItemStack; 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.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>(); private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private boolean playerOnline = false; private boolean playerOnline;
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
@@ -50,6 +47,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
super(PlayerDataManager.getHandle(player).getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity(); this.owner = nmsPlayer.getBukkitEntity();
@@ -57,12 +55,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
@@ -71,7 +69,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); field.set(playerEnderChest, this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,20 +17,18 @@
package com.lishid.openinv.internal.v1_5_R3; package com.lishid.openinv.internal.v1_5_R3;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_5_R3.ItemStack; import net.minecraft.server.v1_5_R3.ItemStack;
import net.minecraft.server.v1_5_R3.PlayerInventory; import net.minecraft.server.v1_5_R3.PlayerInventory;
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
private final ItemStack[] extra = new ItemStack[5]; private final ItemStack[] extra = new ItemStack[5];
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private boolean playerOnline = false; private boolean playerOnline;
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
super(PlayerDataManager.getHandle(bukkitPlayer)); super(PlayerDataManager.getHandle(bukkitPlayer));
@@ -40,12 +38,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
this.player = PlayerDataManager.getHandle(player); this.player = PlayerDataManager.getHandle(player);
this.player.inventory.items = this.items; this.player.inventory.items = this.items;

View File

@@ -1,3 +1,19 @@
<!--
~ Copyright (C) 2011-2018 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 <http://www.gnu.org/licenses/>.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,7 +21,7 @@
<parent> <parent>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId> <artifactId>openinvinternal</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</parent> </parent>
<artifactId>openinvadapter1_6_R1</artifactId> <artifactId>openinvadapter1_6_R1</artifactId>
@@ -21,7 +37,7 @@
<dependency> <dependency>
<groupId>com.lishid</groupId> <groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId> <artifactId>openinvcommon</artifactId>
<version>3.2.0</version> <version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -17,11 +17,6 @@
package com.lishid.openinv.internal.v1_6_R1; package com.lishid.openinv.internal.v1_6_R1;
import com.lishid.openinv.internal.IAnySilentContainer; import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_6_R1.AxisAlignedBB; import net.minecraft.server.v1_6_R1.AxisAlignedBB;
import net.minecraft.server.v1_6_R1.BlockEnderChest; import net.minecraft.server.v1_6_R1.BlockEnderChest;
import net.minecraft.server.v1_6_R1.Container; import net.minecraft.server.v1_6_R1.Container;
@@ -34,43 +29,46 @@ import net.minecraft.server.v1_6_R1.Packet100OpenWindow;
import net.minecraft.server.v1_6_R1.TileEntityChest; import net.minecraft.server.v1_6_R1.TileEntityChest;
import net.minecraft.server.v1_6_R1.TileEntityEnderChest; import net.minecraft.server.v1_6_R1.TileEntityEnderChest;
import net.minecraft.server.v1_6_R1.World; import net.minecraft.server.v1_6_R1.World;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_6_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_6_R1.event.CraftEventFactory;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class AnySilentContainer implements IAnySilentContainer { public class AnySilentContainer implements IAnySilentContainer {
@Override @Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) { public boolean isAnySilentContainer(@NotNull Block bukkitBlock) {
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest; return bukkitBlock.getType() == Material.ENDER_CHEST || bukkitBlock.getState() instanceof org.bukkit.block.Chest;
} }
@Override @Override
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) { public boolean isAnyContainerNeeded(@NotNull Player bukkitPlayer, @NotNull Block bukkitBlock) {
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = PlayerDataManager.getHandle(p); World world = PlayerDataManager.getHandle(bukkitPlayer).world;
World world = player.world;
if (block instanceof BlockEnderChest) { if (bukkitBlock instanceof BlockEnderChest) {
// Ender chests are not blocked by ocelots. // Ender chests are not blocked by ocelots.
return world.t(block.getX(), block.getY() + 1, block.getZ()); return world.t(bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
// If block or ocelot on top // If block or ocelot on top
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) { if (isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ())) {
return true; return true;
} }
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
// If block next to chest is chest and has a block or ocelot on top // If block next to chest is chest and has a block or ocelot on top
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() + 1);
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if(world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1); return isBlockedChest(world, bukkitBlock.getX(), bukkitBlock.getY() + 1, bukkitBlock.getZ() - 1);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() + 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ()); return isBlockedChest(world, bukkitBlock.getX() - 1, bukkitBlock.getY() + 1, bukkitBlock.getZ());
} }
return false; return false;
@@ -93,18 +91,18 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
@Override @Override
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) { public boolean activateContainer(@NotNull Player bukkitPlayer, boolean silent, @NotNull Block bukkitBlock) {
EntityPlayer player = PlayerDataManager.getHandle(p); EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
// Silent ender chest is API-only // Silent ender chest is API-only
if (silentchest && block.getType() == Material.ENDER_CHEST) { if (silent && bukkitBlock.getType() == Material.ENDER_CHEST) {
p.openInventory(p.getEnderChest()); bukkitPlayer.openInventory(bukkitPlayer.getEnderChest());
return true; return true;
} }
World world = player.world; World world = player.world;
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ()); Object tile = world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (tile == null) { if (tile == null) {
return false; return false;
@@ -123,20 +121,20 @@ public class AnySilentContainer implements IAnySilentContainer {
} }
IInventory inventory = (IInventory) tile; IInventory inventory = (IInventory) tile;
int id = world.getTypeId(block.getX(), block.getY(), block.getZ()); int id = world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) { if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1)); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() + 1));
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) { } else if (world.getTypeId(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ() - 1), inventory);
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ())); inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(bukkitBlock.getX() + 1, bukkitBlock.getY(), bukkitBlock.getZ()));
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) { } else if (world.getTypeId(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()) == id) {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory); inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(bukkitBlock.getX() - 1, bukkitBlock.getY(), bukkitBlock.getZ()), inventory);
} }
// AnyChest only // AnyChest only
if (!silentchest) { if (!silent) {
player.openContainer(inventory); player.openContainer(inventory);
return true; return true;
} }
@@ -160,9 +158,12 @@ public class AnySilentContainer implements IAnySilentContainer {
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container."); bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false; return false;
} }
} }
@Override
public void deactivateContainer(@NotNull final Player bukkitPlayer) {}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -20,17 +20,15 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest; import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.InternalAccessor; import com.lishid.openinv.util.InternalAccessor;
import org.bukkit.inventory.Inventory;
import net.minecraft.server.v1_6_R1.IInventory; import net.minecraft.server.v1_6_R1.IInventory;
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
@Override @Override
public boolean isSpecialPlayerInventory(Inventory inventory) { public boolean isSpecialPlayerInventory(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory; return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
} }
@@ -38,7 +36,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) { public ISpecialPlayerInventory getSpecialPlayerInventory(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();
@@ -53,7 +51,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public boolean isSpecialEnderChest(Inventory inventory) { public boolean isSpecialEnderChest(@NotNull Inventory inventory) {
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest; return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
} }
@@ -61,7 +59,7 @@ public class InventoryAccess implements IInventoryAccess {
} }
@Override @Override
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) { public ISpecialEnderChest getSpecialEnderChest(@NotNull Inventory inventory) {
IInventory inv; IInventory inv;
if (inventory instanceof CraftInventory) { if (inventory instanceof CraftInventory) {
inv = ((CraftInventory) inventory).getInventory(); inv = ((CraftInventory) inventory).getInventory();

View File

@@ -1,44 +1,43 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_6_R1; package com.lishid.openinv.internal.v1_6_R1;
import com.lishid.openinv.internal.IPlayerDataManager;
import com.lishid.openinv.internal.ISpecialInventory;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import com.lishid.openinv.internal.IPlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_6_R1.EntityPlayer; import net.minecraft.server.v1_6_R1.EntityPlayer;
import net.minecraft.server.v1_6_R1.MinecraftServer; import net.minecraft.server.v1_6_R1.MinecraftServer;
import net.minecraft.server.v1_6_R1.PlayerInteractManager; import net.minecraft.server.v1_6_R1.PlayerInteractManager;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.craftbukkit.v1_6_R1.CraftServer; import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class PlayerDataManager implements IPlayerDataManager { public class PlayerDataManager implements IPlayerDataManager {
@Override @Override
public Player loadPlayer(OfflinePlayer offline) { public Player loadPlayer(@NotNull OfflinePlayer offline) {
// Ensure the player has data // Ensure the player has data
if (offline == null || !offline.hasPlayedBefore()) { if (!offline.hasPlayedBefore()) {
return null; return null;
} }
@@ -49,7 +48,7 @@ public class PlayerDataManager implements IPlayerDataManager {
new PlayerInteractManager(server.getWorldServer(0))); new PlayerInteractManager(server.getWorldServer(0)));
// Get the bukkit entity // Get the bukkit entity
Player target = (entity == null) ? null : entity.getBukkitEntity(); Player target = entity.getBukkitEntity();
if (target != null) { if (target != null) {
// Load data // Load data
target.loadData(); target.loadData();
@@ -59,12 +58,12 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public String getPlayerDataID(OfflinePlayer player) { public @NotNull String getPlayerDataID(@NotNull OfflinePlayer offline) {
return player.getName(); return offline.getName();
} }
@Override @Override
public OfflinePlayer getPlayerByID(String identifier) { public OfflinePlayer getPlayerByID(@NotNull String identifier) {
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier); OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
// Ensure player is a real player, otherwise return null // Ensure player is a real player, otherwise return null
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) { if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
@@ -74,7 +73,7 @@ public class PlayerDataManager implements IPlayerDataManager {
} }
@Override @Override
public Collection<? extends Player> getOnlinePlayers() { public @NotNull Collection<? extends Player> getOnlinePlayers() {
return Arrays.asList(Bukkit.getOnlinePlayers()); return Arrays.asList(Bukkit.getOnlinePlayers());
} }
@@ -98,4 +97,9 @@ public class PlayerDataManager implements IPlayerDataManager {
return nmsPlayer; return nmsPlayer;
} }
@Override
public InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
return player.openInventory(inventory.getBukkitInventory());
}
} }

View File

@@ -1,15 +1,15 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@@ -22,9 +22,9 @@ import net.minecraft.server.v1_6_R1.IInventory;
import net.minecraft.server.v1_6_R1.ItemStack; import net.minecraft.server.v1_6_R1.ItemStack;
import net.minecraft.server.v1_6_R1.PlayerInventory; import net.minecraft.server.v1_6_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest { class SilentContainerChest extends ContainerChest {
public SilentContainerChest(IInventory i1, IInventory i2) { SilentContainerChest(IInventory i1, IInventory i2) {
super(i1, i2); super(i1, i2);
// Send close signal // Send close signal
i2.g(); i2.g();

View File

@@ -1,48 +1,45 @@
/* /*
* Copyright (C) 2011-2014 lishid. All rights reserved. * Copyright (C) 2011-2018 lishid. All rights reserved.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3. * the Free Software Foundation, version 3.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.lishid.openinv.internal.v1_6_R1; package com.lishid.openinv.internal.v1_6_R1;
import com.lishid.openinv.internal.ISpecialEnderChest;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.lishid.openinv.internal.ISpecialEnderChest;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import net.minecraft.server.v1_6_R1.EntityPlayer; import net.minecraft.server.v1_6_R1.EntityPlayer;
import net.minecraft.server.v1_6_R1.IInventory; import net.minecraft.server.v1_6_R1.IInventory;
import net.minecraft.server.v1_6_R1.InventoryEnderChest; import net.minecraft.server.v1_6_R1.InventoryEnderChest;
import net.minecraft.server.v1_6_R1.InventorySubcontainer; import net.minecraft.server.v1_6_R1.InventorySubcontainer;
import net.minecraft.server.v1_6_R1.ItemStack; 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.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
private final InventoryEnderChest enderChest; private final InventoryEnderChest enderChest;
private final CraftInventory inventory = new CraftInventory(this); private final CraftInventory inventory = new CraftInventory(this);
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>(); private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
private boolean playerOnline = false; private boolean playerOnline;
private CraftPlayer owner; private CraftPlayer owner;
private int maxStack = MAX_STACK; private int maxStack = MAX_STACK;
@@ -50,6 +47,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
super(PlayerDataManager.getHandle(player).getEnderChest().getName(), super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
PlayerDataManager.getHandle(player).getEnderChest().c(), PlayerDataManager.getHandle(player).getEnderChest().c(),
PlayerDataManager.getHandle(player).getEnderChest().getSize()); PlayerDataManager.getHandle(player).getEnderChest().getSize());
this.playerOnline = online;
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
this.enderChest = nmsPlayer.getEnderChest(); this.enderChest = nmsPlayer.getEnderChest();
this.owner = nmsPlayer.getBukkitEntity(); this.owner = nmsPlayer.getBukkitEntity();
@@ -57,12 +55,12 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
} }
@Override @Override
public Inventory getBukkitInventory() { public @NotNull Inventory getBukkitInventory() {
return inventory; return inventory;
} }
@Override @Override
public void setPlayerOnline(Player player) { public void setPlayerOnline(@NotNull Player player) {
if (!playerOnline) { if (!playerOnline) {
try { try {
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player); EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
@@ -71,7 +69,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
Field field = playerEnderChest.getClass().getField("items"); Field field = playerEnderChest.getClass().getField("items");
field.setAccessible(true); field.setAccessible(true);
field.set(playerEnderChest, this.items); field.set(playerEnderChest, this.items);
} catch (Exception e) {} } catch (Exception ignored) {}
playerOnline = true; playerOnline = true;
} }
} }

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