Compare commits

..

15 Commits
3.2.0 ... 3.3.2

Author SHA1 Message Date
Jikoo
f5c682ff2b Bump version to 3.3.2 for release 2017-11-08 17:52:41 -05:00
Jikoo
e652b43670 Classic mistake, changed my mind and only changed part of the code.
Also the actual mistake. Never forget. (#81)
2017-11-08 17:40:01 -05:00
Jikoo
f07cef5621 Bump version to 3.3.2-SNAPSHOT for development 2017-11-07 18:18:33 -05:00
Jikoo
ded6421e33 Bump version to 3.3.1 for release 2017-11-07 18:17:12 -05:00
Jikoo
cbb2b4d232 Lowercase permissions can wait for a major version bump
I don't want to double our permissions checks for backwards compatibility.
2017-11-07 18:16:38 -05:00
Jikoo
48c61eeb82 Support lowercase permissions for consistency. 2017-11-06 19:23:26 -05:00
Jikoo
e3d1af010b Add permissions to alter the default state of Any/SilentChest (#76) 2017-11-05 20:00:22 -05:00
Jikoo
2195677651 Actually fix CME (#71) 2017-08-06 16:35:18 -04:00
Jikoo
c72af5dbac Bump version to 3.3.1-SNAPSHOT for development 2017-07-05 05:53:38 -04:00
Jikoo
931cdb6fb1 Bump version to 3.3.0 for release 2017-07-05 05:52:33 -04:00
Jikoo
9db18613a1 Abuse spectator mode for SilentContainer (#64, #68)
Potentially causes issues with Cauldron and similar mods that use different mapping names.
2017-07-04 13:22:03 -04:00
Jikoo
784935a975 Synchronize cache (for real), updated dependencies
Closes #69
2017-07-03 18:06:18 -04:00
Jikoo
d9abe76531 Bump version to 3.2.2-SNAPSHOT for development 2017-06-09 20:21:30 -04:00
Jikoo
ca85a392aa Correct field name for list of inventory contents (#66) 2017-06-09 20:15:51 -04:00
Jikoo
307f47e4d3 Bump version to 3.2.1-SNAPSHOT for development 2017-06-08 18:44:10 -04:00
61 changed files with 482 additions and 489 deletions

1
.gitignore vendored
View File

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

View File

@@ -7,12 +7,12 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
- Cross-world support! Don't grant `OpenInv.crossworld`
- 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.
- **OpenEnder**: Open anyone's ender chest, 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.
- **SilentContainer**: Open containers without displaying an animation or making sound.
- **AnyContainer**: Open containers, even if blocked by ocelots or blocks.
## Commands
<table width=100%>
@@ -42,14 +42,19 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
<td>Lists all online players that have a certain item in their ender chest.</td>
</tr>
<tr>
<td>/anychest [check]</td>
<td>ac</td>
<td>Check or toggle the AnyChest function, allowing opening blocked containers.</td>
<td>/searchenchant &lt[enchantment] [MinLevel]&gt</td>
<td>searchenchants</td>
<td>Lists all online players with a specific enchantment.</td>
</tr>
<tr>
<td>/silentchest [check]</td>
<td>sc</td>
<td>Check or toggle the SilentChest function, allowing opening containers silently.</td>
<td>/anycontainer [check]</td>
<td>ac, anychest</td>
<td>Check or toggle the AnyContainer function, allowing opening blocked containers.</td>
</tr>
<tr>
<td>/silentcontainer [check]</td>
<td>sc, silentchest</td>
<td>Check or toggle the SilentContainer function, allowing opening containers silently.</td>
</tr>
</table>
@@ -103,21 +108,33 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi
<td>OpenInv.search</td>
<td>Required to use /searchinv and /searchender.</td>
</tr>
<tr>
<td>OpenInv.searchenchant</td>
<td>Required to use /searchenchant.</td>
</tr>
<tr>
<td>OpenInv.anychest</td>
<td>Required to use /anychest.</td>
</tr>
<tr>
<td>OpenInv.any.default</td>
<td>Cause AnyContainer to be enabled by default.</td>
</tr>
<tr>
<td>OpenInv.silent</td>
<td>Required to use /silentchest.</td>
<td>Required to use /silentcontainer.</td>
</tr>
<tr>
<td>OpenInv.silent.default</td>
<td>Cause SilentContainer to be enabled by default.</td>
</tr>
</table>
## For Developers
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
To compile for a specific version or set of versions, you'll need to use a profile. Provided profiles are `latest`, `modern` (versions 1.8+), and `all`. Select an existing profile using the `-P` argument (ex: `mvn clean package -am -P all`) or make your own. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
To compile for a specific version or set of versions, you'll need to use a profile. Provided profiles are `latest`, `recent` (last 2 major Minecraft versions), and `all`. Select an existing profile using the `-P` argument (ex: `mvn clean package -am -P all`) or make your own. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
The final file is target/OpenInv.jar
@@ -136,4 +153,4 @@ GNU General 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/>.
```
```

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvapi</artifactId>

View File

@@ -6,16 +6,27 @@ 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
* Opens the container at the given coordinates for the Player. If you do not want blocked
* containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)}
* first.
*
* @param player the Player opening the container
* @param silentchest whether the container's noise is to be silenced
* @param block the Block
* @return true if the container can be opened
*/
public boolean isAnySilentContainer(Block block);
public boolean activateContainer(Player player, boolean silentchest, Block block);
/**
* Closes the Player's currently open container silently, if necessary.
*
* @param player the Player closing a container
*/
public void deactivateContainer(Player player);
/**
* Checks if the container at the given coordinates is blocked.
*
*
* @param player the Player opening the container
* @param block the Block
* @return true if the container is blocked
@@ -23,15 +34,11 @@ public interface IAnySilentContainer {
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
* 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 activateContainer(Player player, boolean silentchest, Block block);
public boolean isAnySilentContainer(Block block);
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvassembly</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvcommon</artifactId>
@@ -22,7 +22,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvapi</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

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

View File

@@ -4,35 +4,46 @@ 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");
OPENINV("openinv"),
OVERRIDE("override"),
EXEMPT("exempt"),
CROSSWORLD("crossworld"),
SILENT("silent"),
SILENT_DEFAULT("silent", "default"),
ANYCHEST("anychest"),
ANY_DEFAULT("any", "default"),
ENDERCHEST("openender"),
ENDERCHEST_ALL("openenderall"),
SEARCH("search"),
EDITINV("editinv"),
EDITENDER("editender"),
OPENSELF("openself");
private final String permission;
private final String[] permission;
private Permissions(String permission) {
this.permission = permission;
Permissions(String... permissions) {
this.permission = new String[permissions.length + 1];
this.permission[0] = "OpenInv";
System.arraycopy(permissions, 0, this.permission, 1, permissions.length);
}
public boolean hasPermission(Permissible permissible) {
String[] parts = permission.split("\\.");
String perm = "";
for (int i = 0; i < parts.length; i++) {
if (permissible.hasPermission(perm + "*")) {
StringBuilder permissionBuilder = new StringBuilder();
// Support wildcard nodes.
for (int i = 0; i < permission.length; i++) {
if (permissible.hasPermission(permissionBuilder.toString() + "*")) {
return true;
}
perm += parts[i] + ".";
permissionBuilder.append(permission[i]).append('.');
}
return permissible.hasPermission(permission);
// Delete trailing period.
if (permissionBuilder.length() > 0) {
permissionBuilder.deleteCharAt(permissionBuilder.length() - 1);
}
return permissible.hasPermission(permissionBuilder.toString());
}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_4_5</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_4_6</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvinternal</artifactId>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_10_R1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -211,4 +211,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_11_R1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -16,14 +16,14 @@
package com.lishid.openinv.internal.v1_11_R1;
import java.lang.reflect.Field;
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;
import org.bukkit.inventory.InventoryView;
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
import net.minecraft.server.v1_11_R1.Block;
@@ -31,7 +31,6 @@ import net.minecraft.server.v1_11_R1.BlockChest;
import net.minecraft.server.v1_11_R1.BlockEnderChest;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
import net.minecraft.server.v1_11_R1.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;
@@ -40,18 +39,29 @@ import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.ITileInventory;
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
import net.minecraft.server.v1_11_R1.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.event.CraftEventFactory;
import net.minecraft.server.v1_11_R1.EnumGamemode;
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
public class AnySilentContainer implements IAnySilentContainer {
private Field playerInteractManagerGamemode;
public AnySilentContainer() {
try {
this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
this.playerInteractManagerGamemode.setAccessible(true);
} catch (Exception e) {
System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
e.printStackTrace();
}
}
@Override
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
if (block.getType() == Material.ENDER_CHEST) {
@@ -186,7 +196,6 @@ public class AnySilentContainer implements IAnySilentContainer {
ITileInventory tileInventory = (ITileInventory) tile;
Block block = world.getType(blockPosition).getBlock();
Container container = null;
if (block instanceof BlockChest) {
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
@@ -218,68 +227,68 @@ public class AnySilentContainer implements IAnySilentContainer {
} else if (blockChest.g == BlockChest.Type.TRAP) {
player.b(StatisticList.getStatistic("stat.trappedChestTriggered"));
}
if (silentchest) {
container = new SilentContainerChest(player.inventory, tileInventory, player);
}
}
if (block instanceof BlockShulkerBox) {
player.b(StatisticList.getStatistic("stat.shulkerBoxOpened"));
if (silentchest && tileInventory instanceof TileEntityShulkerBox) {
// Set value to current + 1. Ensures consistency later when resetting.
SilentContainerShulkerBox.setOpenValue((TileEntityShulkerBox) tileInventory,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tileInventory) + 1);
container = new SilentContainerShulkerBox(player.inventory, tileInventory, player);
}
}
// AnyChest only - SilentChest not active or container unsupported
if (!silentchest || container == null) {
// AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory);
return true;
}
// SilentChest
// SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
case SHULKER_BOX:
break;
default:
return;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try {
// Call InventoryOpenEvent
container = CraftEventFactory.callInventoryOpenEvent(player, container, false);
if (container == null) {
return false;
if (!this.playerInteractManagerGamemode.isAccessible()) {
// Just in case, ensure accessible.
this.playerInteractManagerGamemode.setAccessible(true);
}
// Open window
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(), tileInventory.getScoreboardDisplayName(), tileInventory.getSize()));
player.activeContainer = container;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
// Special handling for shulker boxes - reset value for viewers to what it was initially.
if (tile instanceof TileEntityShulkerBox) {
new BukkitRunnable() {
@Override
public void run() {
// TODO hacky
Object tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return;
}
TileEntityShulkerBox box = (TileEntityShulkerBox) tile;
// Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more.
SilentContainerShulkerBox.setOpenValue(box,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) - 2);
}
}.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2);
}
return true;
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
} catch (Exception e) {
e.printStackTrace();
p.sendMessage(ChatColor.RED + "Error while sending silent container.");
return false;
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_11_R1;
import net.minecraft.server.v1_11_R1.ContainerChest;
import net.minecraft.server.v1_11_R1.EntityHuman;
import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.ItemStack;
import net.minecraft.server.v1_11_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest {
public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
// Send close signal
iInventory.closeContainer(entityHuman);
}
@Override
public void b(EntityHuman entityHuman) {
// Don't send close signal twice, might screw up
PlayerInventory playerinventory = entityHuman.inventory;
if (playerinventory.getCarried() != ItemStack.a) {
ItemStack carried = playerinventory.getCarried();
playerinventory.setCarried(ItemStack.a);
entityHuman.drop(carried, false);
}
}
}

View File

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

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_12_R1</artifactId>
@@ -21,8 +21,21 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -10,15 +10,15 @@
package com.lishid.openinv.internal.v1_12_R1;
import java.lang.reflect.Field;
import com.lishid.openinv.internal.IAnySilentContainer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.inventory.InventoryView;
import net.minecraft.server.v1_12_R1.AxisAlignedBB;
import net.minecraft.server.v1_12_R1.Block;
@@ -26,26 +26,36 @@ import net.minecraft.server.v1_12_R1.BlockChest;
import net.minecraft.server.v1_12_R1.BlockEnderChest;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.BlockShulkerBox;
import net.minecraft.server.v1_12_R1.Container;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityOcelot;
import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.EnumDirection;
import net.minecraft.server.v1_12_R1.EnumGamemode;
import net.minecraft.server.v1_12_R1.IBlockData;
import net.minecraft.server.v1_12_R1.ITileInventory;
import net.minecraft.server.v1_12_R1.InventoryEnderChest;
import net.minecraft.server.v1_12_R1.InventoryLargeChest;
import net.minecraft.server.v1_12_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_12_R1.PlayerInteractManager;
import net.minecraft.server.v1_12_R1.TileEntity;
import net.minecraft.server.v1_12_R1.TileEntityChest;
import net.minecraft.server.v1_12_R1.TileEntityEnderChest;
import net.minecraft.server.v1_12_R1.TileEntityShulkerBox;
import net.minecraft.server.v1_12_R1.World;
import org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory;
public class AnySilentContainer implements IAnySilentContainer {
private Field playerInteractManagerGamemode;
public AnySilentContainer() {
try {
this.playerInteractManagerGamemode = PlayerInteractManager.class.getDeclaredField("gamemode");
this.playerInteractManagerGamemode.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
System.err.println("[OpenInv] Unable to directly write player gamemode! SilentChest will fail.");
e.printStackTrace();
}
}
@Override
public boolean activateContainer(final Player bukkitPlayer, final boolean silentchest,
final org.bukkit.block.Block bukkitBlock) {
@@ -82,7 +92,6 @@ public class AnySilentContainer implements IAnySilentContainer {
ITileInventory tileInventory = (ITileInventory) tile;
Block block = world.getType(blockPosition).getBlock();
Container container = null;
if (block instanceof BlockChest) {
for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
@@ -115,73 +124,69 @@ public class AnySilentContainer implements IAnySilentContainer {
} else if (blockChest.g == BlockChest.Type.TRAP) {
bukkitPlayer.incrementStatistic(Statistic.TRAPPED_CHEST_TRIGGERED);
}
if (silentchest) {
container = new SilentContainerChest(player.inventory, tileInventory, player);
}
}
if (block instanceof BlockShulkerBox) {
bukkitPlayer.incrementStatistic(Statistic.SHULKER_BOX_OPENED);
if (silentchest && tileInventory instanceof TileEntityShulkerBox) {
// Set value to current + 1. Ensures consistency later when resetting.
SilentContainerShulkerBox.setOpenValue((TileEntityShulkerBox) tileInventory,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tileInventory)
+ 1);
container = new SilentContainerShulkerBox(player.inventory, tileInventory, player);
}
}
// AnyChest only - SilentChest not active or container unsupported
if (!silentchest || container == null) {
// AnyChest only - SilentChest not active, container unsupported, or unnecessary.
if (!silentchest || player.playerInteractManager.getGameMode() == EnumGamemode.SPECTATOR) {
player.openContainer(tileInventory);
return true;
}
// SilentChest
try {
// Call InventoryOpenEvent
container = CraftEventFactory.callInventoryOpenEvent(player, container, false);
if (container == null) {
return false;
}
// Open window
int windowId = player.nextContainerCounter();
player.playerConnection.sendPacket(
new PacketPlayOutOpenWindow(windowId, tileInventory.getContainerName(),
tileInventory.getScoreboardDisplayName(), tileInventory.getSize()));
player.activeContainer = container;
player.activeContainer.windowId = windowId;
player.activeContainer.addSlotListener(player);
// Special handling for shulker boxes - reset value for viewers to what it was initially.
if (tile instanceof TileEntityShulkerBox) {
new BukkitRunnable() {
@Override
public void run() {
// TODO hacky
Object tile = world.getTileEntity(blockPosition);
if (!(tile instanceof TileEntityShulkerBox)) {
return;
}
TileEntityShulkerBox box = (TileEntityShulkerBox) tile;
// Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more.
SilentContainerShulkerBox.setOpenValue(box,
SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile)
- 2);
}
}.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2);
}
return true;
} catch (Exception e) {
e.printStackTrace();
bukkitPlayer.sendMessage(ChatColor.RED + "Error while sending silent container.");
// SilentChest requires access to setting players' gamemode directly.
if (this.playerInteractManagerGamemode == null) {
return false;
}
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.openContainer(tileInventory);
this.forceGameMode(player, gamemode);
return true;
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {
if (this.playerInteractManagerGamemode == null) {
return;
}
InventoryView view = bukkitPlayer.getOpenInventory();
switch (view.getType()) {
case CHEST:
case ENDER_CHEST:
case SHULKER_BOX:
break;
default:
return;
}
EntityPlayer player = PlayerDataManager.getHandle(bukkitPlayer);
EnumGamemode gamemode = player.playerInteractManager.getGameMode();
this.forceGameMode(player, EnumGamemode.SPECTATOR);
player.activeContainer.b(player);
player.activeContainer = player.defaultContainer;
this.forceGameMode(player, gamemode);
}
private void forceGameMode(final EntityPlayer player, final EnumGamemode gameMode) {
if (this.playerInteractManagerGamemode == null) {
// No need to warn repeatedly, error on startup and lack of function should be enough.
return;
}
try {
if (!this.playerInteractManagerGamemode.isAccessible()) {
// Just in case, ensure accessible.
this.playerInteractManagerGamemode.setAccessible(true);
}
this.playerInteractManagerGamemode.set(player.playerInteractManager, gameMode);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
private boolean hasOcelotOnTop(final World world, final BlockPosition blockPosition) {

View File

@@ -1,40 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved. This program is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, version 3. This program is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should
* have received a copy of the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
package com.lishid.openinv.internal.v1_12_R1;
import net.minecraft.server.v1_12_R1.ContainerChest;
import net.minecraft.server.v1_12_R1.EntityHuman;
import net.minecraft.server.v1_12_R1.IInventory;
import net.minecraft.server.v1_12_R1.ItemStack;
import net.minecraft.server.v1_12_R1.PlayerInventory;
public class SilentContainerChest extends ContainerChest {
public SilentContainerChest(final PlayerInventory playerInventory, final IInventory iInventory,
final EntityHuman entityHuman) {
super(playerInventory, iInventory, entityHuman);
// Send close signal
iInventory.closeContainer(entityHuman);
}
@Override
public void b(final EntityHuman entityHuman) {
// Don't send close signal twice, might screw up
PlayerInventory playerinventory = entityHuman.inventory;
if (playerinventory.getCarried() != ItemStack.a) {
ItemStack carried = playerinventory.getCarried();
playerinventory.setCarried(ItemStack.a);
entityHuman.drop(carried, false);
}
}
}

View File

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

View File

@@ -150,28 +150,28 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
// Access and replace main inventory array
// Access and replace main inventory list
Field field = PlayerInventory.class.getField("items");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, items);
// Access and replace armor inventory array
// Access and replace armor inventory list
field = PlayerInventory.class.getField("armor");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, armor);
// Access and replace offhand inventory array
// Access and replace offhand inventory list
field = PlayerInventory.class.getField("extraSlots");
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, extraSlots);
// Access and replace array containing all inventory arrays
field = PlayerInventory.class.getDeclaredField("g");
// Access and replace list containing all inventory lists
field = PlayerInventory.class.getDeclaredField("f");
field.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots }));
} catch (NoSuchFieldException e) {
// Unable to set final fields to item arrays, we're screwed. Noisily fail.
// Unable to set final fields to item lists, we're screwed. Noisily fail.
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_4_R1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_5_R2</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_5_R3</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_6_R1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_6_R2</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_6_R3</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -165,4 +165,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_7_R1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -166,4 +166,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_7_R2</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -166,4 +166,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_7_R3</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -166,4 +166,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_7_R4</artifactId>
@@ -27,7 +27,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -166,4 +166,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_8_R1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -210,4 +210,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_8_R2</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -211,4 +211,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_8_R3</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -211,4 +211,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_9_R1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>
</project>

View File

@@ -211,4 +211,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvinternal</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvadapter1_9_R2</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -211,4 +211,7 @@ public class AnySilentContainer implements IAnySilentContainer {
}
}
@Override
public void deactivateContainer(final Player bukkitPlayer) {}
}

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvplugincore</artifactId>
@@ -22,12 +22,12 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvpluginv1_10_r1</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -41,6 +41,7 @@ import com.lishid.openinv.internal.IInventoryAccess;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.listeners.InventoryClickListener;
import com.lishid.openinv.listeners.InventoryCloseListener;
import com.lishid.openinv.listeners.InventoryDragListener;
import com.lishid.openinv.listeners.PlayerListener;
import com.lishid.openinv.listeners.PluginListener;
@@ -270,7 +271,16 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
@Override
public boolean getPlayerAnyChestStatus(final OfflinePlayer player) {
return this.getConfig().getBoolean("toggles.any-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), false);
boolean defaultState = false;
if (player.isOnline()) {
Player onlinePlayer = player.getPlayer();
if (onlinePlayer != null) {
defaultState = Permissions.ANY_DEFAULT.hasPermission(onlinePlayer);
}
}
return this.getConfig().getBoolean("toggles.any-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), defaultState);
}
@Override
@@ -280,7 +290,16 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
@Override
public boolean getPlayerSilentChestStatus(final OfflinePlayer player) {
return this.getConfig().getBoolean("toggles.silent-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), false);
boolean defaultState = false;
if (player.isOnline()) {
Player onlinePlayer = player.getPlayer();
if (onlinePlayer != null) {
defaultState = Permissions.SILENT_DEFAULT.hasPermission(onlinePlayer);
}
}
return this.getConfig().getBoolean("toggles.silent-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), defaultState);
}
@Override
@@ -504,6 +523,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
pm.registerEvents(new PlayerListener(this), this);
pm.registerEvents(new PluginListener(this), this);
pm.registerEvents(new InventoryClickListener(this), this);
pm.registerEvents(new InventoryCloseListener(this), this);
// Bukkit will handle missing events for us, attempt to register InventoryDragEvent without a version check
pm.registerEvents(new InventoryDragListener(this), this);

View File

@@ -0,0 +1,36 @@
package com.lishid.openinv.listeners;
import com.lishid.openinv.IOpenInv;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
/**
*
*
* @author Jikoo
*/
public class InventoryCloseListener implements Listener {
private final IOpenInv plugin;
public InventoryCloseListener(final IOpenInv plugin) {
this.plugin = plugin;
}
@EventHandler
public void onInventoryClose(final InventoryCloseEvent event) {
if (!(event.getPlayer() instanceof Player)) {
return;
}
Player player = (Player) event.getPlayer();
if (this.plugin.getPlayerSilentChestStatus(player)) {
this.plugin.getAnySilentContainer().deactivateContainer(player);
}
}
}

View File

@@ -5,6 +5,15 @@ 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.
permissions:
OpenInv.any.default:
description: Permission for AnyContainer to default on prior to toggling.
default: false
OpenInv.silent.default:
description: Permission for SilentContainer to default on prior to toggling.
default: false
commands:
openinv:
aliases: [oi, inv, open]
@@ -30,15 +39,15 @@ commands:
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.
silentcontainer:
aliases: [sc, silent, silentchest]
description: Toggle SilentContainer 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.
anycontainer:
aliases: [ac, anychest]
description: Toggle AnyContainer function, which allows opening of blocked containers.
permission: OpenInv.*;OpenInv.anychest
usage: |-
/<command> [Check] - Checks or toggle anychest

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvplugin</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvpluginv1_10_r1</artifactId>
@@ -21,7 +21,7 @@
<dependency>
<groupId>com.lishid</groupId>
<artifactId>openinvcommon</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</dependency>
</dependencies>

View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.lishid</groupId>
<artifactId>openinvparent</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</parent>
<artifactId>openinvplugin</artifactId>

View File

@@ -6,7 +6,7 @@
<artifactId>openinvparent</artifactId>
<name>OpenInvParent</name>
<url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
<version>3.2.0</version>
<version>3.3.2</version>
<packaging>pom</packaging>
@@ -74,7 +74,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<version>3.0.0</version>
<configuration>
<filters>
<filter>
@@ -98,7 +98,7 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<version>3.6.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>