Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
23bda96f38 | ||
|
1bbdde683c | ||
|
9edac80544 | ||
|
53eadcb821 | ||
|
326ffdb433 | ||
|
fc5f9587d1 | ||
|
a929eeeb69 | ||
|
7256494df3 | ||
|
1fbaa5b2a9 | ||
|
eeb28b4210 | ||
|
0ebe6fe132 | ||
|
e39ab10797 | ||
|
fb48f6a783 | ||
|
d761b6bfe4 | ||
|
5b3ba79b82 | ||
|
3549431fbc | ||
|
17b0cb6efe | ||
|
2d7522554c | ||
|
131f874329 | ||
|
a623af5119 | ||
|
8f17bd0237 | ||
|
20fb61705d | ||
|
c0f513177a | ||
|
b3a3947b03 | ||
|
c7bab7d451 | ||
|
4058463f7f | ||
|
21cd1926ae | ||
|
2a66b2e81b |
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,10 +0,0 @@
|
|||||||
**/.settings
|
|
||||||
**/.gitignore
|
|
||||||
**/.project
|
|
||||||
**/.classpath
|
|
||||||
**/.idea
|
|
||||||
**/target
|
|
||||||
**/bin
|
|
||||||
**/lib
|
|
||||||
**/out
|
|
||||||
**dependency-reduced-pom.xml
|
|
128
README.MD
128
README.MD
@@ -1,125 +1,13 @@
|
|||||||
## About
|
## Goals
|
||||||
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!
|
This fork of OpenInv was created when the lag caused by offline player lookups post-UUID migration became too much to bear. Overall, it does not differ much from the original.
|
||||||
|
|
||||||
## Features
|
### Changes of Note
|
||||||
- **OpenInv**: Open anyone's inventory, even if they're offline.
|
- Removed updater
|
||||||
- Read-only mode! No edits allowed! Don't grant the permission `OpenInv.editinv`
|
- Removed wand
|
||||||
- Cross-world support! Don't grant `OpenInv.crossworld`
|
- New configuration option `DisableSaving`: Inventory edits will not be saved unless the user is online.
|
||||||
- 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`
|
|
||||||
- **SilentChest**: Open containers without displaying an animation or making sound.
|
|
||||||
- **AnyChest**: Open containers, even if blocked by ocelots or blocks.
|
|
||||||
|
|
||||||
## Commands
|
## Previous Versions
|
||||||
<table width=100%>
|
This fork supports any version after 1.4.5. Binaries are available in the [releases tab](https://github.com/Jikoo/OpenInv/releases). Please allow a brief period after the release of a new version for updates.
|
||||||
<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>/anychest [check]</td>
|
|
||||||
<td>ac</td>
|
|
||||||
<td>Check or toggle the AnyChest function, allowing opening blocked containers.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>/silentchest [check]</td>
|
|
||||||
<td>sc</td>
|
|
||||||
<td>Check or toggle the SilentChest 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.anychest</td>
|
|
||||||
<td>Required to use /anychest.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>OpenInv.silent</td>
|
|
||||||
<td>Required to use /silentchest.</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
|
## License
|
||||||
```
|
```
|
||||||
|
23
api/pom.xml
23
api/pom.xml
@@ -1,23 +0,0 @@
|
|||||||
<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>1.0-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>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,187 +0,0 @@
|
|||||||
package com.lishid.openinv;
|
|
||||||
|
|
||||||
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 {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the server version is supported by OpenInv.
|
|
||||||
*
|
|
||||||
* @return true if the server version is supported
|
|
||||||
*/
|
|
||||||
public boolean isSupportedVersion();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the active IInventoryAccess implementation. May return null if the server version is
|
|
||||||
* unsupported.
|
|
||||||
*
|
|
||||||
* @return the IInventoryAccess
|
|
||||||
*/
|
|
||||||
public IInventoryAccess getInventoryAccess();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the active ISilentContainer implementation. May return null if the server version is
|
|
||||||
* unsupported.
|
|
||||||
*
|
|
||||||
* @return the ISilentContainer
|
|
||||||
*/
|
|
||||||
public IAnySilentContainer getAnySilentContainer();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an ISpecialPlayerInventory for the given Player.
|
|
||||||
*
|
|
||||||
* @param player the Player
|
|
||||||
* @param online true if the Player is currently online
|
|
||||||
* @return the ISpecialPlayerInventory
|
|
||||||
*/
|
|
||||||
public ISpecialPlayerInventory getInventory(Player player, boolean online);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an ISpecialEnderChest for the given Player.
|
|
||||||
*
|
|
||||||
* @param player the Player
|
|
||||||
* @param online true if the Player is currently online
|
|
||||||
* @return the ISpecialEnderChest
|
|
||||||
*/
|
|
||||||
public ISpecialEnderChest getEnderChest(Player player, boolean online);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Forcibly unload a cached Player's data.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer to unload
|
|
||||||
*/
|
|
||||||
public void unload(OfflinePlayer player);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a player's SilentChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @return true if SilentChest is enabled
|
|
||||||
*/
|
|
||||||
public boolean getPlayerSilentChestStatus(OfflinePlayer player);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a player's SilentChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @param status the status
|
|
||||||
*/
|
|
||||||
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the provided player's AnyChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @return true if AnyChest is enabled
|
|
||||||
*/
|
|
||||||
public boolean getPlayerAnyChestStatus(OfflinePlayer player);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a player's AnyChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @param status the status
|
|
||||||
*/
|
|
||||||
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public String getPlayerID(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
|
|
||||||
*/
|
|
||||||
public OfflinePlayer matchPlayer(String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a Player from an OfflinePlayer. May return null under some circumstances.
|
|
||||||
*
|
|
||||||
* @param offline the OfflinePlayer to load a Player for
|
|
||||||
* @return the Player
|
|
||||||
*/
|
|
||||||
public Player loadPlayer(final OfflinePlayer offline);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public void retainPlayer(Player player, Plugin plugin);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public void releasePlayer(Player player, Plugin plugin);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,37 +0,0 @@
|
|||||||
package com.lishid.openinv.internal;
|
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public interface IAnySilentContainer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given block is a container which can be unblocked or silenced.
|
|
||||||
*
|
|
||||||
* @param block the BlockState
|
|
||||||
* @return true if the Block is a supported container
|
|
||||||
*/
|
|
||||||
public boolean isAnySilentContainer(Block block);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the container at the given coordinates is blocked.
|
|
||||||
*
|
|
||||||
* @param player the Player opening the container
|
|
||||||
* @param block the Block
|
|
||||||
* @return true if the container is blocked
|
|
||||||
*/
|
|
||||||
public boolean isAnyContainerNeeded(Player player, Block block);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the container at the given coordinates for the Player. If you do not want blocked
|
|
||||||
* containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)}
|
|
||||||
* first.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* @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);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal;
|
|
||||||
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
public interface IInventoryAccess {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public ISpecialEnderChest getSpecialEnderChest(Inventory inventory);
|
|
||||||
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
<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>1.0-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>
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>
|
|
@@ -1,29 +0,0 @@
|
|||||||
<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>1.0-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>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvapi</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,186 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.util;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
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 {
|
|
||||||
|
|
||||||
private final Plugin plugin;
|
|
||||||
|
|
||||||
private final String version;
|
|
||||||
private boolean supported = false;
|
|
||||||
|
|
||||||
public InternalAccessor(Plugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
|
|
||||||
String packageName = plugin.getServer().getClass().getPackage().getName();
|
|
||||||
version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class.forName("com.lishid.openinv.internal." + version + ".PlayerDataManager");
|
|
||||||
supported = true;
|
|
||||||
} catch (Exception e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 IPlayerDataManager implementation for the current server version,
|
|
||||||
* or null if unsupported.
|
|
||||||
*
|
|
||||||
* @return the IPlayerDataManager
|
|
||||||
*/
|
|
||||||
public IPlayerDataManager newPlayerDataManager() {
|
|
||||||
return createObject(IPlayerDataManager.class, "PlayerDataManager");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of the IInventoryAccess implementation for the current server version, or
|
|
||||||
* null if unsupported.
|
|
||||||
*
|
|
||||||
* @return the IInventoryAccess
|
|
||||||
*/
|
|
||||||
public IInventoryAccess newInventoryAccess() {
|
|
||||||
return createObject(IInventoryAccess.class, "InventoryAccess");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of the IAnySilentContainer implementation for the current server version,
|
|
||||||
* or null if unsupported.
|
|
||||||
*
|
|
||||||
* @return the IAnySilentContainer
|
|
||||||
*/
|
|
||||||
public IAnySilentContainer newAnySilentContainer() {
|
|
||||||
return createObject(IAnySilentContainer.class, "AnySilentContainer");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an instance of the ISpecialPlayerInventory 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 ISpecialPlayerInventory created
|
|
||||||
*/
|
|
||||||
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean online) {
|
|
||||||
return createObject(ISpecialPlayerInventory.class, "SpecialPlayerInventory", player, online);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public ISpecialEnderChest newSpecialEnderChest(Player player, boolean online) {
|
|
||||||
return createObject(ISpecialEnderChest.class, "SpecialEnderChest", player, online);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T createObject(Class<? extends T> assignableClass, String className, Object... params) {
|
|
||||||
try {
|
|
||||||
// Check if internal versioned class exists
|
|
||||||
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
|
|
||||||
if (!assignableClass.isAssignableFrom(internalClass)) {
|
|
||||||
plugin.getLogger().warning("Found class " + internalClass.getName() + " but cannot cast to " + assignableClass.getName());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 message = new StringBuilder("Found class ").append(internalClass.getName())
|
|
||||||
.append(" but cannot find any matching constructors for [");
|
|
||||||
for (Object object : params) {
|
|
||||||
message.append(object.getClass().getName()).append(", ");
|
|
||||||
}
|
|
||||||
if (params.length > 0) {
|
|
||||||
message.delete(message.length() - 2, message.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getLogger().warning(message.append(']').toString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> T grabFieldOfTypeFromObject(Class<T> type, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,38 +0,0 @@
|
|||||||
package com.lishid.openinv.util;
|
|
||||||
|
|
||||||
import org.bukkit.permissions.Permissible;
|
|
||||||
|
|
||||||
public enum Permissions {
|
|
||||||
|
|
||||||
OPENINV("OpenInv.openinv"),
|
|
||||||
OVERRIDE("OpenInv.override"),
|
|
||||||
EXEMPT("OpenInv.exempt"),
|
|
||||||
CROSSWORLD("OpenInv.crossworld"),
|
|
||||||
SILENT("OpenInv.silent"),
|
|
||||||
ANYCHEST("OpenInv.anychest"),
|
|
||||||
ENDERCHEST("OpenInv.openender"),
|
|
||||||
ENDERCHEST_ALL("OpenInv.openenderall"),
|
|
||||||
SEARCH("OpenInv.search"),
|
|
||||||
EDITINV("OpenInv.editinv"),
|
|
||||||
EDITENDER("OpenInv.editender"),
|
|
||||||
OPENSELF("OpenInv.openself");
|
|
||||||
|
|
||||||
private final String permission;
|
|
||||||
|
|
||||||
private Permissions(String permission) {
|
|
||||||
this.permission = permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPermission(Permissible permissible) {
|
|
||||||
String[] parts = permission.split("\\.");
|
|
||||||
String perm = "";
|
|
||||||
for (int i = 0; i < parts.length; i++) {
|
|
||||||
if (permissible.hasPermission(perm + "*")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
perm += parts[i] + ".";
|
|
||||||
}
|
|
||||||
return permissible.hasPermission(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_4_5</artifactId>
|
|
||||||
<name>OpenInvAdapter1_4_5</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.4.5-R1.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_5;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_5.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_4_5.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_5.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_4_6</artifactId>
|
|
||||||
<name>OpenInvAdapter1_4_6</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.4.6-R0.3</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_6;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_6.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_4_6.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,68 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvinternal</artifactId>
|
|
||||||
<name>OpenInvInternal</name>
|
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
|
|
||||||
<profiles>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>latest</id>
|
|
||||||
<modules>
|
|
||||||
<module>v1_11_R1</module>
|
|
||||||
</modules>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>modern</id>
|
|
||||||
<modules>
|
|
||||||
<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>
|
|
||||||
</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>
|
|
||||||
</modules>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_10_R1</artifactId>
|
|
||||||
<name>OpenInvAdapter1_10_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>1.10-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,209 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_10_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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.BlockChest.Type;
|
|
||||||
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.IInventory;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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 IInventory)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((BlockChest) block).g == Type.BASIC) {
|
|
||||||
player.b(StatisticList.ac);
|
|
||||||
} else if (((BlockChest) block).g == Type.TRAP) {
|
|
||||||
player.b(StatisticList.W);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
final IInventory iInventory = (IInventory) tile;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer(iInventory);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_10_R1;
|
|
||||||
|
|
||||||
import 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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_11_R1</artifactId>
|
|
||||||
<name>OpenInvAdapter1_11_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>1.11-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,276 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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.BlockChest.Type;
|
|
||||||
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.Container;
|
|
||||||
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.IInventory;
|
|
||||||
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.PacketPlayOutOpenWindow;
|
|
||||||
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 org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentContainer implements IAnySilentContainer {
|
|
||||||
|
|
||||||
@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 = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
|
|
||||||
Block block = world.getType(blockPosition).getBlock();
|
|
||||||
|
|
||||||
if (block instanceof BlockShulkerBox) {
|
|
||||||
return isBlockedShulkerBox(world, blockPosition, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
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, Block block) {
|
|
||||||
// For reference, look at net.minecraft.server.BlockShulkerBox
|
|
||||||
TileEntity tile = world.getTileEntity(blockPosition);
|
|
||||||
|
|
||||||
if (!(tile instanceof TileEntityShulkerBox)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IBlockData iBlockData = block.getBlockData();
|
|
||||||
|
|
||||||
EnumDirection enumDirection = iBlockData.get(BlockShulkerBox.a);
|
|
||||||
if (((TileEntityShulkerBox) tile).p() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
|
|
||||||
AxisAlignedBB axisAlignedBB = BlockShulkerBox.j.b(0.5F * enumDirection.getAdjacentX(),
|
|
||||||
0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
|
|
||||||
.a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
|
|
||||||
enumDirection.getAdjacentZ());
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
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 IInventory)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block block = world.getType(blockPosition).getBlock();
|
|
||||||
Container container = null;
|
|
||||||
|
|
||||||
if (block instanceof BlockChest) {
|
|
||||||
BlockChest blockChest = (BlockChest) block;
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blockChest.g == Type.BASIC) {
|
|
||||||
player.b(StatisticList.getStatistic("stat.chestOpened"));
|
|
||||||
} else if (blockChest.g == Type.TRAP) {
|
|
||||||
player.b(StatisticList.getStatistic("stat.trappedChestTriggered"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (block instanceof BlockShulkerBox) {
|
|
||||||
player.b(StatisticList.getStatistic("stat.shulkerBoxOpened"));
|
|
||||||
|
|
||||||
if (silentchest && tile instanceof TileEntityShulkerBox) {
|
|
||||||
// Set value to current + 1. Ensures consistency later when resetting.
|
|
||||||
SilentContainerShulkerBox.setOpenValue((TileEntityShulkerBox) tile,
|
|
||||||
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) + 1);
|
|
||||||
|
|
||||||
container = new SilentContainerShulkerBox(player.inventory, (IInventory) tile, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
final IInventory iInventory = (IInventory) tile;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer(iInventory);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
if (tile instanceof TileEntityShulkerBox) {
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// TODO hacky
|
|
||||||
Object tile = world.getTileEntity(blockPosition);
|
|
||||||
if (!(tile instanceof TileEntityShulkerBox)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TileEntityShulkerBox box = (TileEntityShulkerBox) tile;
|
|
||||||
// Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more.
|
|
||||||
SilentContainerShulkerBox.setOpenValue(box,
|
|
||||||
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) - 2);
|
|
||||||
}
|
|
||||||
}.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import 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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import 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.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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;
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_11_R1.ContainerChest;
|
|
||||||
import net.minecraft.server.v1_11_R1.EntityHuman;
|
|
||||||
import net.minecraft.server.v1_11_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
|
||||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
|
|
||||||
|
|
||||||
public class SilentContainerChest extends ContainerChest {
|
|
||||||
|
|
||||||
public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
|
|
||||||
EntityHuman entityHuman) {
|
|
||||||
super(playerInventory, iInventory, entityHuman);
|
|
||||||
// Send close signal
|
|
||||||
iInventory.closeContainer(entityHuman);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void b(EntityHuman entityHuman) {
|
|
||||||
// Don't send close signal twice, might screw up
|
|
||||||
PlayerInventory playerinventory = entityHuman.inventory;
|
|
||||||
|
|
||||||
if (playerinventory.getCarried() != ItemStack.a) {
|
|
||||||
ItemStack carried = playerinventory.getCarried();
|
|
||||||
playerinventory.setCarried(ItemStack.a);
|
|
||||||
entityHuman.drop(carried, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,56 +0,0 @@
|
|||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_11_R1.ContainerShulkerBox;
|
|
||||||
import net.minecraft.server.v1_11_R1.EntityHuman;
|
|
||||||
import net.minecraft.server.v1_11_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_11_R1.ItemStack;
|
|
||||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
|
|
||||||
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
|
|
||||||
|
|
||||||
public class SilentContainerShulkerBox extends ContainerShulkerBox {
|
|
||||||
|
|
||||||
private static Field fieldShulkerActionData;
|
|
||||||
|
|
||||||
public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
|
|
||||||
EntityHuman entityHuman) {
|
|
||||||
super(playerInventory, iInventory, entityHuman);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void b(EntityHuman entityHuman) {
|
|
||||||
PlayerInventory playerinventory = entityHuman.inventory;
|
|
||||||
|
|
||||||
if (!playerinventory.getCarried().isEmpty()) {
|
|
||||||
entityHuman.drop(playerinventory.getCarried(), false);
|
|
||||||
playerinventory.setCarried(ItemStack.a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
|
|
||||||
if (fieldShulkerActionData == null) {
|
|
||||||
fieldShulkerActionData = TileEntityShulkerBox.class.getDeclaredField("h");
|
|
||||||
fieldShulkerActionData.setAccessible(true);
|
|
||||||
}
|
|
||||||
return fieldShulkerActionData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setOpenValue(TileEntityShulkerBox tileShulkerBox, Object value) {
|
|
||||||
try {
|
|
||||||
exposeOpenStatus().set(tileShulkerBox, value);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Integer getOpenValue(TileEntityShulkerBox tileShulkerBox) {
|
|
||||||
try {
|
|
||||||
return (Integer) exposeOpenStatus().get(tileShulkerBox);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import 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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
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(((CraftPlayer) player).getHandle().getEnderChest().getName(),
|
|
||||||
((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
|
|
||||||
((CraftPlayer) player).getHandle().getEnderChest().getSize());
|
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
|
||||||
this.enderChest = craftPlayer.getHandle().getEnderChest();
|
|
||||||
this.bukkitOwner = craftPlayer;
|
|
||||||
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 {
|
|
||||||
this.bukkitOwner = player;
|
|
||||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
|
||||||
setItemLists(craftPlayer.getHandle().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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,261 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import 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;
|
|
||||||
// Volatile
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
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(((CraftPlayer) bukkitPlayer).getHandle());
|
|
||||||
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 = ((CraftPlayer) player).getHandle();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_4_R1</artifactId>
|
|
||||||
<name>OpenInvAdapter1_4_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.4.7-R1.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_4_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_4_R1.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_5_R2</artifactId>
|
|
||||||
<name>OpenInvAdapter1_5_R2</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.5.1-R0.2</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_5_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_5_R2.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_5_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_5_R3</artifactId>
|
|
||||||
<name>OpenInvAdapter1_5_R3</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.5.2-R1.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_5_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_5_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_5_R3.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_5_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_6_R1</artifactId>
|
|
||||||
<name>OpenInvAdapter1_6_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.6.1-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_6_R1.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_6_R2</artifactId>
|
|
||||||
<name>OpenInvAdapter1_6_R2</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.6.2-R1.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_6_R2.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_6_R3</artifactId>
|
|
||||||
<name>OpenInvAdapter1_6_R3</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.6.4-R2.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,158 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_6_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_6_R3.BlockEnderChest;
|
|
||||||
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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
|
|
||||||
|
|
||||||
if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_6_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_7_R1</artifactId>
|
|
||||||
<name>OpenInvAdapter1_7_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.7.2-R0.4</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
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.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.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if(Block.b(world.getType(block.getX(), block.getY(), block.getZ() - 1)) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (Block.b(world.getType(block.getX() + 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (Block.b(world.getType(block.getX() - 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_7_R2</artifactId>
|
|
||||||
<name>OpenInvAdapter1_7_R2</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.7.5-R0.1</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_7_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_7_R2.Block;
|
|
||||||
import net.minecraft.server.v1_7_R2.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_7_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_7_R2.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_7_R2.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_7_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_7_R2.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if(Block.b(world.getType(block.getX(), block.getY(), block.getZ() - 1)) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (Block.b(world.getType(block.getX() + 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (Block.b(world.getType(block.getX() - 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_7_R3</artifactId>
|
|
||||||
<name>OpenInvAdapter1_7_R3</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.7.9-R0.2-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_7_R3.Block;
|
|
||||||
import net.minecraft.server.v1_7_R3.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R3.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R3.IInventory;
|
|
||||||
import net.minecraft.server.v1_7_R3.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R3.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_7_R3.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_7_R3.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_7_R3.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R3.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if(Block.b(world.getType(block.getX(), block.getY(), block.getZ() - 1)) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (Block.b(world.getType(block.getX() + 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (Block.b(world.getType(block.getX() - 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_7_R4</artifactId>
|
|
||||||
<name>OpenInvAdapter1_7_R4</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot-api</artifactId>
|
|
||||||
<version>1.7.10-R0.1-snapshot</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.7.10-R0.1</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R4;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_7_R4.Block;
|
|
||||||
import net.minecraft.server.v1_7_R4.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R4.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_7_R4.IInventory;
|
|
||||||
import net.minecraft.server.v1_7_R4.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R4.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_7_R4.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_7_R4.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_7_R4.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_7_R4.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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.getId(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.getId(world.getType(block.getX(), block.getY(), block.getZ() + 1)) == id) {
|
|
||||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
|
|
||||||
} else if(Block.getId(world.getType(block.getX(), block.getY(), block.getZ() - 1)) == id) {
|
|
||||||
return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
|
|
||||||
} else if (Block.getId(world.getType(block.getX() + 1, block.getY(), block.getZ())) == id) {
|
|
||||||
return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
|
|
||||||
} else if (Block.getId(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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(block.getX(), block.getY(), block.getZ()));
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(block.getX(), block.getY(), block.getZ() + 1)) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
|
|
||||||
} else if(Block.getId(world.getType(block.getX(), block.getY(), block.getZ() - 1)) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
|
|
||||||
} else if (Block.getId(world.getType(block.getX() + 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
|
|
||||||
} else if (Block.getId(world.getType(block.getX() - 1, block.getY(), block.getZ())) == id) {
|
|
||||||
tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) tile);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) tile).getInventoryName(), ((IInventory) tile).getSize(), true));
|
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_7_R4;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_7_R4.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_8_R1</artifactId>
|
|
||||||
<name>OpenInvAdapter1_8_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>1.8-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,208 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_8_R1.Block;
|
|
||||||
import net.minecraft.server.v1_8_R1.BlockChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_8_R1.Container;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_8_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R1.EnumDirection;
|
|
||||||
import net.minecraft.server.v1_8_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_8_R1.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_8_R1.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_8_R1.TileEntity;
|
|
||||||
import net.minecraft.server.v1_8_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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()).getBlock().c();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.values()) {
|
|
||||||
if (!localEnumDirection.k().c()) {
|
|
||||||
// Not horizontal
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()).getBlock().c() || hasOcelotOnTop(world, blockPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
|
|
||||||
for (Object 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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// Silent ender chest is API-only
|
|
||||||
if (silentchest && b.getType() == Material.ENDER_CHEST) {
|
|
||||||
p.openInventory(p.getEnderChest());
|
|
||||||
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);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(tile instanceof IInventory)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block block = world.getType(blockPosition).getBlock();
|
|
||||||
Container container = null;
|
|
||||||
|
|
||||||
if (block instanceof BlockChest) {
|
|
||||||
for (EnumDirection localEnumDirection : EnumDirection.values()) {
|
|
||||||
if (!localEnumDirection.k().c()) {
|
|
||||||
// Not horizontal
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
final IInventory iInventory = (IInventory) tile;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer(iInventory);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_8_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_8_R2</artifactId>
|
|
||||||
<name>OpenInvAdapter1_8_R2</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>1.8.3-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,208 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_8_R2.Block;
|
|
||||||
import net.minecraft.server.v1_8_R2.BlockChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_8_R2.Container;
|
|
||||||
import net.minecraft.server.v1_8_R2.Entity;
|
|
||||||
import net.minecraft.server.v1_8_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_8_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R2.EnumDirection;
|
|
||||||
import net.minecraft.server.v1_8_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_8_R2.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_8_R2.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_8_R2.StatisticList;
|
|
||||||
import net.minecraft.server.v1_8_R2.TileEntity;
|
|
||||||
import net.minecraft.server.v1_8_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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()).getBlock().c();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()).getBlock().c() || 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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// Silent ender chest is pretty much API-only
|
|
||||||
if (silentchest && b.getType() == Material.ENDER_CHEST) {
|
|
||||||
p.openInventory(p.getEnderChest());
|
|
||||||
player.b(StatisticList.V);
|
|
||||||
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.V);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(tile instanceof IInventory)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((BlockChest) block).b == 0) {
|
|
||||||
player.b(StatisticList.aa);
|
|
||||||
} else if (((BlockChest) block).b == 1) {
|
|
||||||
player.b(StatisticList.U);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
final IInventory iInventory = (IInventory) tile;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer(iInventory);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_8_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_8_R3</artifactId>
|
|
||||||
<name>OpenInvAdapter1_8_R3</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,208 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R3;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_8_R3.Block;
|
|
||||||
import net.minecraft.server.v1_8_R3.BlockChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_8_R3.Container;
|
|
||||||
import net.minecraft.server.v1_8_R3.Entity;
|
|
||||||
import net.minecraft.server.v1_8_R3.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_8_R3.EnumDirection;
|
|
||||||
import net.minecraft.server.v1_8_R3.IInventory;
|
|
||||||
import net.minecraft.server.v1_8_R3.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_8_R3.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_8_R3.StatisticList;
|
|
||||||
import net.minecraft.server.v1_8_R3.TileEntity;
|
|
||||||
import net.minecraft.server.v1_8_R3.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_8_R3.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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()).getBlock().c();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()).getBlock().c() || 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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// Silent ender chest is pretty much API-only
|
|
||||||
if (silentchest && b.getType() == Material.ENDER_CHEST) {
|
|
||||||
p.openInventory(p.getEnderChest());
|
|
||||||
player.b(StatisticList.V);
|
|
||||||
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.V);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(tile instanceof IInventory)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((BlockChest) block).b == 0) {
|
|
||||||
player.b(StatisticList.aa);
|
|
||||||
} else if (((BlockChest) block).b == 1) {
|
|
||||||
player.b(StatisticList.U);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
final IInventory iInventory = (IInventory) tile;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer(iInventory);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_8_R3.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_9_R1</artifactId>
|
|
||||||
<name>OpenInvAdapter1_9_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>1.9-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@@ -1,208 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R1;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_9_R1.Block;
|
|
||||||
import net.minecraft.server.v1_9_R1.BlockChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_9_R1.Container;
|
|
||||||
import net.minecraft.server.v1_9_R1.Entity;
|
|
||||||
import net.minecraft.server.v1_9_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_9_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_9_R1.EnumDirection;
|
|
||||||
import net.minecraft.server.v1_9_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_9_R1.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_9_R1.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_9_R1.StatisticList;
|
|
||||||
import net.minecraft.server.v1_9_R1.TileEntity;
|
|
||||||
import net.minecraft.server.v1_9_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_9_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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 IInventory)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((BlockChest) block).g == BlockChest.Type.BASIC)
|
|
||||||
player.b(StatisticList.ac);
|
|
||||||
else if (((BlockChest) block).g == BlockChest.Type.TRAP) {
|
|
||||||
player.b(StatisticList.W);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
final IInventory iInventory = (IInventory) tile;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer(iInventory);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R1.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory;
|
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvadapter1_9_R2</artifactId>
|
|
||||||
<name>OpenInvAdapter1_9_R2</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot</artifactId>
|
|
||||||
<version>1.9.4-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,208 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R2;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R2.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_9_R2.Block;
|
|
||||||
import net.minecraft.server.v1_9_R2.BlockChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.BlockEnderChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_9_R2.Container;
|
|
||||||
import net.minecraft.server.v1_9_R2.Entity;
|
|
||||||
import net.minecraft.server.v1_9_R2.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_9_R2.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_9_R2.EnumDirection;
|
|
||||||
import net.minecraft.server.v1_9_R2.IInventory;
|
|
||||||
import net.minecraft.server.v1_9_R2.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_9_R2.InventoryEnderChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_9_R2.StatisticList;
|
|
||||||
import net.minecraft.server.v1_9_R2.TileEntity;
|
|
||||||
import net.minecraft.server.v1_9_R2.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.TileEntityEnderChest;
|
|
||||||
import net.minecraft.server.v1_9_R2.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
|
||||||
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
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 = ((CraftPlayer) p).getHandle();
|
|
||||||
|
|
||||||
// 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 IInventory)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)) {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(TileEntityChest) localTileEntity, (ITileInventory) tile);
|
|
||||||
} else {
|
|
||||||
tile = new InventoryLargeChest("container.chestDouble",
|
|
||||||
(ITileInventory) tile, (TileEntityChest) localTileEntity);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (silentchest) {
|
|
||||||
container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((BlockChest) block).g == BlockChest.Type.BASIC) {
|
|
||||||
player.b(StatisticList.ac);
|
|
||||||
} else if (((BlockChest) block).g == BlockChest.Type.TRAP) {
|
|
||||||
player.b(StatisticList.W);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean returnValue = false;
|
|
||||||
final IInventory iInventory = (IInventory) tile;
|
|
||||||
|
|
||||||
if (!silentchest || container == null) {
|
|
||||||
player.openContainer(iInventory);
|
|
||||||
returnValue = true;
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
int windowId = player.nextContainerCounter();
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
|
|
||||||
player.activeContainer = container;
|
|
||||||
player.activeContainer.windowId = windowId;
|
|
||||||
player.activeContainer.addSlotListener(player);
|
|
||||||
returnValue = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_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;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_9_R2.IInventory;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
<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>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvplugincore</artifactId>
|
|
||||||
<name>OpenInvPluginCore</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>bukkit</artifactId>
|
|
||||||
<version>1.4.5-R1.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvpluginv1_10_r1</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,118 +0,0 @@
|
|||||||
package com.lishid.openinv.commands;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Command adding the ability to search online players' inventories for enchantments of a specific
|
|
||||||
* type at or above the level specified.
|
|
||||||
*
|
|
||||||
* @author Jikoo
|
|
||||||
*/
|
|
||||||
public class SearchEnchantPluginCommand implements CommandExecutor {
|
|
||||||
|
|
||||||
private final OpenInv plugin;
|
|
||||||
|
|
||||||
public SearchEnchantPluginCommand(OpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
if (args.length == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Enchantment enchant = null;
|
|
||||||
int level = 0;
|
|
||||||
|
|
||||||
for (String argument : args) {
|
|
||||||
Enchantment localEnchant = Enchantment.getByName(argument.toUpperCase());
|
|
||||||
if (localEnchant != null) {
|
|
||||||
enchant = localEnchant;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
level = Integer.parseInt(argument);
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Arguments not set correctly
|
|
||||||
if (level == 0 && enchant == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder players = new StringBuilder();
|
|
||||||
for (Player player : plugin.getOnlinePlayers()) {
|
|
||||||
boolean flagInventory = containsEnchantment(player.getInventory(), enchant, level);
|
|
||||||
boolean flagEnder = containsEnchantment(player.getEnderChest(), enchant, level);
|
|
||||||
|
|
||||||
// No matches, continue
|
|
||||||
if (!flagInventory && !flagEnder) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Matches, append details
|
|
||||||
players.append(player.getName()).append(" (");
|
|
||||||
if (flagInventory) {
|
|
||||||
players.append("inv");
|
|
||||||
}
|
|
||||||
if (flagEnder) {
|
|
||||||
if (flagInventory) {
|
|
||||||
players.append(',');
|
|
||||||
}
|
|
||||||
players.append("ender");
|
|
||||||
}
|
|
||||||
players.append("), ");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (players.length() > 0) {
|
|
||||||
// Matches found, delete trailing comma and space
|
|
||||||
players.delete(players.length() - 2, players.length());
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("No players found with " + (enchant == null ? "any enchant" : enchant.getName())
|
|
||||||
+ " of level " + level + " or higher.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage("Players: " + players.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean containsEnchantment(Inventory inventory, Enchantment enchant, int minLevel) {
|
|
||||||
for (ItemStack item : inventory.getContents()) {
|
|
||||||
if (item == null || item.getType() == Material.AIR) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (enchant != null) {
|
|
||||||
if (item.containsEnchantment(enchant) && item.getEnchantmentLevel(enchant) >= minLevel) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!item.hasItemMeta()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
if (!meta.hasEnchants()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (int enchLevel : meta.getEnchants().values()) {
|
|
||||||
if (enchLevel >= minLevel) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.listeners;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
import com.lishid.openinv.util.Permissions;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Event.Result;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
|
||||||
|
|
||||||
private final OpenInv plugin;
|
|
||||||
|
|
||||||
public PlayerListener(OpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
|
||||||
plugin.setPlayerOnline(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
plugin.setPlayerOffline(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onWorldChange(PlayerChangedWorldEvent event) {
|
|
||||||
plugin.changeWorld(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking()
|
|
||||||
|| event.useInteractedBlock() == Result.DENY
|
|
||||||
|| !plugin.getAnySilentContainer().isAnySilentContainer(event.getClickedBlock())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
boolean anychest = Permissions.ANYCHEST.hasPermission(player) && plugin.getPlayerAnyChestStatus(player);
|
|
||||||
boolean needsAnyChest = plugin.getAnySilentContainer().isAnyContainerNeeded(player, event.getClickedBlock());
|
|
||||||
|
|
||||||
if (!anychest && needsAnyChest) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean silentchest = Permissions.SILENT.hasPermission(player) && plugin.getPlayerSilentChestStatus(player);
|
|
||||||
|
|
||||||
// If anychest or silentchest is active
|
|
||||||
if ((anychest || silentchest) && plugin.getAnySilentContainer().activateContainer(player, silentchest, event.getClickedBlock())) {
|
|
||||||
if (silentchest && plugin.notifySilentChest() && needsAnyChest && plugin.notifyAnyChest()) {
|
|
||||||
player.sendMessage("You are opening a blocked container silently.");
|
|
||||||
} else if (silentchest && plugin.notifySilentChest()) {
|
|
||||||
player.sendMessage("You are opening a container silently.");
|
|
||||||
} else if (needsAnyChest && plugin.notifyAnyChest()) {
|
|
||||||
player.sendMessage("You are opening a blocked container.");
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
package com.lishid.openinv.listeners;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listener for plugin-related events.
|
|
||||||
*
|
|
||||||
* @author Jikoo
|
|
||||||
*/
|
|
||||||
public class PluginListener implements Listener {
|
|
||||||
|
|
||||||
private final OpenInv plugin;
|
|
||||||
|
|
||||||
public PluginListener(OpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPluginDisable(PluginDisableEvent event) {
|
|
||||||
plugin.releaseAllPlayers(event.getPlugin());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,154 +0,0 @@
|
|||||||
package com.lishid.openinv.util;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public class ConfigUpdater {
|
|
||||||
|
|
||||||
private static final int CONFIG_VERSION = 3;
|
|
||||||
|
|
||||||
private final OpenInv plugin;
|
|
||||||
|
|
||||||
public ConfigUpdater(OpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkForUpdates() {
|
|
||||||
final int version = plugin.getConfig().getInt("config-version", 1);
|
|
||||||
if (version >= CONFIG_VERSION) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getLogger().info("Configuration update found! Performing update...");
|
|
||||||
|
|
||||||
// Backup the old config file
|
|
||||||
try {
|
|
||||||
plugin.getConfig().save(new File(plugin.getDataFolder(), "config_old.yml"));
|
|
||||||
plugin.getLogger().info("Backed up config.yml to config_old.yml before updating.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
plugin.getLogger().warning("Could not back up config.yml before updating!");
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
switch (version) {
|
|
||||||
case 1:
|
|
||||||
updateConfig1To2();
|
|
||||||
case 2:
|
|
||||||
updateConfig2To3();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
plugin.saveConfig();
|
|
||||||
plugin.getLogger().info("Configuration update complete!");
|
|
||||||
}
|
|
||||||
}.runTaskLater(plugin, 1L); // Run on 1 tick delay; on older versions Bukkit's scheduler is not guaranteed FIFO
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateConfig2To3() {
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
plugin.getConfig().set("config-version", 3);
|
|
||||||
plugin.getConfig().set("items.open-inv", null);
|
|
||||||
plugin.getConfig().set("toggles.items.open-inv", null);
|
|
||||||
plugin.getConfig().set("settings.disable-saving",
|
|
||||||
plugin.getConfig().getBoolean("DisableSaving", false));
|
|
||||||
plugin.getConfig().set("DisableSaving", null);
|
|
||||||
}
|
|
||||||
}.runTask(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateConfig1To2() {
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Get the old config settings
|
|
||||||
int itemOpenInvItemId = plugin.getConfig().getInt("ItemOpenInvItemID", 280);
|
|
||||||
boolean notifySilentChest = plugin.getConfig().getBoolean("NotifySilentChest", true);
|
|
||||||
boolean notifyAnyChest = plugin.getConfig().getBoolean("NotifyAnyChest", true);
|
|
||||||
plugin.getConfig().set("ItemOpenInvItemID", null);
|
|
||||||
plugin.getConfig().set("NotifySilentChest", null);
|
|
||||||
plugin.getConfig().set("NotifyAnyChest", null);
|
|
||||||
plugin.getConfig().set("config-version", 2);
|
|
||||||
plugin.getConfig().set("items.open-inv",
|
|
||||||
getMaterialById(itemOpenInvItemId).toString());
|
|
||||||
plugin.getConfig().set("notify.any-chest", notifyAnyChest);
|
|
||||||
plugin.getConfig().set("notify.silent-chest", notifySilentChest);
|
|
||||||
}
|
|
||||||
}.runTask(plugin);
|
|
||||||
|
|
||||||
updateToggles("AnyChest", ".toggle", "toggles.any-chest");
|
|
||||||
updateToggles("ItemOpenInv", ".toggle", "toggles.items.open-inv");
|
|
||||||
updateToggles("SilentChest", ".toggle", "toggles.silent-chest");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateToggles(final String sectionName, String suffix, final String newSectionName) {
|
|
||||||
// Ensure section exists
|
|
||||||
if (!plugin.getConfig().isConfigurationSection(sectionName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName);
|
|
||||||
Set<String> keys = section.getKeys(false);
|
|
||||||
|
|
||||||
// Ensure section has content
|
|
||||||
if (keys == null || keys.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Map<String, Boolean> toggles = new HashMap<String, Boolean>();
|
|
||||||
|
|
||||||
for (String playerName : keys) {
|
|
||||||
OfflinePlayer player = plugin.matchPlayer(playerName);
|
|
||||||
String dataID = plugin.getPlayerID(player);
|
|
||||||
toggles.put(dataID, section.getBoolean(playerName + suffix, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Wipe old ConfigurationSection
|
|
||||||
plugin.getConfig().set(sectionName, null);
|
|
||||||
|
|
||||||
// Prepare new ConfigurationSection
|
|
||||||
ConfigurationSection newSection;
|
|
||||||
if (plugin.getConfig().isConfigurationSection(newSectionName)) {
|
|
||||||
newSection = plugin.getConfig().getConfigurationSection(newSectionName);
|
|
||||||
} else {
|
|
||||||
newSection = plugin.getConfig().createSection(newSectionName);
|
|
||||||
}
|
|
||||||
// Set new values
|
|
||||||
for (Map.Entry<String, Boolean> entry : toggles.entrySet()) {
|
|
||||||
newSection.set(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.runTask(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Material getMaterialById(int id) {
|
|
||||||
Material material = Material.getMaterial(id);
|
|
||||||
|
|
||||||
if (material == null) {
|
|
||||||
material = Material.STICK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
name: OpenInv
|
|
||||||
main: com.lishid.openinv.OpenInv
|
|
||||||
version: ${openinv.version}
|
|
||||||
author: lishid
|
|
||||||
authors: [Jikoo, ShadowRanger]
|
|
||||||
description: >
|
|
||||||
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
|
|
||||||
commands:
|
|
||||||
openinv:
|
|
||||||
aliases: [oi, inv, open]
|
|
||||||
description: Open a player's inventory
|
|
||||||
permission: OpenInv.*;OpenInv.openinv
|
|
||||||
usage: |-
|
|
||||||
/<command> [Player] - Open a player's inventory
|
|
||||||
openender:
|
|
||||||
aliases: [oe]
|
|
||||||
description: Opens the enderchest of a player
|
|
||||||
permission: OpenInv.*;OpenInv.openender
|
|
||||||
usage: |-
|
|
||||||
/<command> [Player] - Open a player's enderchest
|
|
||||||
searchinv:
|
|
||||||
aliases: [si]
|
|
||||||
description: Search and list players having a specific item
|
|
||||||
permission: OpenInv.*;OpenInv.search
|
|
||||||
usage: |-
|
|
||||||
/<command> <Item> [MinAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required
|
|
||||||
searchender:
|
|
||||||
aliases: [se]
|
|
||||||
permission: OpenInv.*;OpenInv.search
|
|
||||||
description: Searches and lists players having a specific item in their ender chest
|
|
||||||
usage: |-
|
|
||||||
/<command> <item> [MinAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required
|
|
||||||
silentchest:
|
|
||||||
aliases: [sc, silent]
|
|
||||||
description: Toggle silent chest function, which stops sounds and animations when using containers.
|
|
||||||
permission: OpenInv.*;OpenInv.silent
|
|
||||||
usage: |-
|
|
||||||
/<command> [Check] - Check or toggle silent chest
|
|
||||||
anychest:
|
|
||||||
aliases: [ac]
|
|
||||||
description: Toggle anychest function, which allows opening of blocked chests.
|
|
||||||
permission: OpenInv.*;OpenInv.anychest
|
|
||||||
usage: |-
|
|
||||||
/<command> [Check] - Checks or toggle anychest
|
|
||||||
searchenchant:
|
|
||||||
aliases: [searchenchants]
|
|
||||||
description: Search and list players with a specific enchantment.
|
|
||||||
permission: OpenInv.*;OpenInv.searchenchant
|
|
||||||
usage: |-
|
|
||||||
/<command> <[enchantment] [MinLevel]> - Enchantment is the enchantment type, MinLevel is the minimum level. One is optional
|
|
@@ -1,28 +0,0 @@
|
|||||||
<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>openinvplugin</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvpluginv1_10_r1</artifactId>
|
|
||||||
<name>OpenInvPluginv1_10_R1</name>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>bukkit</artifactId>
|
|
||||||
<version>1.10-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.lishid</groupId>
|
|
||||||
<artifactId>openinvcommon</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@@ -1,38 +0,0 @@
|
|||||||
package com.lishid.openinv.listeners;
|
|
||||||
|
|
||||||
import com.lishid.openinv.IOpenInv;
|
|
||||||
import com.lishid.openinv.util.Permissions;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listener for InventoryDragEvents to prevent unpermitted modification of special inventories.
|
|
||||||
*
|
|
||||||
* @author Jikoo
|
|
||||||
*/
|
|
||||||
public class InventoryDragListener implements Listener {
|
|
||||||
|
|
||||||
private final IOpenInv plugin;
|
|
||||||
|
|
||||||
public InventoryDragListener(IOpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
|
||||||
public void onInventoryDrag(InventoryDragEvent event) {
|
|
||||||
HumanEntity entity = event.getWhoClicked();
|
|
||||||
Inventory inventory = event.getInventory();
|
|
||||||
if (plugin.getInventoryAccess().isSpecialPlayerInventory(inventory)
|
|
||||||
&& !Permissions.EDITINV.hasPermission(entity)
|
|
||||||
|| plugin.getInventoryAccess().isSpecialEnderChest(inventory)
|
|
||||||
&& !Permissions.EDITENDER.hasPermission(entity)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,21 +0,0 @@
|
|||||||
<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>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>openinvplugin</artifactId>
|
|
||||||
<name>OpenInvPlugin</name>
|
|
||||||
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
|
|
||||||
<modules>
|
|
||||||
<module>plugin-v1_10_R1</module>
|
|
||||||
<module>plugin-core</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
</project>
|
|
229
pom.xml
229
pom.xml
@@ -1,100 +1,150 @@
|
|||||||
<?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">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>OpenInv</groupId>
|
||||||
|
<artifactId>OpenInv</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<groupId>com.lishid</groupId>
|
<dependencies>
|
||||||
<artifactId>openinvparent</artifactId>
|
<dependency>
|
||||||
<name>OpenInvParent</name>
|
<groupId>org.spigotmc</groupId>
|
||||||
<url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
|
<artifactId>spigot</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.10-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
<packaging>pom</packaging>
|
<classifier>v1_10_R1</classifier>
|
||||||
|
</dependency>
|
||||||
<properties>
|
<dependency>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<groupId>org.spigotmc</groupId>
|
||||||
<openinv.version>3.0.6-SNAPSHOT</openinv.version>
|
<artifactId>spigot</artifactId>
|
||||||
</properties>
|
<version>1.9.4-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
<modules>
|
<classifier>v1_9_R2</classifier>
|
||||||
<module>api</module>
|
</dependency>
|
||||||
<module>common</module>
|
<dependency>
|
||||||
<module>plugin</module>
|
<groupId>org.spigotmc</groupId>
|
||||||
<module>internal</module>
|
<artifactId>spigot</artifactId>
|
||||||
<module>assembly</module>
|
<version>1.9-R0.1-SNAPSHOT</version>
|
||||||
</modules>
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_9_R1</classifier>
|
||||||
<profiles>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
<!--
|
<groupId>org.spigotmc</groupId>
|
||||||
~ N.B.: All version-specific code is handled in submodules of the internal module.
|
<artifactId>spigot</artifactId>
|
||||||
~
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
~ Internal submodules built by each profile are handled in internal/pom.xml
|
<scope>provided</scope>
|
||||||
-->
|
<classifier>v1_8_R3</classifier>
|
||||||
|
</dependency>
|
||||||
<profile>
|
<dependency>
|
||||||
<id>all</id>
|
<groupId>org.spigotmc</groupId>
|
||||||
<activation>
|
<artifactId>spigot</artifactId>
|
||||||
<activeByDefault>true</activeByDefault>
|
<version>1.8.3-R0.1-SNAPSHOT</version>
|
||||||
</activation>
|
<scope>provided</scope>
|
||||||
</profile>
|
<classifier>v1_8_R2</classifier>
|
||||||
|
</dependency>
|
||||||
<profile>
|
<dependency>
|
||||||
<id>latest</id>
|
<groupId>org.spigotmc</groupId>
|
||||||
<activation>
|
<artifactId>spigot</artifactId>
|
||||||
<property>
|
<version>1.8-R0.1-SNAPSHOT</version>
|
||||||
<name>latest</name>
|
<scope>provided</scope>
|
||||||
<value>true</value>
|
<classifier>v1_8_R1</classifier>
|
||||||
</property>
|
</dependency>
|
||||||
</activation>
|
<dependency>
|
||||||
</profile>
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
<profile>
|
<version>1.7.10-R0.1-SNAPSHOT</version>
|
||||||
<id>modern</id>
|
<scope>provided</scope>
|
||||||
<activation>
|
<classifier>v1_7_R4</classifier>
|
||||||
<property>
|
</dependency>
|
||||||
<name>modern</name>
|
<dependency>
|
||||||
<value>true</value>
|
<groupId>org.bukkit</groupId>
|
||||||
</property>
|
<artifactId>craftbukkit</artifactId>
|
||||||
</activation>
|
<version>1.7.9-R0.2-SNAPSHOT</version>
|
||||||
</profile>
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_7_R3</classifier>
|
||||||
</profiles>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
<repositories>
|
<groupId>org.bukkit</groupId>
|
||||||
<repository>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<id>spigot-repo</id>
|
<version>1.7.5-R0.1-SNAPSHOT</version>
|
||||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
<scope>provided</scope>
|
||||||
</repository>
|
<classifier>v1_7_R2</classifier>
|
||||||
</repositories>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.7.2-R0.4-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_7_R1</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.6.4-R2.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_6_R3</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.6.2-R1.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_6_R2</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.6.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_6_R1</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.5.2-R1.0-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_5_R3</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.5.1-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_5_R2</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.5-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_5_R1</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.4.7-R1.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_4_R1</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.4.6-R0.4-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_4_6</classifier>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>craftbukkit</artifactId>
|
||||||
|
<version>1.4.5-R1.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<classifier>v1_4_5</classifier>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>2.4.3</version>
|
|
||||||
<configuration>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<!-- Keep the file clean, don't include every single pom from all modules -->
|
|
||||||
<excludes>META-INF/maven/**</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.5.1</version>
|
<version>3.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.6</source>
|
<source>1.6</source>
|
||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
@@ -102,5 +152,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -16,13 +16,7 @@
|
|||||||
|
|
||||||
package com.lishid.openinv;
|
package com.lishid.openinv;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@@ -31,34 +25,25 @@ import java.util.concurrent.Future;
|
|||||||
import com.lishid.openinv.commands.AnyChestPluginCommand;
|
import com.lishid.openinv.commands.AnyChestPluginCommand;
|
||||||
import com.lishid.openinv.commands.OpenEnderPluginCommand;
|
import com.lishid.openinv.commands.OpenEnderPluginCommand;
|
||||||
import com.lishid.openinv.commands.OpenInvPluginCommand;
|
import com.lishid.openinv.commands.OpenInvPluginCommand;
|
||||||
import com.lishid.openinv.commands.SearchEnchantPluginCommand;
|
|
||||||
import com.lishid.openinv.commands.SearchInvPluginCommand;
|
import com.lishid.openinv.commands.SearchInvPluginCommand;
|
||||||
import com.lishid.openinv.commands.SilentChestPluginCommand;
|
import com.lishid.openinv.commands.SilentChestPluginCommand;
|
||||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
import com.lishid.openinv.internal.IAnySilentChest;
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
import com.lishid.openinv.listeners.InventoryClickListener;
|
import com.lishid.openinv.internal.InternalAccessor;
|
||||||
import com.lishid.openinv.listeners.InventoryDragListener;
|
|
||||||
import com.lishid.openinv.listeners.PlayerListener;
|
|
||||||
import com.lishid.openinv.listeners.PluginListener;
|
|
||||||
import com.lishid.openinv.util.Cache;
|
import com.lishid.openinv.util.Cache;
|
||||||
import com.lishid.openinv.util.ConfigUpdater;
|
|
||||||
import com.lishid.openinv.util.Function;
|
import com.lishid.openinv.util.Function;
|
||||||
import com.lishid.openinv.util.InternalAccessor;
|
|
||||||
import com.lishid.openinv.util.Permissions;
|
|
||||||
|
|
||||||
import com.google.common.collect.HashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.permissions.Permissible;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@@ -68,20 +53,17 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
*
|
*
|
||||||
* @author lishid
|
* @author lishid
|
||||||
*/
|
*/
|
||||||
public class OpenInv extends JavaPlugin implements IOpenInv {
|
public class OpenInv extends JavaPlugin {
|
||||||
|
|
||||||
private final Map<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
|
private final Map<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
|
||||||
private final Map<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
|
private final Map<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
|
||||||
private final Multimap<String, Class<? extends Plugin>> pluginUsage = HashMultimap.create();
|
|
||||||
|
|
||||||
private final Cache<String, Player> playerCache = new Cache<String, Player>(300000L,
|
private final Cache<String, Player> playerCache = new Cache<String, Player>(300000L,
|
||||||
new Function<Player>() {
|
new Function<Player>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean run(Player value) {
|
public boolean run(Player value) {
|
||||||
String key = playerLoader.getPlayerDataID(value);
|
String key = playerLoader.getPlayerDataID(value);
|
||||||
return inventories.containsKey(key) && inventories.get(key).isInUse()
|
return inventories.containsKey(key) && inventories.get(key).isInUse()
|
||||||
|| enderChests.containsKey(key) && enderChests.get(key).isInUse()
|
|| enderChests.containsKey(key) && enderChests.get(key).isInUse();
|
||||||
|| pluginUsage.containsKey(key);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new Function<Player>() {
|
new Function<Player>() {
|
||||||
@@ -115,7 +97,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
private InternalAccessor accessor;
|
private InternalAccessor accessor;
|
||||||
private IPlayerDataManager playerLoader;
|
private IPlayerDataManager playerLoader;
|
||||||
private IInventoryAccess inventoryAccess;
|
private IInventoryAccess inventoryAccess;
|
||||||
private IAnySilentContainer anySilentContainer;
|
private IAnySilentChest anySilentChest;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -124,8 +106,8 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
|
|
||||||
accessor = new InternalAccessor(this);
|
accessor = new InternalAccessor(this);
|
||||||
// Version check
|
// Version check
|
||||||
if (!accessor.isSupported()) {
|
if (!accessor.initialize(getServer())) {
|
||||||
getLogger().info("Your version of CraftBukkit (" + accessor.getVersion() + ") is not supported.");
|
getLogger().info("Your version of CraftBukkit is not supported.");
|
||||||
getLogger().info("Please look for an updated version of OpenInv.");
|
getLogger().info("Please look for an updated version of OpenInv.");
|
||||||
pm.disablePlugin(this);
|
pm.disablePlugin(this);
|
||||||
return;
|
return;
|
||||||
@@ -133,26 +115,38 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
|
|
||||||
playerLoader = accessor.newPlayerDataManager();
|
playerLoader = accessor.newPlayerDataManager();
|
||||||
inventoryAccess = accessor.newInventoryAccess();
|
inventoryAccess = accessor.newInventoryAccess();
|
||||||
anySilentContainer = accessor.newAnySilentContainer();
|
anySilentChest = accessor.newAnySilentChest();
|
||||||
|
|
||||||
new ConfigUpdater(this).checkForUpdates();
|
FileConfiguration config = getConfig();
|
||||||
|
boolean dirtyConfig = false;
|
||||||
|
if (!config.isBoolean("NotifySilentChest")) {
|
||||||
|
config.set("NotifySilentChest", true);
|
||||||
|
dirtyConfig = true;
|
||||||
|
}
|
||||||
|
if (!config.isBoolean("NotifyAnyChest")) {
|
||||||
|
config.set("NotifyAnyChest", true);
|
||||||
|
dirtyConfig = true;
|
||||||
|
}
|
||||||
|
if (!config.isBoolean("DisableSaving")) {
|
||||||
|
config.set("DisableSaving", false);
|
||||||
|
dirtyConfig = true;
|
||||||
|
}
|
||||||
|
config.addDefault("NotifySilentChest", true);
|
||||||
|
config.addDefault("NotifyAnyChest", true);
|
||||||
|
config.addDefault("DisableSaving", false);
|
||||||
|
config.options().copyDefaults(true);
|
||||||
|
if (dirtyConfig) {
|
||||||
|
saveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
// Register listeners
|
pm.registerEvents(new OpenInvPlayerListener(this), this);
|
||||||
pm.registerEvents(new PlayerListener(this), this);
|
pm.registerEvents(new OpenInvInventoryListener(this), this);
|
||||||
pm.registerEvents(new PluginListener(this), this);
|
|
||||||
pm.registerEvents(new InventoryClickListener(this), this);
|
|
||||||
// Bukkit will handle missing events for us, attempt to register InventoryDragEvent without a version check
|
|
||||||
pm.registerEvents(new InventoryDragListener(this), this);
|
|
||||||
|
|
||||||
// Register commands to their executors
|
|
||||||
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
||||||
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
|
getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
|
||||||
SearchInvPluginCommand searchInv = new SearchInvPluginCommand(this);
|
|
||||||
getCommand("searchinv").setExecutor(searchInv);
|
|
||||||
getCommand("searchender").setExecutor(searchInv);
|
|
||||||
getCommand("searchenchant").setExecutor(new SearchEnchantPluginCommand(this));
|
|
||||||
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
|
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
|
||||||
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
|
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
|
||||||
|
getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,47 +160,15 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
this.playerCache.invalidateAll();
|
this.playerCache.invalidateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the server version is supported by OpenInv.
|
|
||||||
*
|
|
||||||
* @return true if the server version is supported
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isSupportedVersion() {
|
|
||||||
return this.accessor != null && this.accessor.isSupported();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the active IInventoryAccess implementation. May return null if the server version is
|
|
||||||
* unsupported.
|
|
||||||
*
|
|
||||||
* @return the IInventoryAccess
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IInventoryAccess getInventoryAccess() {
|
public IInventoryAccess getInventoryAccess() {
|
||||||
return this.inventoryAccess;
|
return this.inventoryAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public IAnySilentChest getAnySilentChest() {
|
||||||
* Gets the active ISilentContainer implementation. May return null if the server version is
|
return this.anySilentChest;
|
||||||
* unsupported.
|
|
||||||
*
|
|
||||||
* @return the ISilentContainer
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public IAnySilentContainer getAnySilentContainer() {
|
|
||||||
return this.anySilentContainer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ISpecialPlayerInventory getInventoryFor(Player player, boolean online) {
|
||||||
* Gets an ISpecialPlayerInventory for the given Player.
|
|
||||||
*
|
|
||||||
* @param player the Player
|
|
||||||
* @param online true if the Player is currently online
|
|
||||||
* @return the ISpecialPlayerInventory
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ISpecialPlayerInventory getInventory(Player player, boolean online) {
|
|
||||||
String id = playerLoader.getPlayerDataID(player);
|
String id = playerLoader.getPlayerDataID(player);
|
||||||
if (inventories.containsKey(id)) {
|
if (inventories.containsKey(id)) {
|
||||||
return inventories.get(id);
|
return inventories.get(id);
|
||||||
@@ -217,15 +179,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ISpecialEnderChest getEnderChestFor(Player player, boolean online) {
|
||||||
* Gets an ISpecialEnderChest for the given Player.
|
|
||||||
*
|
|
||||||
* @param player the Player
|
|
||||||
* @param online true if the Player is currently online
|
|
||||||
* @return the ISpecialEnderChest
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ISpecialEnderChest getEnderChest(Player player, boolean online) {
|
|
||||||
String id = playerLoader.getPlayerDataID(player);
|
String id = playerLoader.getPlayerDataID(player);
|
||||||
if (enderChests.containsKey(id)) {
|
if (enderChests.containsKey(id)) {
|
||||||
return enderChests.get(id);
|
return enderChests.get(id);
|
||||||
@@ -237,119 +191,50 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forcibly unload a cached Player's data.
|
* Unload a cached Player's data.
|
||||||
*
|
*
|
||||||
* @param player the OfflinePlayer to unload
|
* @param player the OfflinePlayer to unload
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void unload(OfflinePlayer player) {
|
public void unload(OfflinePlayer player) {
|
||||||
this.playerCache.invalidate(this.playerLoader.getPlayerDataID(player));
|
this.playerCache.invalidate(this.playerLoader.getPlayerDataID(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean disableSaving() {
|
public boolean disableSaving() {
|
||||||
return getConfig().getBoolean("settings.disable-saving", false);
|
return getConfig().getBoolean("DisableSaving", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean notifySilentChest() {
|
public boolean notifySilentChest() {
|
||||||
return getConfig().getBoolean("notify.silent-chest", true);
|
return getConfig().getBoolean("NotifySilentChest", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean notifyAnyChest() {
|
public boolean notifyAnyChest() {
|
||||||
return getConfig().getBoolean("notify.any-chest", true);
|
return getConfig().getBoolean("NotifyAnyChest", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a player's SilentChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @return true if SilentChest is enabled
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean getPlayerSilentChestStatus(OfflinePlayer player) {
|
public boolean getPlayerSilentChestStatus(OfflinePlayer player) {
|
||||||
return getConfig().getBoolean("toggles.silent-chest." + playerLoader.getPlayerDataID(player), false);
|
return getConfig().getBoolean("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a player's SilentChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @param status the status
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status) {
|
public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status) {
|
||||||
getConfig().set("toggles.silent-chest." + playerLoader.getPlayerDataID(player), status);
|
getConfig().set("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the provided player's AnyChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @return true if AnyChest is enabled
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean getPlayerAnyChestStatus(OfflinePlayer player) {
|
public boolean getPlayerAnyChestStatus(OfflinePlayer player) {
|
||||||
return getConfig().getBoolean("toggles.any-chest." + playerLoader.getPlayerDataID(player), false);
|
return getConfig().getBoolean("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a player's AnyChest setting.
|
|
||||||
*
|
|
||||||
* @param player the OfflinePlayer
|
|
||||||
* @param status the status
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status) {
|
public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status) {
|
||||||
getConfig().set("toggles.any-chest." + playerLoader.getPlayerDataID(player), status);
|
getConfig().set("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getPlayerID(OfflinePlayer offline) {
|
|
||||||
return this.playerLoader.getPlayerDataID(offline);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an OfflinePlayer by name.
|
* 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
|
* @param name the name of the Player
|
||||||
* @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
|
* @return the OfflinePlayer, or null if no players have ever logged in
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public OfflinePlayer matchPlayer(String name) {
|
public OfflinePlayer matchPlayer(String name) {
|
||||||
|
|
||||||
// Warn if called on the main thread - if we resort to searching offline players, this may take several seconds.
|
// Warn if called on the main thread - if we resort to searching offline players, this may take several seconds.
|
||||||
@@ -362,19 +247,12 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt exact offline match first - adds UUID support for later versions
|
|
||||||
OfflinePlayer player = this.playerLoader.getPlayerByID(name);
|
|
||||||
|
|
||||||
if (player != null) {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure name is valid if server is in online mode to avoid unnecessary searching
|
// Ensure name is valid if server is in online mode to avoid unnecessary searching
|
||||||
if (getServer().getOnlineMode() && !name.matches("[a-zA-Z0-9_]{3,16}")) {
|
if (getServer().getOnlineMode() && !name.matches("[a-zA-Z0-9_]{3,16}")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
player = getServer().getPlayerExact(name);
|
OfflinePlayer player = getServer().getPlayerExact(name);
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
return player;
|
return player;
|
||||||
@@ -423,12 +301,11 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Player from an OfflinePlayer. May return null under some circumstances.
|
* Load a Player from an OfflinePlayer.
|
||||||
*
|
*
|
||||||
* @param offline the OfflinePlayer to load a Player for
|
* @param offline the OfflinePlayer to load a Player for
|
||||||
* @return the Player
|
* @return the Player
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Player loadPlayer(final OfflinePlayer offline) {
|
public Player loadPlayer(final OfflinePlayer offline) {
|
||||||
|
|
||||||
if (offline == null) {
|
if (offline == null) {
|
||||||
@@ -440,7 +317,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
return this.playerCache.get(key);
|
return this.playerCache.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: wrap Player to ensure all methods can safely be called offline
|
|
||||||
Player loaded;
|
Player loaded;
|
||||||
|
|
||||||
if (offline.isOnline()) {
|
if (offline.isOnline()) {
|
||||||
@@ -493,77 +369,10 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see com.lishid.openinv.IOpenInv#retainPlayer(org.bukkit.entity.Player, org.bukkit.plugin.Plugin)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void retainPlayer(Player player, Plugin plugin) {
|
|
||||||
String key = this.playerLoader.getPlayerDataID(player);
|
|
||||||
|
|
||||||
if (this.pluginUsage.containsEntry(key, plugin.getClass())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pluginUsage.put(key, plugin.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see com.lishid.openinv.IOpenInv#releasePlayer(org.bukkit.entity.Player, org.bukkit.plugin.Plugin)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void releasePlayer(Player player, Plugin plugin) {
|
|
||||||
String key = this.playerLoader.getPlayerDataID(player);
|
|
||||||
|
|
||||||
if (!this.pluginUsage.containsEntry(key, plugin.getClass())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pluginUsage.remove(key, plugin.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unmark any Players in use by the specified Plugin.
|
|
||||||
*
|
|
||||||
* @param plugin
|
|
||||||
*/
|
|
||||||
public void releaseAllPlayers(Plugin plugin) {
|
|
||||||
this.pluginUsage.removeAll(plugin.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Collection<? extends Player> getOnlinePlayers() {
|
|
||||||
|
|
||||||
if (this.playerLoader != null) {
|
|
||||||
return this.playerLoader.getOnlinePlayers();
|
|
||||||
}
|
|
||||||
|
|
||||||
Method getOnlinePlayers;
|
|
||||||
try {
|
|
||||||
getOnlinePlayers = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
Object onlinePlayers;
|
|
||||||
try {
|
|
||||||
onlinePlayers = getOnlinePlayers.invoke(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onlinePlayers instanceof List) {
|
|
||||||
return (Collection<Player>) onlinePlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Arrays.asList((Player[]) onlinePlayers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for handling a Player coming online.
|
* Method for handling a Player coming online.
|
||||||
*
|
*
|
||||||
* @param player the Player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public void setPlayerOnline(final Player player) {
|
public void setPlayerOnline(final Player player) {
|
||||||
|
|
||||||
@@ -579,7 +388,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
if (this.inventories.containsKey(key)) {
|
if (this.inventories.containsKey(key)) {
|
||||||
this.inventories.get(key).setPlayerOnline(player);
|
this.inventories.get(key).setPlayerOnline(player);
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@SuppressWarnings("deprecation") // Unlikely to ever be a viable alternative, Spigot un-deprecated.
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (player.isOnline()) {
|
if (player.isOnline()) {
|
||||||
@@ -597,7 +405,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
/**
|
/**
|
||||||
* Method for handling a Player going offline.
|
* Method for handling a Player going offline.
|
||||||
*
|
*
|
||||||
* @param player the Player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public void setPlayerOffline(final Player player) {
|
public void setPlayerOffline(final Player player) {
|
||||||
|
|
||||||
@@ -617,80 +425,31 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static void ShowHelp(Player player) {
|
||||||
* Evicts all viewers lacking cross-world permissions from a Player's inventory.
|
// TODO: Do not show commands players lack permissions for
|
||||||
*
|
player.sendMessage(ChatColor.GREEN + "/openinv <Player> - Open a player's inventory");
|
||||||
* @param player the Player
|
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
|
||||||
*/
|
player.sendMessage(ChatColor.GREEN + "/openender <Player> - Open a player's enderchest");
|
||||||
public void changeWorld(final Player player) {
|
player.sendMessage(ChatColor.GREEN + " (aliases: oe, enderchest)");
|
||||||
|
player.sendMessage(ChatColor.GREEN + "/searchinv <Item> [MinAmount] - ");
|
||||||
String key = this.playerLoader.getPlayerDataID(player);
|
player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item.");
|
||||||
|
player.sendMessage(ChatColor.GREEN + " (aliases: si, search)");
|
||||||
// Check if the player is cached. If not, neither of their inventories is open.
|
player.sendMessage(ChatColor.GREEN + "/anychest - Toggle anychest function");
|
||||||
if (!this.playerCache.containsKey(key)) {
|
player.sendMessage(ChatColor.GREEN + " (aliases: ac)");
|
||||||
return;
|
player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle silent chest function");
|
||||||
}
|
player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)");
|
||||||
|
|
||||||
if (this.inventories.containsKey(key)) {
|
|
||||||
Iterator<HumanEntity> iterator = this.inventories.get(key).getBukkitInventory().getViewers().iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
HumanEntity human = iterator.next();
|
|
||||||
// If player has permission or is in the same world, allow continued access
|
|
||||||
// Just in case, also allow null worlds.
|
|
||||||
if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
|
|
||||||
|| human.getWorld().equals(player.getWorld())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
human.closeInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.enderChests.containsKey(key)) {
|
|
||||||
Iterator<HumanEntity> iterator = this.enderChests.get(key).getBukkitInventory().getViewers().iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
HumanEntity human = iterator.next();
|
|
||||||
if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
|
|
||||||
|| human.getWorld().equals(player.getWorld())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
human.closeInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static boolean hasPermission(Permissible player, String permission) {
|
||||||
* Displays all applicable help for OpenInv commands.
|
String[] parts = permission.split("\\.");
|
||||||
*
|
String perm = "";
|
||||||
* @param player the Player to help
|
for (int i = 0; i < parts.length; i++) {
|
||||||
*/
|
if (player.hasPermission(perm + "*")) {
|
||||||
public void showHelp(Player player) {
|
return true;
|
||||||
// Get registered commands
|
|
||||||
for (String commandName : this.getDescription().getCommands().keySet()) {
|
|
||||||
PluginCommand command = this.getCommand(commandName);
|
|
||||||
|
|
||||||
// Ensure command is successfully registered and player can use it
|
|
||||||
if (command == null || !command.testPermissionSilent(player)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
perm += parts[i] + ".";
|
||||||
// Send usage
|
|
||||||
player.sendMessage(command.getUsage().replace("<command>", commandName));
|
|
||||||
|
|
||||||
List<String> aliases = command.getAliases();
|
|
||||||
if (aliases.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assemble alias list
|
|
||||||
StringBuilder aliasBuilder = new StringBuilder(" (aliases: ");
|
|
||||||
for (String alias : aliases) {
|
|
||||||
aliasBuilder.append(alias).append(", ");
|
|
||||||
}
|
|
||||||
aliasBuilder.delete(aliasBuilder.length() - 2, aliasBuilder.length()).append(')');
|
|
||||||
|
|
||||||
// Send all aliases
|
|
||||||
player.sendMessage(aliasBuilder.toString());
|
|
||||||
}
|
}
|
||||||
|
return player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -14,36 +14,33 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.lishid.openinv.listeners;
|
package com.lishid.openinv;
|
||||||
|
|
||||||
import com.lishid.openinv.IOpenInv;
|
|
||||||
import com.lishid.openinv.util.Permissions;
|
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
|
|
||||||
public class InventoryClickListener implements Listener {
|
public class OpenInvInventoryListener implements Listener {
|
||||||
|
|
||||||
private final IOpenInv plugin;
|
private final OpenInv plugin;
|
||||||
|
|
||||||
public InventoryClickListener(IOpenInv plugin) {
|
public OpenInvInventoryListener(OpenInv plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
HumanEntity entity = event.getWhoClicked();
|
if (!plugin.getInventoryAccess().check(event.getInventory(), event.getWhoClicked())) {
|
||||||
Inventory inventory = event.getInventory();
|
|
||||||
if (plugin.getInventoryAccess().isSpecialPlayerInventory(inventory)
|
|
||||||
&& !Permissions.EDITINV.hasPermission(entity)
|
|
||||||
|| plugin.getInventoryAccess().isSpecialEnderChest(inventory)
|
|
||||||
&& !Permissions.EDITENDER.hasPermission(entity)) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onInventoryDrag(InventoryDragEvent event) {
|
||||||
|
if (!plugin.getInventoryAccess().check(event.getInventory(), event.getWhoClicked())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
104
src/main/java/com/lishid/openinv/OpenInvPlayerListener.java
Normal file
104
src/main/java/com/lishid/openinv/OpenInvPlayerListener.java
Normal file
@@ -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;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.block.Chest;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event.Result;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
public class OpenInvPlayerListener implements Listener {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
|
||||||
|
public OpenInvPlayerListener(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
|
plugin.setPlayerOnline(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
plugin.setPlayerOffline(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
|
if (event.getPlayer().isSneaking()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) {
|
||||||
|
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.openInventory(player.getEnderChest());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest) {
|
||||||
|
boolean silentchest = false;
|
||||||
|
boolean anychest = false;
|
||||||
|
int x = event.getClickedBlock().getX();
|
||||||
|
int y = event.getClickedBlock().getY();
|
||||||
|
int z = event.getClickedBlock().getZ();
|
||||||
|
|
||||||
|
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) {
|
||||||
|
silentchest = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && plugin.getPlayerAnyChestStatus(player)) {
|
||||||
|
try {
|
||||||
|
anychest = plugin.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the anychest or silentchest is active
|
||||||
|
if (anychest || silentchest) {
|
||||||
|
if (!plugin.getAnySilentChest().activateChest(player, anychest, silentchest, x, y, z)) {
|
||||||
|
if (silentchest && plugin.notifySilentChest()) {
|
||||||
|
player.sendMessage("You are opening a chest silently.");
|
||||||
|
}
|
||||||
|
if (anychest && plugin.notifyAnyChest()) {
|
||||||
|
player.sendMessage("You are opening a blocked chest.");
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
src/main/java/com/lishid/openinv/Permissions.java
Normal file
16
src/main/java/com/lishid/openinv/Permissions.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.lishid.openinv;
|
||||||
|
|
||||||
|
public class Permissions {
|
||||||
|
public static final String PERM_OPENINV = "OpenInv.openinv";
|
||||||
|
public static final String PERM_OVERRIDE = "OpenInv.override";
|
||||||
|
public static final String PERM_EXEMPT = "OpenInv.exempt";
|
||||||
|
public static final String PERM_CROSSWORLD = "OpenInv.crossworld";
|
||||||
|
public static final String PERM_SILENT = "OpenInv.silent";
|
||||||
|
public static final String PERM_ANYCHEST = "OpenInv.anychest";
|
||||||
|
public static final String PERM_ENDERCHEST = "OpenInv.openender";
|
||||||
|
public static final String PERM_ENDERCHEST_ALL = "OpenInv.openenderall";
|
||||||
|
public static final String PERM_SEARCH = "OpenInv.search";
|
||||||
|
public static final String PERM_EDITINV = "OpenInv.editinv";
|
||||||
|
public static final String PERM_EDITENDER = "OpenInv.editender";
|
||||||
|
public static final String PERM_OPENSELF = "OpenInv.openself";
|
||||||
|
}
|
@@ -40,15 +40,18 @@ public class AnyChestPluginCommand implements CommandExecutor {
|
|||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
|
if (args.length > 0) {
|
||||||
sender.sendMessage("AnyChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
|
if (args[0].equalsIgnoreCase("check")) {
|
||||||
return true;
|
if (plugin.getPlayerAnyChestStatus(player))
|
||||||
|
sender.sendMessage("AnyChest is ON.");
|
||||||
|
else
|
||||||
|
sender.sendMessage("AnyChest is OFF.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.setPlayerAnyChestStatus(player, !plugin.getPlayerAnyChestStatus(player));
|
plugin.setPlayerAnyChestStatus(player, !plugin.getPlayerAnyChestStatus(player));
|
||||||
sender.sendMessage("AnyChest is now " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
|
sender.sendMessage("AnyChest is now " + (plugin.getPlayerAnyChestStatus(player) ? "On" : "Off") + ".");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -19,8 +19,8 @@ package com.lishid.openinv.commands;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
|
import com.lishid.openinv.Permissions;
|
||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
import com.lishid.openinv.util.Permissions;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@@ -31,9 +31,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class OpenEnderPluginCommand implements CommandExecutor {
|
public class OpenEnderPluginCommand implements CommandExecutor {
|
||||||
|
|
||||||
private final OpenInv plugin;
|
private final OpenInv plugin;
|
||||||
private final HashMap<Player, String> openEnderHistory = new HashMap<Player, String>();
|
public static HashMap<Player, String> openEnderHistory = new HashMap<Player, String>();
|
||||||
|
|
||||||
public OpenEnderPluginCommand(OpenInv plugin) {
|
public OpenEnderPluginCommand(OpenInv plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -47,7 +46,7 @@ public class OpenEnderPluginCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
|
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
|
||||||
plugin.showHelp((Player) sender);
|
OpenInv.ShowHelp((Player) sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +65,8 @@ public class OpenEnderPluginCommand implements CommandExecutor {
|
|||||||
// Read from history if target is not named
|
// Read from history if target is not named
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
name = history;
|
name = history;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
name = args[0];
|
name = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,29 +113,19 @@ public class OpenEnderPluginCommand implements CommandExecutor {
|
|||||||
onlineTarget = target.getPlayer();
|
onlineTarget = target.getPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!onlineTarget.equals(player)) {
|
|
||||||
if (!Permissions.ENDERCHEST_ALL.hasPermission(player)) {
|
if (!onlineTarget.equals(player) && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) {
|
||||||
player.sendMessage(ChatColor.RED + "You do not have permission to access other players' enderchests.");
|
player.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest");
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!Permissions.CROSSWORLD.hasPermission(player) && !player.getWorld().equals(onlineTarget.getWorld())) {
|
|
||||||
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Permissions.OVERRIDE.hasPermission(player) && Permissions.EXEMPT.hasPermission(onlineTarget)) {
|
|
||||||
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the target
|
// Record the target
|
||||||
openEnderHistory.put(player, onlineTarget.getName());
|
openEnderHistory.put(player, onlineTarget.getName());
|
||||||
|
|
||||||
// Create the inventory
|
// Create the inventory
|
||||||
ISpecialEnderChest chest = plugin.getEnderChest(onlineTarget, online);
|
ISpecialEnderChest chest = plugin.getEnderChestFor(onlineTarget, online);
|
||||||
|
|
||||||
// Open the inventory
|
// Open the inventory
|
||||||
player.openInventory(chest.getBukkitInventory());
|
player.openInventory(chest.getBukkitInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -19,8 +19,8 @@ package com.lishid.openinv.commands;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
|
import com.lishid.openinv.Permissions;
|
||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||||
import com.lishid.openinv.util.Permissions;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@@ -31,9 +31,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class OpenInvPluginCommand implements CommandExecutor {
|
public class OpenInvPluginCommand implements CommandExecutor {
|
||||||
|
|
||||||
private final OpenInv plugin;
|
private final OpenInv plugin;
|
||||||
private final HashMap<Player, String> openInvHistory = new HashMap<Player, String>();
|
public static HashMap<Player, String> openInvHistory = new HashMap<Player, String>();
|
||||||
|
|
||||||
public OpenInvPluginCommand(OpenInv plugin) {
|
public OpenInvPluginCommand(OpenInv plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@@ -47,7 +46,7 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
|
if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
|
||||||
plugin.showHelp((Player) sender);
|
OpenInv.ShowHelp((Player) sender);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +65,8 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||||||
// Read from history if target is not named
|
// Read from history if target is not named
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
name = history;
|
name = history;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
name = args[0];
|
name = args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,34 +115,30 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Permissions checks
|
// Permissions checks
|
||||||
if (onlineTarget.equals(player)) {
|
if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(onlineTarget, Permissions.PERM_EXEMPT)) {
|
||||||
// Self-open check
|
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
|
||||||
if (!Permissions.OPENSELF.hasPermission(player)) {
|
return;
|
||||||
player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Protected check
|
|
||||||
if (!Permissions.OVERRIDE.hasPermission(player) && Permissions.EXEMPT.hasPermission(onlineTarget)) {
|
|
||||||
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crossworld check
|
// Crosswork check
|
||||||
if ((!Permissions.CROSSWORLD.hasPermission(player) && !Permissions.OVERRIDE.hasPermission(player)) && onlineTarget.getWorld() != player.getWorld()) {
|
if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && onlineTarget.getWorld() != player.getWorld()) {
|
||||||
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
|
player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Self-open check
|
||||||
|
if (!OpenInv.hasPermission(player, Permissions.PERM_OPENSELF) && onlineTarget.equals(player)) {
|
||||||
|
player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the target
|
// Record the target
|
||||||
openInvHistory.put(player, onlineTarget.getName());
|
openInvHistory.put(player, onlineTarget.getName());
|
||||||
|
|
||||||
// Create the inventory
|
// Create the inventory
|
||||||
ISpecialPlayerInventory inv = plugin.getInventory(onlineTarget, online);
|
ISpecialPlayerInventory inv = plugin.getInventoryFor(onlineTarget, online);
|
||||||
|
|
||||||
// Open the inventory
|
// Open the inventory
|
||||||
player.openInventory(inv.getBukkitInventory());
|
player.openInventory(inv.getBukkitInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -16,26 +16,21 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.commands;
|
package com.lishid.openinv.commands;
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
public class SearchInvPluginCommand implements CommandExecutor {
|
public class SearchInvPluginCommand implements CommandExecutor {
|
||||||
|
public SearchInvPluginCommand() {
|
||||||
|
|
||||||
private final OpenInv plugin;
|
|
||||||
|
|
||||||
public SearchInvPluginCommand(OpenInv plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
String PlayerList = "";
|
||||||
|
|
||||||
Material material = null;
|
Material material = null;
|
||||||
int count = 1;
|
int count = 1;
|
||||||
@@ -45,11 +40,11 @@ public class SearchInvPluginCommand implements CommandExecutor {
|
|||||||
gData = args[0].split(":");
|
gData = args[0].split(":");
|
||||||
material = Material.matchMaterial(gData[0]);
|
material = Material.matchMaterial(gData[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length >= 2) {
|
if (args.length >= 2) {
|
||||||
try {
|
try {
|
||||||
count = Integer.parseInt(args[1]);
|
count = Integer.parseInt(args[1]);
|
||||||
} catch (NumberFormatException ex) {
|
}
|
||||||
|
catch (NumberFormatException ex) {
|
||||||
sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
|
sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -60,23 +55,13 @@ public class SearchInvPluginCommand implements CommandExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder players = new StringBuilder();
|
for (Player templayer : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
for (Player player : plugin.getOnlinePlayers()) {
|
if (templayer.getInventory().contains(material, count)) {
|
||||||
Inventory inventory = command.getName().equals("searchinv") ? player.getInventory() : player.getEnderChest();
|
PlayerList += templayer.getName() + " ";
|
||||||
if (inventory.contains(material, count)) {
|
|
||||||
players.append(player.getName()).append(", ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matches found, delete trailing comma and space
|
sender.sendMessage("Players with the item " + material.toString() + ": " + PlayerList);
|
||||||
if (players.length() > 0) {
|
|
||||||
players.delete(players.length() - 2, players.length());
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("No players found with " + material.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage("Players with the item " + material.toString() + ": " + players.toString());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -40,13 +40,17 @@ public class SilentChestPluginCommand implements CommandExecutor {
|
|||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
|
if (args.length > 0) {
|
||||||
sender.sendMessage("SilentChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
|
if (args[0].equalsIgnoreCase("check")) {
|
||||||
return true;
|
if (plugin.getPlayerSilentChestStatus(player))
|
||||||
|
sender.sendMessage("SilentChest is ON.");
|
||||||
|
else
|
||||||
|
sender.sendMessage("SilentChest is OFF.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.setPlayerSilentChestStatus(player, !plugin.getPlayerSilentChestStatus(player));
|
plugin.setPlayerSilentChestStatus(player, !plugin.getPlayerSilentChestStatus(player));
|
||||||
sender.sendMessage("SilentChest is now " + (plugin.getPlayerSilentChestStatus(player) ? "ON" : "OFF") + ".");
|
sender.sendMessage("SilentChest is now " + (plugin.getPlayerSilentChestStatus(player) ? "On" : "Off") + ".");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface IAnySilentChest {
|
||||||
|
public boolean isAnyChestNeeded(Player player, int x, int y, int z);
|
||||||
|
|
||||||
|
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
|
||||||
|
}
|
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
public interface IInventoryAccess {
|
||||||
|
public boolean check(Inventory inventory, HumanEntity player);
|
||||||
|
}
|
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal;
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@@ -41,19 +39,4 @@ public interface IPlayerDataManager {
|
|||||||
*/
|
*/
|
||||||
public String getPlayerDataID(OfflinePlayer player);
|
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();
|
|
||||||
|
|
||||||
}
|
}
|
@@ -21,11 +21,6 @@ import org.bukkit.inventory.Inventory;
|
|||||||
|
|
||||||
public interface ISpecialEnderChest {
|
public interface ISpecialEnderChest {
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Inventory associated with this ISpecialEnderChest.
|
|
||||||
*
|
|
||||||
* @return the Inventory
|
|
||||||
*/
|
|
||||||
public Inventory getBukkitInventory();
|
public Inventory getBukkitInventory();
|
||||||
|
|
||||||
/**
|
/**
|
@@ -21,11 +21,6 @@ import org.bukkit.inventory.Inventory;
|
|||||||
|
|
||||||
public interface ISpecialPlayerInventory {
|
public interface ISpecialPlayerInventory {
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Inventory associated with this ISpecialPlayerInventory.
|
|
||||||
*
|
|
||||||
* @return the Inventory
|
|
||||||
*/
|
|
||||||
public Inventory getBukkitInventory();
|
public Inventory getBukkitInventory();
|
||||||
|
|
||||||
/**
|
/**
|
118
src/main/java/com/lishid/openinv/internal/InternalAccessor.java
Normal file
118
src/main/java/com/lishid/openinv/internal/InternalAccessor.java
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.lishid.openinv.OpenInv;
|
||||||
|
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class InternalAccessor {
|
||||||
|
|
||||||
|
private final OpenInv plugin;
|
||||||
|
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
public InternalAccessor(OpenInv plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current server version is supported, and, if it is, prepare to load version-specific code.
|
||||||
|
*
|
||||||
|
* @param server the Server
|
||||||
|
*
|
||||||
|
* @return true if supported
|
||||||
|
*/
|
||||||
|
public boolean initialize(Server server) {
|
||||||
|
String packageName = server.getClass().getPackage().getName();
|
||||||
|
version = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("com.lishid.openinv.internal." + version + ".AnySilentChest");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printErrorMessage() {
|
||||||
|
plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPlayerDataManager newPlayerDataManager() {
|
||||||
|
return (IPlayerDataManager) createObject(IPlayerDataManager.class, "PlayerDataManager");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IInventoryAccess newInventoryAccess() {
|
||||||
|
return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAnySilentChest newAnySilentChest() {
|
||||||
|
return (IAnySilentChest) createObject(IAnySilentChest.class, "AnySilentChest");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) {
|
||||||
|
try {
|
||||||
|
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialPlayerInventory");
|
||||||
|
if (ISpecialPlayerInventory.class.isAssignableFrom(internalClass)) {
|
||||||
|
return (ISpecialPlayerInventory) internalClass
|
||||||
|
.getConstructor(Player.class, Boolean.class)
|
||||||
|
.newInstance(player, offline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
printErrorMessage();
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISpecialEnderChest newSpecialEnderChest(Player player, boolean offline) {
|
||||||
|
try {
|
||||||
|
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialEnderChest");
|
||||||
|
if (ISpecialEnderChest.class.isAssignableFrom(internalClass)) {
|
||||||
|
return (ISpecialEnderChest) internalClass
|
||||||
|
.getConstructor(Player.class, Boolean.class)
|
||||||
|
.newInstance(player, offline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
printErrorMessage();
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object createObject(Class<? extends Object> assignableClass, String className) {
|
||||||
|
try {
|
||||||
|
Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
|
||||||
|
if (assignableClass.isAssignableFrom(internalClass)) {
|
||||||
|
return internalClass.getConstructor().newInstance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
printErrorMessage();
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user