Compare commits
134 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f07cef5621 | ||
|
ded6421e33 | ||
|
cbb2b4d232 | ||
|
48c61eeb82 | ||
|
e3d1af010b | ||
|
2195677651 | ||
|
c72af5dbac | ||
|
931cdb6fb1 | ||
|
9db18613a1 | ||
|
784935a975 | ||
|
d9abe76531 | ||
|
ca85a392aa | ||
|
307f47e4d3 | ||
|
96c59f163d | ||
|
01f147b13c | ||
|
1c104b775f | ||
|
9a53e46dd3 | ||
|
6744e71127 | ||
|
12c3ebb798 | ||
|
32ec8d8147 | ||
|
443e0c489e | ||
|
7ab0003b62 | ||
|
12c0cac311 | ||
|
f54481e872 | ||
|
f27dd8a233 | ||
|
d6df1a0871 | ||
|
e34e51d127 | ||
|
5ca2ae461a | ||
|
4095e8039d | ||
|
73f390ab20 | ||
|
2f7d3bc235 | ||
|
ef486032f1 | ||
|
72ef873772 | ||
|
9b6e32a775 | ||
|
f05110c9b8 | ||
|
a41f89b011 | ||
|
d24827ffcb | ||
|
802ce28103 | ||
|
f31356b227 | ||
|
7942466863 | ||
|
db2cade4e2 | ||
|
718b4bb5dd | ||
|
6aa25dd2dc | ||
|
0bbcf6cdb2 | ||
|
f11d60f78c | ||
|
8a6b98614f | ||
|
d7eec528e4 | ||
|
a10c61168a | ||
|
5c4886c66b | ||
|
4335b8dc2c | ||
|
3bf7225712 | ||
|
b76440ab9a | ||
|
3152605bca | ||
|
eaabd30dc2 | ||
|
de0d28b12d | ||
|
c3a8bc9486 | ||
|
5b77404597 | ||
|
d9c1b00b50 | ||
|
2fc439b306 | ||
|
2cb1b01fbf | ||
|
d16cca9847 | ||
|
e39f009661 | ||
|
1d622b653d | ||
|
582a958195 | ||
|
9245b4cc27 | ||
|
ba9396ad5c | ||
|
27de16cba9 | ||
|
90ea073089 | ||
|
4811e53d12 | ||
|
c7f38adb3f | ||
|
99a7359be3 | ||
|
d42cc3e275 | ||
|
b8f4589b87 | ||
|
f9ac6804b2 | ||
|
62f5d54676 | ||
|
8feca3fb21 | ||
|
7b16140ee1 | ||
|
14ec280d26 | ||
|
71ac05ae85 | ||
|
c4a9cb0a4a | ||
|
7ae87d1dbe | ||
|
346036b7e7 | ||
|
69c355c8cd | ||
|
8dbbe80dbf | ||
|
77e6ce8c7c | ||
|
cd405a9b9e | ||
|
b5d6cf047c | ||
|
aaa9c4e190 | ||
|
6ea09dc964 | ||
|
eace5ca8fb | ||
|
03308be7f5 | ||
|
4f40459b96 | ||
|
791368b100 | ||
|
5dd3f5bbd7 | ||
|
d1d60e55d5 | ||
|
471b631838 | ||
|
2f1fd87435 | ||
|
a03c73f8d6 | ||
|
f7029e5ee2 | ||
|
802e405c4e | ||
|
55deabe56b | ||
|
f8e4e69e53 | ||
|
3c7d1696ff | ||
|
902def1dd7 | ||
|
f260ed1175 | ||
|
bc40e91215 | ||
|
120b35d394 | ||
|
ded568ec3f | ||
|
e958059572 | ||
|
d988becf1f | ||
|
e8476d5b05 | ||
|
1ea0307156 | ||
|
4ae47b09dc | ||
|
3e9bb63894 | ||
|
dce86d9c69 | ||
|
4013098201 | ||
|
56f633d58b | ||
|
6c1fb14cda | ||
|
ad0e55cf4c | ||
|
c4fb5489fa | ||
|
3d3006c681 | ||
|
a9d983ddc6 | ||
|
f6554a2a51 | ||
|
ec3426b827 | ||
|
d0494aa2e7 | ||
|
6adcd491db | ||
|
bc709336e1 | ||
|
7d56a04283 | ||
|
7851404d69 | ||
|
30b5acc3b4 | ||
|
29b0bc980f | ||
|
b05279ed4b | ||
|
88f3cb0a3f | ||
|
f48fdac085 |
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
**/.settings
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.classpath
|
||||
**/.idea
|
||||
**/.iml
|
||||
**/target
|
||||
**/bin
|
||||
**/out
|
||||
**dependency-reduced-pom.xml
|
||||
**pom.xml.versionsBackup
|
@@ -1,3 +0,0 @@
|
||||
#Wed Jun 01 17:38:54 EDT 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
|
13
README
13
README
@@ -1,13 +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/>.
|
156
README.MD
Normal file
156
README.MD
Normal file
@@ -0,0 +1,156 @@
|
||||
## About
|
||||
OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) which allows users to open and edit anyone's inventory or ender chest - online or not!
|
||||
|
||||
## Features
|
||||
- **OpenInv**: Open anyone's inventory, even if they're offline.
|
||||
- Read-only mode! No edits allowed! Don't grant the permission `OpenInv.editinv`
|
||||
- Cross-world support! Don't grant `OpenInv.crossworld`
|
||||
- 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
|
||||
- **OpenEnder**: Open anyone's inventory, even if they're offline.
|
||||
- Read-only mode! No edits allowed! Don't grant `OpenInv.editender`
|
||||
- Cross-world support! Don't grant `OpenInv.crossworld`
|
||||
- No opening others! Don't grant `OpenInv.openenderall`
|
||||
- **SilentContainer**: Open containers without displaying an animation or making sound.
|
||||
- **AnyContainer**: Open containers, even if blocked by ocelots or blocks.
|
||||
|
||||
## Commands
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<th width=175px>Command</th>
|
||||
<th>Aliases</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/openinv [player]</td>
|
||||
<td>oi, inv, open</td>
|
||||
<td>Open a player's inventory. If unspecified, will select last player opened or own if none opened previously.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/openender [player]</td>
|
||||
<td>oe</td>
|
||||
<td>Open a player's ender chest. If unspecified, will select last player opened or own if none opened previously.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/searchinv <item> [minAmount]</td>
|
||||
<td>si</td>
|
||||
<td>Lists all online players that have a certain item in their inventory.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/searchender <item> [minAmount]</td>
|
||||
<td>se</td>
|
||||
<td>Lists all online players that have a certain item in their ender chest.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/searchenchant <[enchantment] [MinLevel]></td>
|
||||
<td>searchenchants</td>
|
||||
<td>Lists all online players with a specific enchantment.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>/anycontainer [check]</td>
|
||||
<td>ac, anychest</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>
|
||||
</table>
|
||||
|
||||
## Permissions
|
||||
<table>
|
||||
<tr>
|
||||
<th>Node</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.*</td>
|
||||
<td>Gives permission to use all of OpenInv.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openinv</td>
|
||||
<td>Required to use /openinv.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openself</td>
|
||||
<td>Required to open own inventory.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.editinv</td>
|
||||
<td>Required to make changes to open inventories.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openender</td>
|
||||
<td>Required to use /openender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.editender</td>
|
||||
<td>Required to make changes to open ender chests.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.openenderall</td>
|
||||
<td>Allows users to open others' ender chests. Without it, users can only open their own.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.exempt</td>
|
||||
<td>Prevents the player's inventory being opened by others.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.override</td>
|
||||
<td>Allows bypassing of the exempt permission.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.crossworld</td>
|
||||
<td>Allows cross-world usage of /openinv and /openender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.search</td>
|
||||
<td>Required to use /searchinv and /searchender.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.searchenchant</td>
|
||||
<td>Required to use /searchenchant.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.anychest</td>
|
||||
<td>Required to use /anychest.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.any.default</td>
|
||||
<td>Cause AnyContainer to be enabled by default.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.silent</td>
|
||||
<td>Required to use /silentcontainer.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>OpenInv.silent.default</td>
|
||||
<td>Cause SilentContainer to be enabled by default.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## For Developers
|
||||
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`
|
||||
|
||||
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).
|
||||
|
||||
The final file is target/OpenInv.jar
|
||||
|
||||
## License
|
||||
```
|
||||
Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
```
|
24
api/pom.xml
Normal file
24
api/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<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>openinvparent</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvapi</artifactId>
|
||||
<name>OpenInvAPI</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.5-R1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../lib/bukkit-1.4.5-R1.0.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
234
api/src/main/java/com/lishid/openinv/IOpenInv.java
Normal file
234
api/src/main/java/com/lishid/openinv/IOpenInv.java
Normal file
@@ -0,0 +1,234 @@
|
||||
package com.lishid.openinv;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Interface defining behavior for the OpenInv plugin.
|
||||
*
|
||||
* @author Jikoo
|
||||
*/
|
||||
public interface IOpenInv {
|
||||
|
||||
/**
|
||||
* Check the configuration value for whether or not OpenInv saves player data when unloading
|
||||
* players. This is exclusively for users who do not allow editing of inventories, only viewing,
|
||||
* and wish to prevent any possibility of bugs such as lishid#40. If true, OpenInv will not ever
|
||||
* save any edits made to players.
|
||||
*
|
||||
* @return false unless configured otherwise
|
||||
*/
|
||||
public boolean disableSaving();
|
||||
|
||||
/**
|
||||
* Gets the active ISilentContainer implementation. May return null if the server version is
|
||||
* unsupported.
|
||||
*
|
||||
* @return the ISilentContainer
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public IAnySilentContainer getAnySilentContainer();
|
||||
|
||||
/**
|
||||
* Gets an ISpecialEnderChest for the given Player. Returns null if the ISpecialEnderChest could
|
||||
* 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
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public IInventoryAccess getInventoryAccess();
|
||||
|
||||
/**
|
||||
* Gets the provided player's AnyChest setting.
|
||||
*
|
||||
* @param player the OfflinePlayer
|
||||
* @return true if AnyChest is enabled
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public boolean getPlayerAnyChestStatus(OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* Gets a unique identifier by which the OfflinePlayer can be referenced. Using the value
|
||||
* returned to look up a Player will generally be much faster for later implementations.
|
||||
*
|
||||
* @param offline the OfflinePlayer
|
||||
* @return the identifier
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public String getPlayerID(OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Gets a player's SilentChest setting.
|
||||
*
|
||||
* @param player the OfflinePlayer
|
||||
* @return true if SilentChest is enabled
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public boolean getPlayerSilentChestStatus(OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* Gets an ISpecialEnderChest for the given Player.
|
||||
*
|
||||
* @param player the Player
|
||||
* @param online true if the Player is currently online
|
||||
* @return the ISpecialEnderChest
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
* @throws InstantiationException if the ISpecialEnderChest could not be instantiated
|
||||
*/
|
||||
public ISpecialEnderChest getSpecialEnderChest(Player player, boolean online) throws InstantiationException;
|
||||
|
||||
/**
|
||||
* Gets an ISpecialPlayerInventory for the given Player.
|
||||
*
|
||||
* @param player the Player
|
||||
* @param online true if the Player is currently online
|
||||
* @return the ISpecialPlayerInventory
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
* @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated
|
||||
*/
|
||||
public ISpecialPlayerInventory getSpecialInventory(Player player, boolean online) throws InstantiationException;
|
||||
|
||||
/**
|
||||
* Checks if the server version is supported by OpenInv.
|
||||
*
|
||||
* @return true if the server version is supported
|
||||
*/
|
||||
public boolean isSupportedVersion();
|
||||
|
||||
/**
|
||||
* Load a Player from an OfflinePlayer. May return null under some circumstances.
|
||||
*
|
||||
* @param offline the OfflinePlayer to load a Player for
|
||||
* @return the Player, or null
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
@Nullable
|
||||
public Player loadPlayer(final OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Get an OfflinePlayer by name.
|
||||
* <p>
|
||||
* Note: This method is potentially very heavily blocking. It should not ever be called on the
|
||||
* main thread, and if it is, a stack trace will be displayed alerting server owners to the
|
||||
* call.
|
||||
*
|
||||
* @param name the name of the Player
|
||||
* @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
|
||||
*/
|
||||
@Nullable
|
||||
public OfflinePlayer matchPlayer(String name);
|
||||
|
||||
/**
|
||||
* Check the configuration value for whether or not OpenInv displays a notification to the user
|
||||
* when a container is activated with AnyChest.
|
||||
*
|
||||
* @return true unless configured otherwise
|
||||
*/
|
||||
public boolean notifyAnyChest();
|
||||
|
||||
/**
|
||||
* Check the configuration value for whether or not OpenInv displays a notification to the user
|
||||
* when a container is activated with SilentChest.
|
||||
*
|
||||
* @return true unless configured otherwise
|
||||
*/
|
||||
public boolean notifySilentChest();
|
||||
|
||||
/**
|
||||
* Mark a Player as no longer in use by a Plugin to allow OpenInv to remove it from the cache
|
||||
* when eligible.
|
||||
*
|
||||
* @param player the Player
|
||||
* @param plugin the Plugin no longer holding a reference to the Player
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public void releasePlayer(Player player, Plugin plugin);
|
||||
|
||||
/**
|
||||
* Mark a Player as in use by a Plugin to prevent it from being removed from the cache. Used to
|
||||
* prevent issues with multiple copies of the same Player being loaded such as lishid#49.
|
||||
* Changes made to loaded copies overwrite changes to the others when saved, leading to
|
||||
* duplication bugs and more.
|
||||
* <p>
|
||||
* When finished with the Player object, be sure to call {@link #releasePlayer(Player, Plugin)}
|
||||
* to prevent the cache from keeping it stored until the plugin is disabled.
|
||||
* <p>
|
||||
* When using a Player object from OpenInv, you must handle the Player coming online, replacing
|
||||
* your Player reference with the Player from the PlayerJoinEvent. In addition, you must change
|
||||
* any values in the Player to reflect any unsaved alterations to the existing Player which do
|
||||
* not affect the inventory or ender chest contents.
|
||||
* <p>
|
||||
* OpenInv only saves player data when unloading a Player from the cache, and then only if
|
||||
* {@link #disableSaving()} returns false. If you are making changes that OpenInv does not cause
|
||||
* to persist when a Player logs in as noted above, it is suggested that you manually call
|
||||
* {@link Player#saveData()} when releasing your reference to ensure your changes persist.
|
||||
*
|
||||
* @param player the Player
|
||||
* @param plugin the Plugin holding the reference to the Player
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public void retainPlayer(Player player, Plugin plugin);
|
||||
|
||||
/**
|
||||
* Sets a player's AnyChest setting.
|
||||
*
|
||||
* @param player the OfflinePlayer
|
||||
* @param status the status
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status);
|
||||
|
||||
/**
|
||||
* Sets a player's SilentChest setting.
|
||||
*
|
||||
* @param player the OfflinePlayer
|
||||
* @param status the status
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status);
|
||||
|
||||
/**
|
||||
* Forcibly unload a cached Player's data.
|
||||
*
|
||||
* @param player the OfflinePlayer to unload
|
||||
* @throws IllegalStateException if the server version is unsupported
|
||||
*/
|
||||
public void unload(OfflinePlayer player);
|
||||
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IAnySilentContainer {
|
||||
|
||||
/**
|
||||
* 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)}
|
||||
* first.
|
||||
*
|
||||
* @param player the Player opening the container
|
||||
* @param silentchest whether the container's noise is to be silenced
|
||||
* @param block the Block
|
||||
* @return true if the container can be opened
|
||||
*/
|
||||
public boolean activateContainer(Player player, boolean silentchest, Block block);
|
||||
|
||||
/**
|
||||
* Closes the Player's currently open container silently, if necessary.
|
||||
*
|
||||
* @param player the Player closing a container
|
||||
*/
|
||||
public void deactivateContainer(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
|
||||
*/
|
||||
public boolean isAnyContainerNeeded(Player player, 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
|
||||
*/
|
||||
public boolean isAnySilentContainer(Block block);
|
||||
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface IInventoryAccess {
|
||||
|
||||
/**
|
||||
* Gets an ISpecialEnderChest from an Inventory or null if the Inventory is not backed by an
|
||||
* ISpecialEnderChest.
|
||||
*
|
||||
* @param inventory the Inventory
|
||||
* @return the ISpecialEnderChest or null
|
||||
*/
|
||||
@Nullable
|
||||
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory);
|
||||
|
||||
/**
|
||||
* Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
|
||||
* an ISpecialPlayerInventory.
|
||||
*
|
||||
* @param inventory the Inventory
|
||||
* @return the ISpecialPlayerInventory or null
|
||||
*/
|
||||
@Nullable
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory);
|
||||
|
||||
/**
|
||||
* Check if an Inventory is an ISpecialEnderChest implementation.
|
||||
*
|
||||
* @param inventory the Inventory
|
||||
* @return true if the Inventory is backed by an ISpecialEnderChest
|
||||
*/
|
||||
public boolean isSpecialEnderChest(Inventory inventory);
|
||||
|
||||
/**
|
||||
* Check if an Inventory is an ISpecialPlayerInventory implementation.
|
||||
*
|
||||
* @param inventory the Inventory
|
||||
* @return true if the Inventory is backed by an ISpecialPlayerInventory
|
||||
*/
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory);
|
||||
|
||||
}
|
@@ -1,31 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface ISpecialEnderChest {
|
||||
public Inventory getBukkitInventory();
|
||||
|
||||
public void InventoryRemovalCheck();
|
||||
|
||||
public void PlayerGoOnline(Player p);
|
||||
|
||||
public void PlayerGoOffline();
|
||||
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
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();
|
||||
|
||||
}
|
@@ -1,30 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface ISpecialPlayerInventory {
|
||||
public Inventory getBukkitInventory();
|
||||
|
||||
public void InventoryRemovalCheck();
|
||||
|
||||
public void PlayerGoOnline(Player p);
|
||||
|
||||
public void PlayerGoOffline();
|
||||
}
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
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();
|
||||
|
||||
}
|
42
assembly/pom.xml
Normal file
42
assembly/pom.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<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>openinvparent</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvassembly</artifactId>
|
||||
<name>OpenInvAssembly</name>
|
||||
|
||||
<build>
|
||||
<directory>../target</directory>
|
||||
<finalName>OpenInv</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>reactor-uberjar</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<descriptors>
|
||||
<descriptor>src/assembly/reactor-uberjar.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
28
assembly/src/assembly/reactor-uberjar.xml
Normal file
28
assembly/src/assembly/reactor-uberjar.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
|
||||
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">
|
||||
|
||||
<id>reactor-uberjar</id>
|
||||
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
|
||||
<moduleSets>
|
||||
<moduleSet>
|
||||
|
||||
<useAllReactorProjects>true</useAllReactorProjects>
|
||||
|
||||
<binaries>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<unpack>true</unpack>
|
||||
<!-- unpackOptions must be present or build breaks. -->
|
||||
<unpackOptions/>
|
||||
</binaries>
|
||||
|
||||
</moduleSet>
|
||||
</moduleSets>
|
||||
|
||||
</assembly>
|
29
common/pom.xml
Normal file
29
common/pom.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<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>openinvparent</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<name>OpenInvCommon</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.4.5-R1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/../lib/bukkit-1.4.5-R1.0.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvapi</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IPlayerDataManager {
|
||||
|
||||
/**
|
||||
* Loads a Player for an OfflinePlayer.
|
||||
* </p>
|
||||
* This method is potentially blocking, and should not be called on the main thread.
|
||||
*
|
||||
* @param offline
|
||||
* @return
|
||||
*/
|
||||
public Player loadPlayer(OfflinePlayer offline);
|
||||
|
||||
/**
|
||||
* Gets a unique identifying string for an OfflinePlayer.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public String getPlayerDataID(OfflinePlayer player);
|
||||
|
||||
/**
|
||||
* Gets an OfflinePlayer by the given unique identifier.
|
||||
*
|
||||
* @param identifier the unique identifier
|
||||
* @return the OfflinePlayer, or null if no exact match was found
|
||||
*/
|
||||
public OfflinePlayer getPlayerByID(String identifier);
|
||||
|
||||
/**
|
||||
* Gets a Collection of all Players currently online.
|
||||
*
|
||||
* @return the Collection of Players
|
||||
*/
|
||||
public Collection<? extends Player> getOnlinePlayers();
|
||||
|
||||
}
|
180
common/src/main/java/com/lishid/openinv/util/Cache.java
Normal file
180
common/src/main/java/com/lishid/openinv/util/Cache.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package com.lishid.openinv.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.TreeMultimap;
|
||||
|
||||
/**
|
||||
* A minimal thread-safe time-based cache implementation backed by a HashMap and TreeMultimap.
|
||||
*
|
||||
* @author Jikoo
|
||||
*/
|
||||
public class Cache<K, V> {
|
||||
|
||||
private final Map<K, V> internal;
|
||||
private final Multimap<Long, K> expiry;
|
||||
private final long retention;
|
||||
private final Function<V> inUseCheck, postRemoval;
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
*/
|
||||
public Cache(final long retention, final Function<V> inUseCheck, final Function<V> postRemoval) {
|
||||
this.internal = new HashMap<K, V>();
|
||||
|
||||
this.expiry = TreeMultimap.create(new Comparator<Long>() {
|
||||
@Override
|
||||
public int compare(final Long long1, final Long long2) {
|
||||
return long1.compareTo(long2);
|
||||
}
|
||||
},
|
||||
new Comparator<K>() {
|
||||
@Override
|
||||
public int compare(final K k1, final K k2) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
this.retention = retention;
|
||||
this.inUseCheck = inUseCheck;
|
||||
this.postRemoval = postRemoval;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param key key with which the specified value is to be associated
|
||||
* @param value value to be associated with the specified key
|
||||
*/
|
||||
public void put(final K key, final V value) {
|
||||
// Invalidate key - runs lazy check and ensures value won't be cleaned up early
|
||||
this.invalidate(key);
|
||||
|
||||
synchronized (this.internal) {
|
||||
this.internal.put(key, value);
|
||||
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.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public V get(final K key) {
|
||||
// Run lazy check to clean cache
|
||||
this.lazyCheck();
|
||||
|
||||
synchronized (this.internal) {
|
||||
return this.internal.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified key is mapped to a value.
|
||||
*
|
||||
* @param key key to check if a mapping exists for
|
||||
* @return true if a mapping exists for the specified key
|
||||
*/
|
||||
public boolean containsKey(final K key) {
|
||||
// Run lazy check to clean cache
|
||||
this.lazyCheck();
|
||||
|
||||
synchronized (this.internal) {
|
||||
return this.internal.containsKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcibly invalidates a key, even if it is considered to be in use.
|
||||
*
|
||||
* @param key key to invalidate
|
||||
*/
|
||||
public void invalidate(final K key) {
|
||||
// Run lazy check to clean cache
|
||||
this.lazyCheck();
|
||||
|
||||
synchronized (this.internal) {
|
||||
if (!this.internal.containsKey(key)) {
|
||||
// Value either not present or cleaned by lazy check. Either way, we're good
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove stored object
|
||||
this.internal.remove(key);
|
||||
|
||||
// Remove expiration entry - prevents more work later, plus prevents issues with values invalidating early
|
||||
for (Iterator<Map.Entry<Long, K>> iterator = this.expiry.entries().iterator(); iterator.hasNext();) {
|
||||
if (key.equals(iterator.next().getValue())) {
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcibly invalidates all keys, even if they are considered to be in use.
|
||||
*/
|
||||
public void invalidateAll() {
|
||||
synchronized (this.internal) {
|
||||
for (V value : this.internal.values()) {
|
||||
this.postRemoval.run(value);
|
||||
}
|
||||
this.expiry.clear();
|
||||
this.internal.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate all expired keys that are not considered in use. If a key is expired but is
|
||||
* considered in use by the provided Function, its expiration time is reset.
|
||||
*/
|
||||
private void lazyCheck() {
|
||||
long now = System.currentTimeMillis();
|
||||
synchronized (this.internal) {
|
||||
List<K> inUse = new ArrayList<K>();
|
||||
for (Iterator<Map.Entry<Long, K>> iterator = this.expiry.entries().iterator(); iterator
|
||||
.hasNext();) {
|
||||
Map.Entry<Long, K> entry = iterator.next();
|
||||
|
||||
if (entry.getKey() > now) {
|
||||
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);
|
||||
}
|
||||
|
||||
long nextExpiry = now + this.retention;
|
||||
for (K value : inUse) {
|
||||
this.expiry.put(nextExpiry, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
12
common/src/main/java/com/lishid/openinv/util/Function.java
Normal file
12
common/src/main/java/com/lishid/openinv/util/Function.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.lishid.openinv.util;
|
||||
|
||||
/**
|
||||
* Abstraction for some simple cache calls.
|
||||
*
|
||||
* @author Jikoo
|
||||
*/
|
||||
public abstract class Function<V> {
|
||||
|
||||
public abstract boolean run(V value);
|
||||
|
||||
}
|
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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.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.IInventoryAccess;
|
||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class InternalAccessor {
|
||||
|
||||
public static <T> T grabFieldOfTypeFromObject(final Class<T> type, final Object object) {
|
||||
// Use reflection to find the IInventory
|
||||
Class<?> clazz = object.getClass();
|
||||
T result = null;
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
f.setAccessible(true);
|
||||
if (type.isAssignableFrom(f.getDeclaringClass())) {
|
||||
try {
|
||||
result = type.cast(f.get(object));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private final Plugin plugin;
|
||||
private final String version;
|
||||
private boolean supported = false;
|
||||
private IPlayerDataManager playerDataManager;
|
||||
private IInventoryAccess inventoryAccess;
|
||||
|
||||
private IAnySilentContainer anySilentContainer;
|
||||
|
||||
public InternalAccessor(final Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
String packageName = plugin.getServer().getClass().getPackage().getName();
|
||||
this.version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
|
||||
try {
|
||||
Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialPlayerInventory");
|
||||
Class.forName("com.lishid.openinv.internal." + this.version + ".SpecialEnderChest");
|
||||
this.playerDataManager = this.createObject(IPlayerDataManager.class, "PlayerDataManager");
|
||||
this.inventoryAccess = this.createObject(IInventoryAccess.class, "InventoryAccess");
|
||||
this.anySilentContainer = this.createObject(IAnySilentContainer.class, "AnySilentContainer");
|
||||
this.supported = true;
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
private <T> T createObject(final Class<? extends T> assignableClass, final String className,
|
||||
final Object... params) throws ClassCastException, ClassNotFoundException,
|
||||
InstantiationException, IllegalAccessException, IllegalArgumentException,
|
||||
InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
// Fetch internal class if it exists.
|
||||
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + this.version + "." + className);
|
||||
if (!assignableClass.isAssignableFrom(internalClass)) {
|
||||
String message = String.format("Found class %s but cannot cast to %s!", internalClass.getName(), assignableClass.getName());
|
||||
this.plugin.getLogger().warning(message);
|
||||
throw new IllegalStateException(message);
|
||||
}
|
||||
|
||||
// Quick return: no parameters, no need to fiddle about finding the correct constructor.
|
||||
if (params.length == 0) {
|
||||
return assignableClass.cast(internalClass.getConstructor().newInstance());
|
||||
}
|
||||
|
||||
// Search constructors for one matching the given parameters
|
||||
nextConstructor: for (Constructor<?> constructor : internalClass.getConstructors()) {
|
||||
Class<?>[] requiredClasses = constructor.getParameterTypes();
|
||||
if (requiredClasses.length != params.length) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
if (!requiredClasses[i].isAssignableFrom(params[i].getClass())) {
|
||||
continue nextConstructor;
|
||||
}
|
||||
}
|
||||
return assignableClass.cast(constructor.newInstance(params));
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder("Found class ").append(internalClass.getName())
|
||||
.append(" but cannot find any matching constructors for [");
|
||||
for (Object object : params) {
|
||||
builder.append(object.getClass().getName()).append(", ");
|
||||
}
|
||||
if (params.length > 0) {
|
||||
builder.delete(builder.length() - 2, builder.length());
|
||||
}
|
||||
|
||||
String message = builder.append(']').toString();
|
||||
this.plugin.getLogger().warning(message);
|
||||
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the IAnySilentContainer implementation for the current server version.
|
||||
*
|
||||
* @return the IAnySilentContainer
|
||||
* @throws IllegalStateException if server version is unsupported
|
||||
*/
|
||||
public IAnySilentContainer getAnySilentContainer() {
|
||||
if (!this.supported) {
|
||||
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
|
||||
}
|
||||
return this.anySilentContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the IInventoryAccess implementation for the current server version.
|
||||
*
|
||||
* @return the IInventoryAccess
|
||||
* @throws IllegalStateException if server version is unsupported
|
||||
*/
|
||||
public IInventoryAccess getInventoryAccess() {
|
||||
if (!this.supported) {
|
||||
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
|
||||
}
|
||||
return this.inventoryAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the IPlayerDataManager implementation for the current server version.
|
||||
*
|
||||
* @return the IPlayerDataManager
|
||||
* @throws IllegalStateException if server version is unsupported
|
||||
*/
|
||||
public IPlayerDataManager getPlayerDataManager() {
|
||||
if (!this.supported) {
|
||||
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
|
||||
}
|
||||
return this.playerDataManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server implementation version. If not initialized, returns the string "null"
|
||||
* instead.
|
||||
*
|
||||
* @return the version, or "null"
|
||||
*/
|
||||
public String getVersion() {
|
||||
return this.version != null ? this.version : "null";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the server implementation is supported.
|
||||
*
|
||||
* @return true if initialized for a supported server version
|
||||
*/
|
||||
public boolean isSupported() {
|
||||
return this.supported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the ISpecialEnderChest implementation for the given Player, or
|
||||
* null if the current version is unsupported.
|
||||
*
|
||||
* @param player the Player
|
||||
* @param online true if the Player is online
|
||||
* @return the ISpecialEnderChest created
|
||||
* @throws InstantiationException if the ISpecialEnderChest could not be instantiated
|
||||
*/
|
||||
public ISpecialEnderChest newSpecialEnderChest(final Player player, final boolean online) throws InstantiationException {
|
||||
if (!this.supported) {
|
||||
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
|
||||
}
|
||||
try {
|
||||
return this.createObject(ISpecialEnderChest.class, "SpecialEnderChest", player, online);
|
||||
} catch (Exception e) {
|
||||
throw new InstantiationException(String.format("Unable to create a new ISpecialEnderChest: %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the ISpecialPlayerInventory implementation for the given Player..
|
||||
*
|
||||
* @param player the Player
|
||||
* @param online true if the Player is online
|
||||
* @return the ISpecialPlayerInventory created
|
||||
* @throws InstantiationException if the ISpecialPlayerInventory could not be instantiated
|
||||
*/
|
||||
public ISpecialPlayerInventory newSpecialPlayerInventory(final Player player, final boolean online) throws InstantiationException {
|
||||
if (!this.supported) {
|
||||
throw new IllegalStateException(String.format("Unsupported server version %s!", this.version));
|
||||
}
|
||||
try {
|
||||
return this.createObject(ISpecialPlayerInventory.class, "SpecialPlayerInventory", player, online);
|
||||
} catch (Exception e) {
|
||||
throw new InstantiationException(String.format("Unable to create a new ISpecialPlayerInventory: %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package com.lishid.openinv.util;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
|
||||
public enum Permissions {
|
||||
|
||||
OPENINV("openinv"),
|
||||
OVERRIDE("override"),
|
||||
EXEMPT("exempt"),
|
||||
CROSSWORLD("crossworld"),
|
||||
SILENT("silent"),
|
||||
ANYCHEST("anychest"),
|
||||
ENDERCHEST("openender"),
|
||||
ENDERCHEST_ALL("openenderall"),
|
||||
SEARCH("search"),
|
||||
EDITINV("editinv"),
|
||||
EDITENDER("editender"),
|
||||
OPENSELF("openself");
|
||||
|
||||
private final String[] permission;
|
||||
|
||||
Permissions(String... permission) {
|
||||
this.permission = new String[permission.length + 1];
|
||||
this.permission[0] = "OpenInv";
|
||||
System.arraycopy(permission, 0, permission, 1, permission.length);
|
||||
}
|
||||
|
||||
public boolean hasPermission(Permissible permissible) {
|
||||
StringBuilder permissionBuilder = new StringBuilder();
|
||||
|
||||
// Support wildcard nodes.
|
||||
for (int i = 0; i < permission.length; i++) {
|
||||
if (permissible.hasPermission(permissionBuilder.toString() + "*")) {
|
||||
return true;
|
||||
}
|
||||
permissionBuilder.append(permission[i]).append('.');
|
||||
}
|
||||
|
||||
// Delete trailing period.
|
||||
if (permissionBuilder.length() > 0) {
|
||||
permissionBuilder.deleteCharAt(permissionBuilder.length() - 1);
|
||||
}
|
||||
|
||||
return permissible.hasPermission(permissionBuilder.toString());
|
||||
}
|
||||
|
||||
}
|
28
internal/1_4_5/pom.xml
Normal file
28
internal/1_4_5/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_4_5</artifactId>
|
||||
<name>OpenInvAdapter1_4_5</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.5-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_4_5;
|
||||
|
||||
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.BlockEnderChest;
|
||||
import net.minecraft.server.v1_4_5.Container;
|
||||
import net.minecraft.server.v1_4_5.EntityOcelot;
|
||||
import net.minecraft.server.v1_4_5.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_5.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_5.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_5.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_4_5.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize()));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_4_5;
|
||||
|
||||
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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_4_5;
|
||||
|
||||
import java.util.Arrays;
|
||||
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.ItemInWorldManager;
|
||||
import net.minecraft.server.v1_4_5.MinecraftServer;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new ItemInWorldManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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().f(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_4_5;
|
||||
|
||||
import net.minecraft.server.v1_4_5.ContainerChest;
|
||||
import net.minecraft.server.v1_4_5.EntityHuman;
|
||||
import net.minecraft.server.v1_4_5.IInventory;
|
||||
import net.minecraft.server.v1_4_5.ItemStack;
|
||||
import net.minecraft.server.v1_4_5.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.f();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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_4_5;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_5.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_5.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
|
||||
((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* 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_4_5;
|
||||
|
||||
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.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
28
internal/1_4_6/pom.xml
Normal file
28
internal/1_4_6/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_4_6</artifactId>
|
||||
<name>OpenInvAdapter1_4_6</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.6-R0.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_4_6;
|
||||
|
||||
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.BlockEnderChest;
|
||||
import net.minecraft.server.v1_4_6.Container;
|
||||
import net.minecraft.server.v1_4_6.EntityOcelot;
|
||||
import net.minecraft.server.v1_4_6.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_6.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_6.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_6.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_4_6.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize()));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_4_6;
|
||||
|
||||
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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_4_6;
|
||||
|
||||
import java.util.Arrays;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_4_6.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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().f(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_4_6;
|
||||
|
||||
import net.minecraft.server.v1_4_6.ContainerChest;
|
||||
import net.minecraft.server.v1_4_6.EntityHuman;
|
||||
import net.minecraft.server.v1_4_6.IInventory;
|
||||
import net.minecraft.server.v1_4_6.ItemStack;
|
||||
import net.minecraft.server.v1_4_6.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.f();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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_4_6;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_6.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_6.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
|
||||
((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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_4_6;
|
||||
|
||||
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.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
65
internal/pom.xml
Normal file
65
internal/pom.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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>openinvparent</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvinternal</artifactId>
|
||||
<name>OpenInvInternal</name>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>latest</id>
|
||||
<modules>
|
||||
<module>v1_12_R1</module>
|
||||
</modules>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>recent</id>
|
||||
<!-- The recent profile is for the most recent 2 versions. -->
|
||||
<modules>
|
||||
<module>v1_11_R1</module>
|
||||
<module>v1_12_R1</module>
|
||||
</modules>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>all</id>
|
||||
<modules>
|
||||
<module>1_4_5</module>
|
||||
<module>1_4_6</module>
|
||||
<module>v1_4_R1</module>
|
||||
<!-- 1_5_R1 was never released -->
|
||||
<module>v1_5_R2</module>
|
||||
<module>v1_5_R3</module>
|
||||
<!-- 1_6_R1 also had no tagged releases, remove? -->
|
||||
<module>v1_6_R1</module>
|
||||
<module>v1_6_R2</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_R2</module>
|
||||
<module>v1_7_R3</module>
|
||||
<module>v1_7_R4</module>
|
||||
<module>v1_8_R1</module>
|
||||
<module>v1_8_R2</module>
|
||||
<module>v1_8_R3</module>
|
||||
<module>v1_9_R1</module>
|
||||
<module>v1_9_R2</module>
|
||||
<module>v1_10_R1</module>
|
||||
<module>v1_11_R1</module>
|
||||
<module>v1_12_R1</module>
|
||||
</modules>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
|
||||
</project>
|
28
internal/v1_10_R1/pom.xml
Normal file
28
internal/v1_10_R1/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_10_R1</artifactId>
|
||||
<name>OpenInvAdapter1_10_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.10-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
* 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 com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
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.Block;
|
||||
import net.minecraft.server.v1_10_R1.BlockChest;
|
||||
import net.minecraft.server.v1_10_R1.BlockEnderChest;
|
||||
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.EntityOcelot;
|
||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_10_R1.EnumDirection;
|
||||
import net.minecraft.server.v1_10_R1.ITileInventory;
|
||||
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_10_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_10_R1.StatisticList;
|
||||
import net.minecraft.server.v1_10_R1.TileEntity;
|
||||
import net.minecraft.server.v1_10_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_10_R1.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_10_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
||||
Block block = world.getType(blockPosition).getBlock();
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.getType(blockPosition.up()).m();
|
||||
}
|
||||
|
||||
// Check if chest is blocked or has an ocelot on top
|
||||
if (isBlockedChest(world, blockPosition)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for matching adjacent chests that are blocked or have an ocelot on top
|
||||
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 (isBlockedChest(world, localBlockPosition)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, BlockPosition blockPosition) {
|
||||
// For reference, loot at net.minecraft.server.BlockChest
|
||||
return world.getType(blockPosition.up()).l() || hasOcelotOnTop(world, blockPosition);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, 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(Player p, boolean silentchest, org.bukkit.block.Block b) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is pretty much API-only
|
||||
if (silentchest && b.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
player.b(StatisticList.X);
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
||||
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);
|
||||
player.b(StatisticList.X);
|
||||
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) {
|
||||
player.b(StatisticList.ac);
|
||||
} else if (blockChest.g == BlockChest.Type.TRAP) {
|
||||
player.b(StatisticList.W);
|
||||
}
|
||||
|
||||
if (silentchest) {
|
||||
container = new SilentContainerChest(player.inventory, tileInventory, player);
|
||||
}
|
||||
}
|
||||
|
||||
// AnyChest only - SilentChest not active or container unsupported
|
||||
if (!silentchest || container == null) {
|
||||
player.openContainer(tileInventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container, false);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 com.lishid.openinv.internal.IInventoryAccess;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.util.InternalAccessor;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_10_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure player has data
|
||||
if (offline == null || !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 == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(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 Collection<? extends Player> getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_10_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_10_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.bukkitOwner = nmsPlayer.getBukkitEntity();
|
||||
setItemArrays(this, enderChest.getContents());
|
||||
}
|
||||
|
||||
private void setItemArrays(InventorySubcontainer subcontainer, ItemStack[] items) {
|
||||
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, items);
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.bukkitOwner = nmsPlayer.getBukkitEntity();
|
||||
setItemArrays(nmsPlayer.getEnderChest(), this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
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.ItemStack;
|
||||
import net.minecraft.server.v1_10_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[4];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
|
||||
}
|
||||
|
||||
private void setItemArrays(PlayerInventory inventory, ItemStack[] items, ItemStack[] armor,
|
||||
ItemStack[] extraSlots) {
|
||||
try {
|
||||
// Prepare to remove final modifier
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
|
||||
// Access and replace main inventory array
|
||||
Field field = PlayerInventory.class.getField("items");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, items);
|
||||
|
||||
// Access and replace armor inventory array
|
||||
field = PlayerInventory.class.getField("armor");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, armor);
|
||||
|
||||
// Access and replace offhand inventory array
|
||||
field = PlayerInventory.class.getField("extraSlots");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, extraSlots);
|
||||
|
||||
// Access and replace array containing all inventory arrays
|
||||
field = PlayerInventory.class.getDeclaredField("g");
|
||||
field.setAccessible(true);
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, new ItemStack[][] { items, armor, extraSlots });
|
||||
} catch (NoSuchFieldException e) {
|
||||
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
setItemArrays(this.player.inventory, items, armor, extraSlots);
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
System.arraycopy(extraSlots, 0, contents, items.length + armor.length, extraSlots.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
// extraSlots is, for now, just an array with length 1. No need for special handling.
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].cloneAndSubtract(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extraSlots;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack, true);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_11_R1/pom.xml
Normal file
28
internal/v1_11_R1/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_11_R1</artifactId>
|
||||
<name>OpenInvAdapter1_11_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_11_R1.Block;
|
||||
import net.minecraft.server.v1_11_R1.BlockChest;
|
||||
import net.minecraft.server.v1_11_R1.BlockEnderChest;
|
||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
|
||||
import net.minecraft.server.v1_11_R1.Entity;
|
||||
import net.minecraft.server.v1_11_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_11_R1.EnumDirection;
|
||||
import net.minecraft.server.v1_11_R1.IBlockData;
|
||||
import net.minecraft.server.v1_11_R1.ITileInventory;
|
||||
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_11_R1.StatisticList;
|
||||
import net.minecraft.server.v1_11_R1.TileEntity;
|
||||
import net.minecraft.server.v1_11_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_11_R1.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
|
||||
import net.minecraft.server.v1_11_R1.World;
|
||||
import net.minecraft.server.v1_11_R1.EnumGamemode;
|
||||
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
|
||||
|
||||
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
|
||||
public boolean isAnySilentContainer(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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
||||
IBlockData blockData = world.getType(blockPosition);
|
||||
Block block = blockData.getBlock();
|
||||
|
||||
if (block instanceof BlockShulkerBox) {
|
||||
return isBlockedShulkerBox(world, blockPosition, blockData);
|
||||
}
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.getType(blockPosition.up()).m();
|
||||
}
|
||||
|
||||
// Check if chest is blocked or has an ocelot on top
|
||||
if (isBlockedChest(world, blockPosition)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for matching adjacent chests that are blocked or have an ocelot on top
|
||||
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 (isBlockedChest(world, localBlockPosition)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedShulkerBox(World world, BlockPosition blockPosition, 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).p() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
|
||||
AxisAlignedBB axisAlignedBB = Block.j.b(0.5F * enumDirection.getAdjacentX(),
|
||||
0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
|
||||
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
|
||||
enumDirection.getAdjacentZ());
|
||||
|
||||
try {
|
||||
// 1.11.2
|
||||
return world.a(axisAlignedBB.a(blockPosition.shift(enumDirection)));
|
||||
} catch (NoSuchMethodError e) {
|
||||
// 1.11
|
||||
return world.b(axisAlignedBB.a(blockPosition.shift(enumDirection)));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, BlockPosition blockPosition) {
|
||||
// For reference, loot at net.minecraft.server.BlockChest
|
||||
return world.getType(blockPosition.up()).m() || hasOcelotOnTop(world, blockPosition);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, 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(Player p, boolean silentchest, org.bukkit.block.Block b) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is pretty much API-only
|
||||
if (silentchest && b.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
player.b(StatisticList.getStatistic("stat.enderchestOpened"));
|
||||
return true;
|
||||
}
|
||||
|
||||
final World world = player.world;
|
||||
final BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.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);
|
||||
player.b(StatisticList.getStatistic("stat.enderchestOpened"));
|
||||
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) {
|
||||
player.b(StatisticList.getStatistic("stat.chestOpened"));
|
||||
} else if (blockChest.g == BlockChest.Type.TRAP) {
|
||||
player.b(StatisticList.getStatistic("stat.trappedChestTriggered"));
|
||||
}
|
||||
}
|
||||
|
||||
if (block instanceof BlockShulkerBox) {
|
||||
player.b(StatisticList.getStatistic("stat.shulkerBoxOpened"));
|
||||
}
|
||||
|
||||
// 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(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 (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 com.lishid.openinv.internal.IInventoryAccess;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
import com.lishid.openinv.util.InternalAccessor;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_11_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure player has data
|
||||
if (offline == null || !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 == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(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 Collection<? extends Player> getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_11_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.bukkitOwner = nmsPlayer.getBukkitEntity();
|
||||
setItemLists(this, enderChest.getContents());
|
||||
}
|
||||
|
||||
private void setItemLists(InventorySubcontainer subcontainer, 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 e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.bukkitOwner = nmsPlayer.getBukkitEntity();
|
||||
setItemLists(nmsPlayer.getEnderChest(), this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
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.EntityHuman;
|
||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
||||
import net.minecraft.server.v1_11_R1.NonNullList;
|
||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
|
||||
}
|
||||
|
||||
private void setItemArrays(PlayerInventory inventory, NonNullList<ItemStack> items,
|
||||
NonNullList<ItemStack> armor, NonNullList<ItemStack> extraSlots) {
|
||||
try {
|
||||
// Prepare to remove final modifier
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
|
||||
// Access and replace main inventory array
|
||||
Field field = PlayerInventory.class.getField("items");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, items);
|
||||
|
||||
// Access and replace armor inventory array
|
||||
field = PlayerInventory.class.getField("armor");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, armor);
|
||||
|
||||
// Access and replace offhand inventory array
|
||||
field = PlayerInventory.class.getField("extraSlots");
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, extraSlots);
|
||||
|
||||
// Access and replace array containing all inventory arrays
|
||||
field = PlayerInventory.class.getDeclaredField("g");
|
||||
field.setAccessible(true);
|
||||
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots }));
|
||||
} catch (NoSuchFieldException e) {
|
||||
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);;
|
||||
setItemArrays(this.player.inventory, items, armor, extraSlots);
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
NonNullList<ItemStack> list = this.items;
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
return list.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
NonNullList<ItemStack> list = this.items;
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
return list == null || 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 = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
if (list != null && !list.get(i).isEmpty()) {
|
||||
ItemStack itemstack = list.get(i);
|
||||
|
||||
list.set(i, ItemStack.a);
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
NonNullList<ItemStack> list = this.items;
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
i -= list.size();
|
||||
list = this.extraSlots;
|
||||
} else if (list == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= list.size()) {
|
||||
player.drop(itemstack, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (list != null) {
|
||||
list.set(i, itemstack);
|
||||
}
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
41
internal/v1_12_R1/pom.xml
Normal file
41
internal/v1_12_R1/pom.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_12_R1</artifactId>
|
||||
<name>OpenInvAdapter1_12_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</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>
|
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_12_R1.Block;
|
||||
import net.minecraft.server.v1_12_R1.BlockChest;
|
||||
import net.minecraft.server.v1_12_R1.BlockEnderChest;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.BlockShulkerBox;
|
||||
import net.minecraft.server.v1_12_R1.Entity;
|
||||
import net.minecraft.server.v1_12_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_12_R1.EntityPlayer;
|
||||
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.ITileInventory;
|
||||
import net.minecraft.server.v1_12_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_12_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_12_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_12_R1.TileEntity;
|
||||
import net.minecraft.server.v1_12_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_12_R1.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_12_R1.TileEntityShulkerBox;
|
||||
import net.minecraft.server.v1_12_R1.World;
|
||||
|
||||
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 activateContainer(final Player bukkitPlayer, final boolean silentchest,
|
||||
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(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();
|
||||
}
|
||||
}
|
||||
|
||||
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 isAnyContainerNeeded(final Player p, final org.bukkit.block.Block b) {
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.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()).m();
|
||||
}
|
||||
|
||||
// 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
|
||||
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 (this.isBlockedChest(world, localBlockPosition)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
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).p() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
|
||||
AxisAlignedBB axisAlignedBB = Block.j.b(0.5F * enumDirection.getAdjacentX(),
|
||||
0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
|
||||
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
|
||||
enumDirection.getAdjacentZ());
|
||||
|
||||
return world.a(axisAlignedBB.a(blockPosition.shift(enumDirection)));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2014 lishid. All rights reserved. This program is free software: you can
|
||||
* redistribute it and/or modify it under the terms of the GNU General Public License as published
|
||||
* by the Free Software Foundation, version 3. This program is distributed in the hope that it will
|
||||
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should
|
||||
* have received a copy of the GNU General Public License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.lishid.openinv.internal.v1_12_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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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(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(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(final Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class,
|
||||
inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_12_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
|
||||
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 Collection<? extends Player> getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(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 String getPlayerDataID(final OfflinePlayer player) {
|
||||
return player.getUniqueId().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(final OfflinePlayer offline) {
|
||||
// Ensure player has data
|
||||
if (offline == null || !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 == null ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_12_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_12_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_12_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer
|
||||
implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialEnderChest(final Player player, final Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().hasCustomName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.bukkitOwner = nmsPlayer.getBukkitEntity();
|
||||
this.setItemLists(this, this.enderChest.getContents());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return this.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 e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
this.playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(final Player player) {
|
||||
if (!this.playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.bukkitOwner = nmsPlayer.getBukkitEntity();
|
||||
this.setItemLists(nmsPlayer.getEnderChest(), this.items);
|
||||
} catch (Exception e) {}
|
||||
this.playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
this.enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* 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 java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
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.EntityHuman;
|
||||
import net.minecraft.server.v1_12_R1.ItemStack;
|
||||
import net.minecraft.server.v1_12_R1.NonNullList;
|
||||
import net.minecraft.server.v1_12_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
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 Inventory getBukkitInventory() {
|
||||
return this.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 String getName() {
|
||||
if (this.player.getName().length() > 16) {
|
||||
return this.player.getName().substring(0, 16);
|
||||
}
|
||||
return this.player.getName();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (list != null) {
|
||||
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(new NonNullList[] { items, armor, extraSlots }));
|
||||
} catch (NoSuchFieldException e) {
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
this.playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(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 == null || 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 != null && !list.get(i).isEmpty()) {
|
||||
ItemStack itemstack = list.get(i);
|
||||
|
||||
list.set(i, ItemStack.a);
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return ItemStack.a;
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_4_R1/pom.xml
Normal file
28
internal/v1_4_R1/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_4_R1</artifactId>
|
||||
<name>OpenInvAdapter1_4_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.4.7-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_4_R1;
|
||||
|
||||
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.BlockEnderChest;
|
||||
import net.minecraft.server.v1_4_R1.Container;
|
||||
import net.minecraft.server.v1_4_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_4_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_4_R1.IInventory;
|
||||
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_4_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_4_R1.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_4_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_R1.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize()));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_4_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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_4_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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_4_R1;
|
||||
|
||||
import java.util.Arrays;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_4_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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().f(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_4_R1;
|
||||
|
||||
import net.minecraft.server.v1_4_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_4_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_4_R1.IInventory;
|
||||
import net.minecraft.server.v1_4_R1.ItemStack;
|
||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.f();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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_4_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_4_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_4_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* 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_4_R1;
|
||||
|
||||
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.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_5_R2/pom.xml
Normal file
28
internal/v1_5_R2/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_5_R2</artifactId>
|
||||
<name>OpenInvAdapter1_5_R2</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.5.1-R0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_5_R2;
|
||||
|
||||
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.BlockEnderChest;
|
||||
import net.minecraft.server.v1_5_R2.Container;
|
||||
import net.minecraft.server.v1_5_R2.EntityOcelot;
|
||||
import net.minecraft.server.v1_5_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_5_R2.IInventory;
|
||||
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_5_R2.TileEntityChest;
|
||||
import net.minecraft.server.v1_5_R2.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_5_R2.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_5_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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_5_R2.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_5_R2;
|
||||
|
||||
import java.util.Arrays;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_5_R2.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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().f(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_5_R2;
|
||||
|
||||
import net.minecraft.server.v1_5_R2.ContainerChest;
|
||||
import net.minecraft.server.v1_5_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_5_R2.IInventory;
|
||||
import net.minecraft.server.v1_5_R2.ItemStack;
|
||||
import net.minecraft.server.v1_5_R2.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.g();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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_5_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_5_R2.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_5_R2.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().c(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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_5_R2;
|
||||
|
||||
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.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_5_R3/pom.xml
Normal file
28
internal/v1_5_R3/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_5_R3</artifactId>
|
||||
<name>OpenInvAdapter1_5_R3</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.5.2-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_5_R3;
|
||||
|
||||
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.BlockEnderChest;
|
||||
import net.minecraft.server.v1_5_R3.Container;
|
||||
import net.minecraft.server.v1_5_R3.EntityOcelot;
|
||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_5_R3.IInventory;
|
||||
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_5_R3.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_5_R3.TileEntityChest;
|
||||
import net.minecraft.server.v1_5_R3.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_5_R3.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_5_R3;
|
||||
|
||||
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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_5_R3.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_5_R3;
|
||||
|
||||
import java.util.Arrays;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_5_R3.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_5_R3;
|
||||
|
||||
import net.minecraft.server.v1_5_R3.ContainerChest;
|
||||
import net.minecraft.server.v1_5_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_5_R3.IInventory;
|
||||
import net.minecraft.server.v1_5_R3.ItemStack;
|
||||
import net.minecraft.server.v1_5_R3.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest { public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.g();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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_5_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_5_R3.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_5_R3.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().c(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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_5_R3;
|
||||
|
||||
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.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_6_R1/pom.xml
Normal file
28
internal/v1_6_R1/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_6_R1</artifactId>
|
||||
<name>OpenInvAdapter1_6_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.6.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_6_R1;
|
||||
|
||||
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.BlockEnderChest;
|
||||
import net.minecraft.server.v1_6_R1.Container;
|
||||
import net.minecraft.server.v1_6_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_6_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R1.IInventory;
|
||||
import net.minecraft.server.v1_6_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_6_R1.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_6_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_6_R1.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_6_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_6_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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_6_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_6_R1;
|
||||
|
||||
import java.util.Arrays;
|
||||
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.MinecraftServer;
|
||||
import net.minecraft.server.v1_6_R1.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_6_R1;
|
||||
|
||||
import net.minecraft.server.v1_6_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_6_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_6_R1.IInventory;
|
||||
import net.minecraft.server.v1_6_R1.ItemStack;
|
||||
import net.minecraft.server.v1_6_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.g();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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_6_R1;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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.IInventory;
|
||||
import net.minecraft.server.v1_6_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R1.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_6_R1.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().c(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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_6_R1;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_6_R1.ItemStack;
|
||||
import net.minecraft.server.v1_6_R1.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_6_R2/pom.xml
Normal file
28
internal/v1_6_R2/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_6_R2</artifactId>
|
||||
<name>OpenInvAdapter1_6_R2</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.6.2-R1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_6_R2;
|
||||
|
||||
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_R2.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_6_R2.BlockEnderChest;
|
||||
import net.minecraft.server.v1_6_R2.Container;
|
||||
import net.minecraft.server.v1_6_R2.EntityOcelot;
|
||||
import net.minecraft.server.v1_6_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
import net.minecraft.server.v1_6_R2.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_6_R2.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_6_R2.TileEntityChest;
|
||||
import net.minecraft.server.v1_6_R2.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_6_R2.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_6_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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_6_R2;
|
||||
|
||||
import java.util.Arrays;
|
||||
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_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R2.MinecraftServer;
|
||||
import net.minecraft.server.v1_6_R2.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_6_R2;
|
||||
|
||||
import net.minecraft.server.v1_6_R2.ContainerChest;
|
||||
import net.minecraft.server.v1_6_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||
import net.minecraft.server.v1_6_R2.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.g();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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_6_R2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R2.IInventory;
|
||||
import net.minecraft.server.v1_6_R2.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R2.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().c(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* 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_6_R2;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_6_R2.ItemStack;
|
||||
import net.minecraft.server.v1_6_R2.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27) {
|
||||
return i - 27;
|
||||
}
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0) {
|
||||
return 3;
|
||||
}
|
||||
if (i == 1) {
|
||||
return 2;
|
||||
}
|
||||
if (i == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (i == 3) {
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_6_R3/pom.xml
Normal file
28
internal/v1_6_R3/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_6_R3</artifactId>
|
||||
<name>OpenInvAdapter1_6_R3</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.6.4-R2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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_6_R3;
|
||||
|
||||
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_R3.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_6_R3.BlockEnderChest;
|
||||
import net.minecraft.server.v1_6_R3.Container;
|
||||
import net.minecraft.server.v1_6_R3.EntityOcelot;
|
||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
import net.minecraft.server.v1_6_R3.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R3.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_6_R3.Packet100OpenWindow;
|
||||
import net.minecraft.server.v1_6_R3.TileEntityChest;
|
||||
import net.minecraft.server.v1_6_R3.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_6_R3.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
// 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) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, inventory.getName(), inventory.getSize(), true));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_6_R3;
|
||||
|
||||
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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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_6_R3;
|
||||
|
||||
import java.util.Arrays;
|
||||
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_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_6_R3.PlayerInteractManager;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
|
||||
new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_6_R3;
|
||||
|
||||
import net.minecraft.server.v1_6_R3.ContainerChest;
|
||||
import net.minecraft.server.v1_6_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
||||
import net.minecraft.server.v1_6_R3.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.g();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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_6_R3;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
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_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R3.IInventory;
|
||||
import net.minecraft.server.v1_6_R3.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_6_R3.InventorySubcontainer;
|
||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftHumanEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
|
||||
private final InventoryEnderChest enderChest;
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
private boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public SpecialEnderChest(Player player, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(player).getEnderChest().getName(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().c(),
|
||||
PlayerDataManager.getHandle(player).getEnderChest().getSize());
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.enderChest = nmsPlayer.getEnderChest();
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
this.items = enderChest.getContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
EntityPlayer nmsPlayer = PlayerDataManager.getHandle(player);
|
||||
this.owner = nmsPlayer.getBukkitEntity();
|
||||
InventoryEnderChest playerEnderChest = nmsPlayer.getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
} catch (Exception e) {}
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
enderChest.update();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* 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_6_R3;
|
||||
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
||||
import net.minecraft.server.v1_6_R3.PlayerInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
|
||||
private final ItemStack[] extra = new ItemStack[5];
|
||||
private final CraftInventory inventory = new CraftInventory(this);
|
||||
private boolean playerOnline = false;
|
||||
|
||||
public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
|
||||
super(PlayerDataManager.getHandle(bukkitPlayer));
|
||||
this.playerOnline = online;
|
||||
this.items = player.inventory.items;
|
||||
this.armor = player.inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
this.player = PlayerDataManager.getHandle(player);
|
||||
this.player.inventory.items = this.items;
|
||||
this.player.inventory.armor = this.armor;
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInUse() {
|
||||
return !this.getViewers().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] contents = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, contents, 0, items.length);
|
||||
System.arraycopy(armor, 0, contents, items.length, armor.length);
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
} else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
} else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
} else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
// Effects
|
||||
if (is == this.extra) {
|
||||
player.drop(itemstack);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
player.defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
return 2;
|
||||
if (i == 2)
|
||||
return 1;
|
||||
if (i == 3)
|
||||
return 0;
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
}
|
28
internal/v1_7_R1/pom.xml
Normal file
28
internal/v1_7_R1/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<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>3.3.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>openinvadapter1_7_R1</artifactId>
|
||||
<name>OpenInvAdapter1_7_R1</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.2-R0.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
<version>3.3.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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_7_R1;
|
||||
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.minecraft.server.v1_7_R1.AxisAlignedBB;
|
||||
import net.minecraft.server.v1_7_R1.Block;
|
||||
import net.minecraft.server.v1_7_R1.BlockEnderChest;
|
||||
import net.minecraft.server.v1_7_R1.Container;
|
||||
import net.minecraft.server.v1_7_R1.EntityOcelot;
|
||||
import net.minecraft.server.v1_7_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R1.IInventory;
|
||||
import net.minecraft.server.v1_7_R1.InventoryEnderChest;
|
||||
import net.minecraft.server.v1_7_R1.InventoryLargeChest;
|
||||
import net.minecraft.server.v1_7_R1.PacketPlayOutOpenWindow;
|
||||
import net.minecraft.server.v1_7_R1.TileEntityChest;
|
||||
import net.minecraft.server.v1_7_R1.TileEntityEnderChest;
|
||||
import net.minecraft.server.v1_7_R1.World;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory;
|
||||
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
|
||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
World world = player.world;
|
||||
|
||||
if (block instanceof BlockEnderChest) {
|
||||
// Ender chests are not blocked by ocelots.
|
||||
return world.t(block.getX(), block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
// If block or ocelot on top
|
||||
if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int id = Block.b(world.getType(block.getX(), block.getY(), block.getZ()));
|
||||
|
||||
// If block next to chest is chest and has a block or ocelot on top
|
||||
if (Block.b(world.getType(block.getX(), block.getY(), block.getZ() + 1)) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
||||
} else if(Block.b(world.getType(block.getX(), block.getY(), block.getZ() - 1)) == id) {
|
||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
||||
} else if (Block.b(world.getType(block.getX() + 1, block.getY(), block.getZ())) == id) {
|
||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
||||
} else if (Block.b(world.getType(block.getX() - 1, block.getY(), block.getZ())) == id) {
|
||||
return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isBlockedChest(World world, int x, int y, int z) {
|
||||
return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
|
||||
}
|
||||
|
||||
private boolean hasOcelotOnTop(World world, int x, int y, int z) {
|
||||
for (Object localEntity : world.a(EntityOcelot.class,
|
||||
AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
|
||||
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||
if (localEntityOcelot.isSitting()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
|
||||
|
||||
EntityPlayer player = PlayerDataManager.getHandle(p);
|
||||
|
||||
// Silent ender chest is API-only
|
||||
if (silentchest && block.getType() == Material.ENDER_CHEST) {
|
||||
p.openInventory(p.getEnderChest());
|
||||
return true;
|
||||
}
|
||||
|
||||
World world = player.world;
|
||||
Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(tile instanceof IInventory)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IInventory inventory = (IInventory) tile;
|
||||
int id = Block.b(world.getType(block.getX(), block.getY(), block.getZ()));
|
||||
|
||||
if (Block.b(world.getType(block.getX(), block.getY(), block.getZ() + 1)) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
||||
} else if(Block.b(world.getType(block.getX(), block.getY(), block.getZ() - 1)) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), inventory);
|
||||
} else if (Block.b(world.getType(block.getX() + 1, block.getY(), block.getZ())) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", inventory, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
||||
} else if (Block.b(world.getType(block.getX() - 1, block.getY(), block.getZ())) == id) {
|
||||
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), inventory);
|
||||
}
|
||||
|
||||
// AnyChest only
|
||||
if (!silentchest) {
|
||||
player.openContainer(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SilentChest
|
||||
try {
|
||||
// Call InventoryOpenEvent
|
||||
Container container = new SilentContainerChest(player.inventory, inventory);
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open window
|
||||
int windowId = player.nextContainerCounter();
|
||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, inventory.getInventoryName(), inventory.getSize(), true));
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivateContainer(final Player bukkitPlayer) {}
|
||||
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_7_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 org.bukkit.inventory.Inventory;
|
||||
|
||||
import net.minecraft.server.v1_7_R1.IInventory;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean isSpecialPlayerInventory(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialPlayerInventory(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(Inventory inventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
|
||||
}
|
||||
return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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_7_R1;
|
||||
|
||||
import java.util.Arrays;
|
||||
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_7_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_7_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_7_R1.PlayerInteractManager;
|
||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
|
||||
|
||||
public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
@Override
|
||||
public Player loadPlayer(OfflinePlayer offline) {
|
||||
// Ensure the player has data
|
||||
if (offline == null || !offline.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create a profile and entity to load the player data
|
||||
GameProfile profile = new GameProfile(null, 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 == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
}
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerDataID(OfflinePlayer player) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfflinePlayer getPlayerByID(String identifier) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
// Ensure player is a real player, otherwise return null
|
||||
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
|
||||
return null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
return Arrays.asList(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static EntityPlayer getHandle(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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_7_R1;
|
||||
|
||||
import net.minecraft.server.v1_7_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_7_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_7_R1.IInventory;
|
||||
import net.minecraft.server.v1_7_R1.ItemStack;
|
||||
import net.minecraft.server.v1_7_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
// Send close signal
|
||||
i2.l_();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user