Update to Java 8 and Minecraft 1.8.8
This commit is contained in:
@@ -28,11 +28,6 @@
|
||||
<name>OpenInvPlugin</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>openinvcommon</artifactId>
|
||||
|
@@ -24,7 +24,6 @@ import com.lishid.openinv.commands.SearchEnchantPluginCommand;
|
||||
import com.lishid.openinv.commands.SearchInvPluginCommand;
|
||||
import com.lishid.openinv.commands.SilentChestPluginCommand;
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
import com.lishid.openinv.internal.IInventoryAccess;
|
||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||
import com.lishid.openinv.internal.ISpecialInventory;
|
||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
|
||||
@@ -38,15 +37,10 @@ import com.lishid.openinv.util.ConfigUpdater;
|
||||
import com.lishid.openinv.util.Function;
|
||||
import com.lishid.openinv.util.InternalAccessor;
|
||||
import com.lishid.openinv.util.Permissions;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -72,50 +66,52 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
|
||||
private final Map<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
|
||||
private final Map<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
|
||||
private final Map<String, ISpecialPlayerInventory> inventories = new HashMap<>();
|
||||
private final Map<String, ISpecialEnderChest> enderChests = new HashMap<>();
|
||||
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<>(300000L,
|
||||
new Function<Player>() {
|
||||
@Override
|
||||
public boolean run(final Player value) {
|
||||
String key = OpenInv.this.accessor.getPlayerDataManager().getPlayerDataID(value);
|
||||
|
||||
String key = OpenInv.this.getPlayerID(value);
|
||||
return OpenInv.this.inventories.containsKey(key)
|
||||
&& OpenInv.this.inventories.get(key).isInUse()
|
||||
|| OpenInv.this.enderChests.containsKey(key)
|
||||
&& OpenInv.this.enderChests.get(key).isInUse()
|
||||
&& OpenInv.this.enderChests.get(key).isInUse()
|
||||
|| OpenInv.this.pluginUsage.containsKey(key);
|
||||
}
|
||||
}, new Function<Player>() {
|
||||
@Override
|
||||
public boolean run(final Player value) {
|
||||
String key = OpenInv.this.accessor.getPlayerDataManager().getPlayerDataID(value);
|
||||
@Override
|
||||
public boolean run(final Player value) {
|
||||
|
||||
// Check if inventory is stored, and if it is, remove it and eject all viewers
|
||||
if (OpenInv.this.inventories.containsKey(key)) {
|
||||
Inventory inv = OpenInv.this.inventories.remove(key).getBukkitInventory();
|
||||
List<HumanEntity> viewers = inv.getViewers();
|
||||
for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) {
|
||||
entity.closeInventory();
|
||||
}
|
||||
}
|
||||
String key = OpenInv.this.getPlayerID(value);
|
||||
|
||||
// Check if ender chest is stored, and if it is, remove it and eject all viewers
|
||||
if (OpenInv.this.enderChests.containsKey(key)) {
|
||||
Inventory inv = OpenInv.this.enderChests.remove(key).getBukkitInventory();
|
||||
List<HumanEntity> viewers = inv.getViewers();
|
||||
for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) {
|
||||
entity.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
if (!OpenInv.this.disableSaving() && !value.isOnline()) {
|
||||
value.saveData();
|
||||
}
|
||||
return true;
|
||||
// Check if inventory is stored, and if it is, remove it and eject all viewers
|
||||
if (OpenInv.this.inventories.containsKey(key)) {
|
||||
Inventory inv = OpenInv.this.inventories.remove(key).getBukkitInventory();
|
||||
List<HumanEntity> viewers = inv.getViewers();
|
||||
for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) {
|
||||
entity.closeInventory();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Check if ender chest is stored, and if it is, remove it and eject all viewers
|
||||
if (OpenInv.this.enderChests.containsKey(key)) {
|
||||
Inventory inv = OpenInv.this.enderChests.remove(key).getBukkitInventory();
|
||||
List<HumanEntity> viewers = inv.getViewers();
|
||||
for (HumanEntity entity : viewers.toArray(new HumanEntity[0])) {
|
||||
entity.closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
if (!OpenInv.this.disableSaving() && !value.isOnline()) {
|
||||
value.saveData();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
private InternalAccessor accessor;
|
||||
|
||||
@@ -126,7 +122,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
*/
|
||||
public void changeWorld(final Player player) {
|
||||
|
||||
String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
|
||||
String key = this.getPlayerID(player);
|
||||
|
||||
// Check if the player is cached. If not, neither of their inventories is open.
|
||||
if (!this.playerCache.containsKey(key)) {
|
||||
@@ -171,12 +167,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
return this.accessor.getAnySilentContainer();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public IInventoryAccess getInventoryAccess() {
|
||||
return this.accessor.getInventoryAccess();
|
||||
}
|
||||
|
||||
private int getLevenshteinDistance(final String string1, final String string2) {
|
||||
if (string1 == null || string2 == null) {
|
||||
throw new IllegalArgumentException("Strings must not be null");
|
||||
@@ -221,36 +211,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
return prevDistances[len1];
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<? extends Player> getOnlinePlayers() {
|
||||
|
||||
if (this.accessor.isSupported()) {
|
||||
return this.accessor.getPlayerDataManager().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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPlayerAnyChestStatus(@NotNull final OfflinePlayer player) {
|
||||
boolean defaultState = false;
|
||||
@@ -262,13 +222,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
}
|
||||
}
|
||||
|
||||
return this.getConfig().getBoolean("toggles.any-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(player), defaultState);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPlayerID(@NotNull final OfflinePlayer offline) {
|
||||
return this.accessor.getPlayerDataManager().getPlayerDataID(offline);
|
||||
return this.getConfig().getBoolean("toggles.any-chest." + this.getPlayerID(player), defaultState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -282,14 +236,14 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
}
|
||||
}
|
||||
|
||||
return this.getConfig().getBoolean("toggles.silent-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(offline), defaultState);
|
||||
return this.getConfig().getBoolean("toggles.silent-chest." + this.getPlayerID(offline), defaultState);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ISpecialEnderChest getSpecialEnderChest(@NotNull final Player player, final boolean online)
|
||||
throws InstantiationException {
|
||||
String id = this.accessor.getPlayerDataManager().getPlayerDataID(player);
|
||||
String id = this.getPlayerID(player);
|
||||
if (this.enderChests.containsKey(id)) {
|
||||
return this.enderChests.get(id);
|
||||
}
|
||||
@@ -303,7 +257,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
@Override
|
||||
public ISpecialPlayerInventory getSpecialInventory(@NotNull final Player player, final boolean online)
|
||||
throws InstantiationException {
|
||||
String id = this.accessor.getPlayerDataManager().getPlayerDataID(player);
|
||||
String id = this.getPlayerID(player);
|
||||
if (this.inventories.containsKey(id)) {
|
||||
return this.inventories.get(id);
|
||||
}
|
||||
@@ -322,7 +276,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
@Override
|
||||
public Player loadPlayer(@NotNull final OfflinePlayer offline) {
|
||||
|
||||
String key = this.accessor.getPlayerDataManager().getPlayerDataID(offline);
|
||||
String key = this.getPlayerID(offline);
|
||||
if (this.playerCache.containsKey(key)) {
|
||||
return this.playerCache.get(key);
|
||||
}
|
||||
@@ -345,12 +299,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
}
|
||||
|
||||
Future<Player> future = Bukkit.getScheduler().callSyncMethod(this,
|
||||
new Callable<Player>() {
|
||||
@Override
|
||||
public Player call() {
|
||||
return OpenInv.this.accessor.getPlayerDataManager().loadPlayer(offline);
|
||||
}
|
||||
});
|
||||
() -> OpenInv.this.accessor.getPlayerDataManager().loadPlayer(offline));
|
||||
|
||||
int ticks = 0;
|
||||
while (!future.isDone() && !future.isCancelled() && ticks < 10) {
|
||||
@@ -369,10 +318,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
|
||||
try {
|
||||
loaded = future.get();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (ExecutionException e) {
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -384,83 +330,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public OfflinePlayer matchPlayer(@NotNull final String name) {
|
||||
|
||||
// Warn if called on the main thread - if we resort to searching offline players, this may take several seconds.
|
||||
if (this.getServer().isPrimaryThread()) {
|
||||
this.getLogger().warning("Call to OpenInv#matchPlayer made on the main thread!");
|
||||
this.getLogger().warning("This can cause the server to hang, potentially severely.");
|
||||
this.getLogger().warning("Trace:");
|
||||
for (StackTraceElement element : new Throwable().fillInStackTrace().getStackTrace()) {
|
||||
this.getLogger().warning(element.toString());
|
||||
}
|
||||
}
|
||||
|
||||
OfflinePlayer player;
|
||||
|
||||
if (this.isSupportedVersion()) {
|
||||
// Attempt exact offline match first - adds UUID support for later versions
|
||||
player = this.accessor.getPlayerDataManager().getPlayerByID(name);
|
||||
|
||||
if (player != null) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure name is valid if server is in online mode to avoid unnecessary searching
|
||||
if (this.getServer().getOnlineMode() && !name.matches("[a-zA-Z0-9_]{3,16}")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
player = this.getServer().getPlayerExact(name);
|
||||
|
||||
if (player != null) {
|
||||
return player;
|
||||
}
|
||||
|
||||
player = this.getServer().getOfflinePlayer(name);
|
||||
|
||||
/*
|
||||
* Compatibility: Pre-UUID, getOfflinePlayer always returns an OfflinePlayer. Post-UUID,
|
||||
* getOfflinePlayer will return null if no matching player is found. To preserve
|
||||
* compatibility, only return the player if they have played before. Ignoring current online
|
||||
* status is fine, they'd have been found by getPlayerExact otherwise.
|
||||
*/
|
||||
if (player != null && player.hasPlayedBefore()) {
|
||||
return player;
|
||||
}
|
||||
|
||||
player = this.getServer().getPlayer(name);
|
||||
|
||||
if (player != null) {
|
||||
return player;
|
||||
}
|
||||
|
||||
int bestMatch = Integer.MAX_VALUE;
|
||||
for (OfflinePlayer offline : this.getServer().getOfflinePlayers()) {
|
||||
if (offline.getName() == null) {
|
||||
// Loaded by UUID only, name has never been looked up.
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentMatch = this.getLevenshteinDistance(name, offline.getName());
|
||||
|
||||
if (currentMatch == 0) {
|
||||
return offline;
|
||||
}
|
||||
|
||||
if (currentMatch < bestMatch) {
|
||||
bestMatch = currentMatch;
|
||||
player = offline;
|
||||
}
|
||||
}
|
||||
|
||||
// Only null if no players have played ever, otherwise even the worst match will do.
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable InventoryView openInventory(@NotNull Player player, @NotNull ISpecialInventory inventory) {
|
||||
return this.accessor.getPlayerDataManager().openInventory(player, inventory);
|
||||
@@ -507,10 +376,10 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
// Register listeners
|
||||
pm.registerEvents(new PlayerListener(this), this);
|
||||
pm.registerEvents(new PluginListener(this), this);
|
||||
pm.registerEvents(new InventoryClickListener(this), this);
|
||||
pm.registerEvents(new InventoryClickListener(), 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);
|
||||
pm.registerEvents(new InventoryDragListener(), this);
|
||||
|
||||
// Register commands to their executors
|
||||
OpenInvPluginCommand openInv = new OpenInvPluginCommand(this);
|
||||
@@ -557,7 +426,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
|
||||
@Override
|
||||
public void releasePlayer(@NotNull final Player player, @NotNull final Plugin plugin) {
|
||||
String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
|
||||
String key = this.getPlayerID(player);
|
||||
|
||||
if (!this.pluginUsage.containsEntry(key, plugin.getClass())) {
|
||||
return;
|
||||
@@ -568,7 +437,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
|
||||
@Override
|
||||
public void retainPlayer(@NotNull final Player player, @NotNull final Plugin plugin) {
|
||||
String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
|
||||
String key = this.getPlayerID(player);
|
||||
|
||||
if (this.pluginUsage.containsEntry(key, plugin.getClass())) {
|
||||
return;
|
||||
@@ -579,7 +448,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
|
||||
@Override
|
||||
public void setPlayerAnyChestStatus(@NotNull final OfflinePlayer offline, final boolean status) {
|
||||
this.getConfig().set("toggles.any-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(offline), status);
|
||||
this.getConfig().set("toggles.any-chest." + this.getPlayerID(offline), status);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@@ -591,7 +460,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
*/
|
||||
public void setPlayerOffline(final Player player) {
|
||||
|
||||
String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
|
||||
String key = this.getPlayerID(player);
|
||||
|
||||
// Check if the player is cached. If not, neither of their inventories is open.
|
||||
if (!this.playerCache.containsKey(key)) {
|
||||
@@ -615,7 +484,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
*/
|
||||
public void setPlayerOnline(final Player player) {
|
||||
|
||||
String key = this.accessor.getPlayerDataManager().getPlayerDataID(player);
|
||||
String key = this.getPlayerID(player);
|
||||
|
||||
// Check if the player is cached. If not, neither of their inventories is open.
|
||||
if (!this.playerCache.containsKey(key)) {
|
||||
@@ -627,7 +496,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
if (this.inventories.containsKey(key)) {
|
||||
this.inventories.get(key).setPlayerOnline(player);
|
||||
new BukkitRunnable() {
|
||||
@SuppressWarnings("deprecation") // Unlikely to ever be a viable alternative, Spigot un-deprecated.
|
||||
@Override
|
||||
public void run() {
|
||||
if (player.isOnline()) {
|
||||
@@ -644,7 +512,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
|
||||
@Override
|
||||
public void setPlayerSilentChestStatus(@NotNull final OfflinePlayer offline, final boolean status) {
|
||||
this.getConfig().set("toggles.silent-chest." + this.accessor.getPlayerDataManager().getPlayerDataID(offline), status);
|
||||
this.getConfig().set("toggles.silent-chest." + this.getPlayerID(offline), status);
|
||||
this.saveConfig();
|
||||
}
|
||||
|
||||
@@ -685,7 +553,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv {
|
||||
|
||||
@Override
|
||||
public void unload(@NotNull final OfflinePlayer offline) {
|
||||
this.playerCache.invalidate(this.accessor.getPlayerDataManager().getPlayerDataID(offline));
|
||||
this.playerCache.invalidate(this.getPlayerID(offline));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -67,7 +67,7 @@ public class SearchEnchantPluginCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
StringBuilder players = new StringBuilder();
|
||||
for (Player player : plugin.getOnlinePlayers()) {
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
boolean flagInventory = containsEnchantment(player.getInventory(), enchant, level);
|
||||
boolean flagEnder = containsEnchantment(player.getEnderChest(), enchant, level);
|
||||
|
||||
|
@@ -59,7 +59,7 @@ public class SearchInvPluginCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
StringBuilder players = new StringBuilder();
|
||||
for (Player player : plugin.getOnlinePlayers()) {
|
||||
for (Player player : plugin.getServer().getOnlinePlayers()) {
|
||||
Inventory inventory = command.getName().equals("searchinv") ? player.getInventory() : player.getEnderChest();
|
||||
if (inventory.contains(material, count)) {
|
||||
players.append(player.getName()).append(", ");
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.lishid.openinv.listeners;
|
||||
|
||||
import com.lishid.openinv.IOpenInv;
|
||||
import com.lishid.openinv.util.InventoryAccess;
|
||||
import com.lishid.openinv.util.Permissions;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -27,20 +27,12 @@ import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class InventoryClickListener implements Listener {
|
||||
|
||||
private final IOpenInv plugin;
|
||||
|
||||
public InventoryClickListener(IOpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent 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)) {
|
||||
if (InventoryAccess.isPlayerInventory(inventory) && !Permissions.EDITINV.hasPermission(entity)
|
||||
|| InventoryAccess.isEnderChest(inventory) && !Permissions.EDITENDER.hasPermission(entity)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@@ -22,11 +22,6 @@ 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;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2018 lishid. All rights reserved.
|
||||
* Copyright (C) 2011-2019 lishid. All rights reserved.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.lishid.openinv.listeners;
|
||||
|
||||
import com.lishid.openinv.IOpenInv;
|
||||
import com.lishid.openinv.util.InventoryAccess;
|
||||
import com.lishid.openinv.util.Permissions;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -32,20 +32,12 @@ import org.bukkit.inventory.Inventory;
|
||||
*/
|
||||
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)) {
|
||||
if (InventoryAccess.isPlayerInventory(inventory) && !Permissions.EDITINV.hasPermission(entity)
|
||||
|| InventoryAccess.isEnderChest(inventory) && !Permissions.EDITENDER.hasPermission(entity)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@@ -61,22 +61,22 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
boolean anychest = Permissions.ANYCHEST.hasPermission(player) && plugin.getPlayerAnyChestStatus(player);
|
||||
boolean needsAnyChest = plugin.getAnySilentContainer().isAnyContainerNeeded(player, event.getClickedBlock());
|
||||
boolean any = Permissions.ANYCHEST.hasPermission(player) && plugin.getPlayerAnyChestStatus(player);
|
||||
boolean needsAny = plugin.getAnySilentContainer().isAnyContainerNeeded(player, event.getClickedBlock());
|
||||
|
||||
if (!anychest && needsAnyChest) {
|
||||
if (!any && needsAny) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean silentchest = Permissions.SILENT.hasPermission(player) && plugin.getPlayerSilentChestStatus(player);
|
||||
boolean silent = 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()) {
|
||||
// If anycontainer or silentcontainer is active
|
||||
if ((any || silent) && plugin.getAnySilentContainer().activateContainer(player, silent, event.getClickedBlock())) {
|
||||
if (silent && plugin.notifySilentChest() && needsAny && plugin.notifyAnyChest()) {
|
||||
player.sendMessage("You are opening a blocked container silently.");
|
||||
} else if (silentchest && plugin.notifySilentChest()) {
|
||||
} else if (silent && plugin.notifySilentChest()) {
|
||||
player.sendMessage("You are opening a container silently.");
|
||||
} else if (needsAnyChest && plugin.notifyAnyChest()) {
|
||||
} else if (needsAny && plugin.notifyAnyChest()) {
|
||||
player.sendMessage("You are opening a blocked container.");
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
@@ -22,7 +22,6 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@@ -78,6 +77,7 @@ public class ConfigUpdater {
|
||||
public void run() {
|
||||
plugin.getConfig().set("config-version", 3);
|
||||
plugin.getConfig().set("items.open-inv", null);
|
||||
plugin.getConfig().set("ItemOpenInv", null);
|
||||
plugin.getConfig().set("toggles.items.open-inv", null);
|
||||
plugin.getConfig().set("settings.disable-saving",
|
||||
plugin.getConfig().getBoolean("DisableSaving", false));
|
||||
@@ -91,22 +91,18 @@ public class ConfigUpdater {
|
||||
@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", "toggles.any-chest");
|
||||
updateToggles("ItemOpenInv", "toggles.items.open-inv");
|
||||
updateToggles("SilentChest", "toggles.silent-chest");
|
||||
}
|
||||
|
||||
@@ -124,7 +120,7 @@ public class ConfigUpdater {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, Boolean> toggles = new HashMap<String, Boolean>();
|
||||
final Map<String, Boolean> toggles = new HashMap<>();
|
||||
|
||||
for (String playerName : keys) {
|
||||
OfflinePlayer player = plugin.matchPlayer(playerName);
|
||||
@@ -154,13 +150,4 @@ public class ConfigUpdater {
|
||||
}.runTask(plugin);
|
||||
}
|
||||
|
||||
private Material getMaterialById(int id) {
|
||||
Material material = Material.getMaterial(id);
|
||||
|
||||
if (material == null) {
|
||||
material = Material.STICK;
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user