diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index 2b66f6c2..6f261be8 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -18,14 +18,9 @@ import java.util.HashMap; import java.util.Map; - -import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permissible; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import com.lishid.openinv.commands.AnyChestPluginCommand; import com.lishid.openinv.commands.OpenEnderPluginCommand; @@ -34,10 +29,24 @@ import com.lishid.openinv.commands.SilentChestPluginCommand; import com.lishid.openinv.internal.IAnySilentChest; 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 com.lishid.openinv.internal.InternalAccessor; -import com.lishid.openinv.internal.PlayerDataManager; +import com.lishid.openinv.util.Cache; +import com.lishid.openinv.util.Function; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.permissions.Permissible; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; /** * Open other player's inventory @@ -48,9 +57,45 @@ public class OpenInv extends JavaPlugin { private final Map inventories = new HashMap(); private final Map enderChests = new HashMap(); + private final Cache playerCache = new Cache(300000L, + new Function() { + @Override + public boolean run(Player value) { + String key = playerLoader.getPlayerDataID(value); + return inventories.containsKey(key) && inventories.get(key).isInUse() + || enderChests.containsKey(key) && enderChests.get(key).isInUse(); + } + }, + new Function() { + @Override + public boolean run(Player value) { + String key = playerLoader.getPlayerDataID(value); + + // Check if inventory is stored, and if it is, remove it and eject all viewers + if (inventories.containsKey(key)) { + Inventory inv = inventories.remove(key).getBukkitInventory(); + for (HumanEntity entity : inv.getViewers()) { + entity.closeInventory(); + } + } + + // Check if ender chest is stored, and if it is, remove it and eject all viewers + if (enderChests.containsKey(key)) { + Inventory inv = enderChests.remove(key).getBukkitInventory(); + for (HumanEntity entity : inv.getViewers()) { + entity.closeInventory(); + } + } + + if (!OpenInv.this.disableSaving() && !value.isOnline()) { + value.saveData(); + } + return true; + } + }); private InternalAccessor accessor; - private PlayerDataManager playerLoader; + private IPlayerDataManager playerLoader; private IInventoryAccess inventoryAccess; private IAnySilentChest anySilentChest; @@ -105,12 +150,14 @@ public void onEnable() { } - public InternalAccessor getInternalAccessor() { - return this.accessor; - } + @Override + public void onDisable() { - public PlayerDataManager getPlayerLoader() { - return this.playerLoader; + if (this.disableSaving()) { + return; + } + + this.playerCache.invalidateAll(); } public IInventoryAccess getInventoryAccess() { @@ -121,54 +168,35 @@ public IAnySilentChest getAnySilentChest() { return this.anySilentChest; } - public ISpecialPlayerInventory getInventoryFor(Player player) { - String id = getPlayerLoader().getPlayerDataID(player); + public ISpecialPlayerInventory getInventoryFor(Player player, boolean online) { + String id = playerLoader.getPlayerDataID(player); if (inventories.containsKey(id)) { return inventories.get(id); } - return null; - } - - public ISpecialPlayerInventory getOrCreateInventoryFor(Player player, boolean online) { - String id = getPlayerLoader().getPlayerDataID(player); - if (inventories.containsKey(id)) { - return inventories.get(id); - } - ISpecialPlayerInventory inv = getInternalAccessor().newSpecialPlayerInventory(player, online); + ISpecialPlayerInventory inv = accessor.newSpecialPlayerInventory(player, online); inventories.put(id, inv); + playerCache.put(id, player); return inv; } - public void removeLoadedInventory(Player player) { - String id = getPlayerLoader().getPlayerDataID(player); - if (inventories.containsKey(id)) { - inventories.remove(id); - } - } - - public ISpecialEnderChest getEnderChestFor(Player player) { - String id = getPlayerLoader().getPlayerDataID(player); + public ISpecialEnderChest getEnderChestFor(Player player, boolean online) { + String id = playerLoader.getPlayerDataID(player); if (enderChests.containsKey(id)) { return enderChests.get(id); } - return null; - } - - public ISpecialEnderChest getOrCreateEnderChestFor(Player player, boolean online) { - String id = getPlayerLoader().getPlayerDataID(player); - if (enderChests.containsKey(id)) { - return enderChests.get(id); - } - ISpecialEnderChest inv = getInternalAccessor().newSpecialEnderChest(player, online); + ISpecialEnderChest inv = accessor.newSpecialEnderChest(player, online); enderChests.put(id, inv); + playerCache.put(id, player); return inv; } - public void removeLoadedEnderChest(Player player) { - String id = getPlayerLoader().getPlayerDataID(player); - if (enderChests.containsKey(id)) { - enderChests.remove(id); - } + /** + * Unload a cached Player's data. + * + * @param player the OfflinePlayer to unload + */ + public void unload(OfflinePlayer player) { + this.playerCache.invalidate(this.playerLoader.getPlayerDataID(player)); } public boolean disableSaving() { @@ -184,20 +212,20 @@ public boolean notifyAnyChest() { } public boolean getPlayerSilentChestStatus(OfflinePlayer player) { - return getConfig().getBoolean("SilentChest." + getPlayerLoader().getPlayerDataID(player) + ".toggle", false); + return getConfig().getBoolean("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", false); } public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status) { - getConfig().set("SilentChest." + getPlayerLoader().getPlayerDataID(player) + ".toggle", status); + getConfig().set("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", status); saveConfig(); } public boolean getPlayerAnyChestStatus(OfflinePlayer player) { - return getConfig().getBoolean("AnyChest." + getPlayerLoader().getPlayerDataID(player) + ".toggle", true); + return getConfig().getBoolean("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", true); } public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status) { - getConfig().set("AnyChest." + getPlayerLoader().getPlayerDataID(player) + ".toggle", status); + getConfig().set("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", status); saveConfig(); } @@ -219,6 +247,11 @@ public OfflinePlayer matchPlayer(String name) { } } + // 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}")) { + return null; + } + OfflinePlayer player = getServer().getPlayerExact(name); if (player != null) { @@ -267,7 +300,133 @@ public OfflinePlayer matchPlayer(String name) { return player; } + /** + * Load a Player from an OfflinePlayer. + * + * @param offline the OfflinePlayer to load a Player for + * @return the Player + */ + public Player loadPlayer(final OfflinePlayer offline) { + + if (offline == null) { + return null; + } + + String key = this.playerLoader.getPlayerDataID(offline); + if (this.playerCache.containsKey(key)) { + return this.playerCache.get(key); + } + + Player loaded; + + if (offline.isOnline()) { + loaded = offline.getPlayer(); + this.playerCache.put(key, loaded); + return loaded; + } + + if (Bukkit.isPrimaryThread()) { + return this.playerLoader.loadPlayer(offline); + } + + Future future = Bukkit.getScheduler().callSyncMethod(this, + new Callable() { + @Override + public Player call() throws Exception { + return playerLoader.loadPlayer(offline); + } + }); + + int ticks = 0; + while (!future.isDone() && !future.isCancelled() && ticks < 10) { + ++ticks; + try { + Thread.sleep(50L); + } catch (InterruptedException e) { + e.printStackTrace(); + return null; + } + } + + if (!future.isDone() || future.isCancelled()) { + return null; + } + + try { + loaded = future.get(); + } catch (InterruptedException e) { + e.printStackTrace(); + return null; + } catch (ExecutionException e) { + e.printStackTrace(); + return null; + } + + if (loaded != null) { + this.playerCache.put(key, loaded); + } + + return loaded; + } + + /** + * Method for handling a Player coming online. + * + * @param player + */ + public void setPlayerOnline(final Player player) { + + String key = this.playerLoader.getPlayerDataID(player); + + // Check if the player is cached. If not, neither of their inventories is open. + if (!this.playerCache.containsKey(key)) { + return; + } + + this.playerCache.put(key, player); + + if (this.inventories.containsKey(key)) { + this.inventories.get(key).setPlayerOnline(player); + new BukkitRunnable() { + @Override + public void run() { + if (player.isOnline()) { + player.updateInventory(); + } + } + }.runTask(this); + } + + if (this.enderChests.containsKey(key)) { + this.enderChests.get(key).setPlayerOnline(player); + } + } + + /** + * Method for handling a Player going offline. + * + * @param player + */ + public void setPlayerOffline(final Player player) { + + String key = this.playerLoader.getPlayerDataID(player); + + // Check if the player is cached. If not, neither of their inventories is open. + if (!this.playerCache.containsKey(key)) { + return; + } + + if (this.inventories.containsKey(key)) { + this.inventories.get(key).setPlayerOffline(); + } + + if (this.enderChests.containsKey(key)) { + this.enderChests.get(key).setPlayerOffline(); + } + } + public static void ShowHelp(Player player) { + // TODO: Do not show commands players lack permissions for player.sendMessage(ChatColor.GREEN + "/openinv - Open a player's inventory"); player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); player.sendMessage(ChatColor.GREEN + "/openender - Open a player's enderchest"); @@ -292,4 +451,5 @@ public static boolean hasPermission(Permissible player, String permission) { } return player.hasPermission(permission); } + } diff --git a/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java b/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java index d0eb93fa..b064e0ce 100644 --- a/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java +++ b/src/main/java/com/lishid/openinv/OpenInvPlayerListener.java @@ -27,10 +27,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.scheduler.BukkitRunnable; - -import com.lishid.openinv.internal.ISpecialEnderChest; -import com.lishid.openinv.internal.ISpecialPlayerInventory; public class OpenInvPlayerListener implements Listener { @@ -42,39 +38,12 @@ public OpenInvPlayerListener(OpenInv plugin) { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(final PlayerJoinEvent event) { - new BukkitRunnable() { - @Override - public void run() { - if (!event.getPlayer().isOnline()) { - return; - } - ISpecialPlayerInventory inventory = plugin.getInventoryFor(event.getPlayer()); - if (inventory != null) { - inventory.setPlayerOnline(event.getPlayer()); - event.getPlayer().updateInventory(); - } - ISpecialEnderChest chest = plugin.getEnderChestFor(event.getPlayer()); - if (chest != null) { - chest.setPlayerOnline(event.getPlayer()); - } - } - }.runTask(plugin); + plugin.setPlayerOnline(event.getPlayer()); } @EventHandler(priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { - ISpecialPlayerInventory inventory = plugin.getInventoryFor(event.getPlayer()); - if (inventory != null) { - if (inventory.setPlayerOffline()) { - plugin.removeLoadedInventory(event.getPlayer()); - } - } - ISpecialEnderChest chest = plugin.getEnderChestFor(event.getPlayer()); - if (chest != null) { - if (chest.setPlayerOffline()) { - plugin.removeLoadedEnderChest(event.getPlayer()); - } - } + plugin.setPlayerOffline(event.getPlayer()); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java index 5299a9ae..da083e42 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderPluginCommand.java @@ -18,6 +18,10 @@ import java.util.HashMap; +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -26,10 +30,6 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.ISpecialEnderChest; - public class OpenEnderPluginCommand implements CommandExecutor { private final OpenInv plugin; public static HashMap openEnderHistory = new HashMap(); @@ -103,7 +103,7 @@ private void openInventory(Player player, OfflinePlayer target) { if (!online) { // Try loading the player's data - onlineTarget = plugin.getPlayerLoader().loadPlayer(plugin, target); + onlineTarget = plugin.loadPlayer(target); if (onlineTarget == null) { player.sendMessage(ChatColor.RED + "Player not found!"); @@ -123,7 +123,7 @@ private void openInventory(Player player, OfflinePlayer target) { openEnderHistory.put(player, onlineTarget.getName()); // Create the inventory - ISpecialEnderChest chest = plugin.getOrCreateEnderChestFor(onlineTarget, online); + ISpecialEnderChest chest = plugin.getEnderChestFor(onlineTarget, online); // Open the inventory player.openInventory(chest.getBukkitInventory()); diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java index 441f2b48..d026a68f 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvPluginCommand.java @@ -18,6 +18,10 @@ import java.util.HashMap; +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; @@ -26,10 +30,6 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - public class OpenInvPluginCommand implements CommandExecutor { private final OpenInv plugin; public static HashMap openInvHistory = new HashMap(); @@ -104,7 +104,7 @@ private void openInventory(Player player, OfflinePlayer target) { if (!online) { // Try loading the player's data - onlineTarget = plugin.getPlayerLoader().loadPlayer(plugin, target); + onlineTarget = plugin.loadPlayer(target); if (onlineTarget == null) { player.sendMessage(ChatColor.RED + "Player not found!"); @@ -136,7 +136,7 @@ private void openInventory(Player player, OfflinePlayer target) { openInvHistory.put(player, onlineTarget.getName()); // Create the inventory - ISpecialPlayerInventory inv = plugin.getOrCreateInventoryFor(onlineTarget, online); + ISpecialPlayerInventory inv = plugin.getInventoryFor(onlineTarget, online); // Open the inventory player.openInventory(inv.getBukkitInventory()); diff --git a/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java new file mode 100644 index 00000000..bbcd68d6 --- /dev/null +++ b/src/main/java/com/lishid/openinv/internal/IPlayerDataManager.java @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +package com.lishid.openinv.internal; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +public interface IPlayerDataManager { + + /** + * Loads a Player for an OfflinePlayer. + *

+ * This method is potentially blocking, and should not be called on the main thread. + * + * @param offline + * @return + */ + public Player loadPlayer(OfflinePlayer offline); + + /** + * Gets a unique identifying string for an OfflinePlayer. + * + * @param player + * @return + */ + public String getPlayerDataID(OfflinePlayer player); + +} diff --git a/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java index 9ad54fe3..e0d88feb 100644 --- a/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/ISpecialEnderChest.java @@ -23,15 +23,23 @@ public interface ISpecialEnderChest { public Inventory getBukkitInventory(); - public boolean inventoryRemovalCheck(boolean save); - + /** + * Sets the Player associated with this ISpecialEnderChest online. + * + * @param player the Player coming online + */ public void setPlayerOnline(Player player); /** * Sets the Player associated with this ISpecialEnderChest offline. + */ + public void setPlayerOffline(); + + /** + * Gets whether or not this ISpecialEnderChest is in use. * - * @return true if the ISpecialEnderChest is eligible for removal + * @return true if the ISpecialEnderChest is in use */ - public boolean setPlayerOffline(); + public boolean isInUse(); } diff --git a/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java index 4cc2b321..24fae35f 100644 --- a/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/ISpecialPlayerInventory.java @@ -23,14 +23,23 @@ public interface ISpecialPlayerInventory { public Inventory getBukkitInventory(); - public boolean inventoryRemovalCheck(boolean save); - + /** + * Sets the Player associated with this ISpecialPlayerInventory online. + * + * @param player the Player coming online + */ public void setPlayerOnline(Player player); /** * Sets the Player associated with this ISpecialPlayerInventory offline. + */ + public void setPlayerOffline(); + + /** + * Gets whether or not this ISpecialPlayerInventory is in use. * - * @return true if the ISpecialPlayerInventory is eligible for removal + * @return true if the ISpecialPlayerInventory is in use */ - public boolean setPlayerOffline(); + public boolean isInUse(); + } diff --git a/src/main/java/com/lishid/openinv/internal/InternalAccessor.java b/src/main/java/com/lishid/openinv/internal/InternalAccessor.java index 3e524509..d0939d8b 100644 --- a/src/main/java/com/lishid/openinv/internal/InternalAccessor.java +++ b/src/main/java/com/lishid/openinv/internal/InternalAccessor.java @@ -16,11 +16,11 @@ package com.lishid.openinv.internal; +import com.lishid.openinv.OpenInv; + import org.bukkit.Server; import org.bukkit.entity.Player; -import com.lishid.openinv.OpenInv; - public class InternalAccessor { private final OpenInv plugin; @@ -55,8 +55,8 @@ private void printErrorMessage() { plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv."); } - public PlayerDataManager newPlayerDataManager() { - return (PlayerDataManager) createObject(PlayerDataManager.class, "PlayerDataManager"); + public IPlayerDataManager newPlayerDataManager() { + return (IPlayerDataManager) createObject(IPlayerDataManager.class, "PlayerDataManager"); } public IInventoryAccess newInventoryAccess() { @@ -72,8 +72,8 @@ public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean Class internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialPlayerInventory"); if (ISpecialPlayerInventory.class.isAssignableFrom(internalClass)) { return (ISpecialPlayerInventory) internalClass - .getConstructor(OpenInv.class, Player.class, Boolean.class) - .newInstance(this.plugin, player, offline); + .getConstructor(Player.class, Boolean.class) + .newInstance(player, offline); } } catch (Exception e) { @@ -89,8 +89,8 @@ public ISpecialEnderChest newSpecialEnderChest(Player player, boolean offline) { Class internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialEnderChest"); if (ISpecialEnderChest.class.isAssignableFrom(internalClass)) { return (ISpecialEnderChest) internalClass - .getConstructor(OpenInv.class, Player.class, Boolean.class) - .newInstance(this.plugin, player, offline); + .getConstructor(Player.class, Boolean.class) + .newInstance(player, offline); } } catch (Exception e) { diff --git a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java deleted file mode 100644 index b7efbfc8..00000000 --- a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java +++ /dev/null @@ -1,73 +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 . - */ - -package com.lishid.openinv.internal; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -public abstract class PlayerDataManager { - public final Player loadPlayer(final Plugin plugin, final OfflinePlayer offline) { - if (offline.isOnline()) { - return offline.getPlayer(); - } - if (Bukkit.isPrimaryThread()) { - return this.loadOfflinePlayer(offline); - } - - - Future future = Bukkit.getScheduler().callSyncMethod(plugin, - new Callable() { - @Override - public Player call() throws Exception { - return loadOfflinePlayer(offline); - } - }); - - int ticks = 0; - while (!future.isDone() && !future.isCancelled() && ticks < 10) { - ++ticks; - try { - Thread.sleep(50L); - } catch (InterruptedException e) { - e.printStackTrace(); - return null; - } - } - if (!future.isDone() || future.isCancelled()) { - return null; - } - try { - return future.get(); - } catch (InterruptedException e) { - e.printStackTrace(); - return null; - } catch (ExecutionException e) { - e.printStackTrace(); - return null; - } - } - - protected abstract Player loadOfflinePlayer(OfflinePlayer offline); - - public abstract String getPlayerDataID(OfflinePlayer player); -} diff --git a/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java index 9dfeb16f..73f687a4 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_10_R1/PlayerDataManager.java @@ -16,12 +16,14 @@ package com.lishid.openinv.internal.v1_10_R1; +import com.lishid.openinv.internal.IPlayerDataManager; + +import com.mojang.authlib.GameProfile; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import com.mojang.authlib.GameProfile; - // Volatile import net.minecraft.server.v1_10_R1.EntityPlayer; import net.minecraft.server.v1_10_R1.MinecraftServer; @@ -29,10 +31,10 @@ import org.bukkit.craftbukkit.v1_10_R1.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { if (offline == null || !offline.hasPlayedBefore()) { return null; } @@ -56,4 +58,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialEnderChest.java index eca499b8..588ae228 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialEnderChest.java @@ -18,44 +18,32 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.entity.HumanEntity; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; // Volatile -import net.minecraft.server.v1_10_R1.EntityHuman; import net.minecraft.server.v1_10_R1.IInventory; import net.minecraft.server.v1_10_R1.InventoryEnderChest; import net.minecraft.server.v1_10_R1.InventorySubcontainer; import net.minecraft.server.v1_10_R1.ItemStack; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); - public List transaction = new ArrayList(); public boolean playerOnline = false; - private CraftPlayer owner; - private int maxStack = MAX_STACK; - - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; + + 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; setItemArrays(this, enderChest.getContents()); } @@ -84,21 +72,13 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { try { - owner = (CraftPlayer) player; - setItemArrays(owner.getHandle().getEnderChest(), this.items); + this.bukkitOwner = player; + CraftPlayer craftPlayer = (CraftPlayer) player; + setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items); } catch (Exception e) {} playerOnline = true; @@ -106,62 +86,19 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); } @Override - public ItemStack[] getContents() { - return this.items; - } - - @Override - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - @Override - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.inventoryRemovalCheck(true); - } - - @Override - public List getViewers() { - return transaction; - } - - @Override - public InventoryHolder getOwner() { - return this.owner; - } - - @Override - public void setMaxStackSize(int size) { - maxStack = size; - } - - @Override - public int getMaxStackSize() { - return maxStack; - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialPlayerInventory.java index c21e5ec4..53e682ab 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_10_R1/SpecialPlayerInventory.java @@ -19,33 +19,27 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile import net.minecraft.server.v1_10_R1.EntityHuman; import net.minecraft.server.v1_10_R1.ItemStack; import net.minecraft.server.v1_10_R1.PlayerInventory; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[4]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots); } @@ -92,49 +86,32 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); setItemArrays(this.player.inventory, items, armor, extraSlots); playerOnline = true; } } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(armor, 0, C, items.length, armor.length); - System.arraycopy(extraSlots, 0, C, items.length + armor.length, extraSlots.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + System.arraycopy(extraSlots, 0, contents, items.length + armor.length, extraSlots.length); + return contents; } @Override @@ -277,13 +254,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java index ece75858..54313c22 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_4_5; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,10 +29,10 @@ import org.bukkit.craftbukkit.v1_4_5.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -51,4 +53,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java index b9c43ade..8e40ac2c 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_4_5.EntityHuman; import net.minecraft.server.v1_4_5.IInventory; import net.minecraft.server.v1_4_5.InventoryEnderChest; import net.minecraft.server.v1_4_5.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - @Override - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java index 486568a2..b989c489 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_4_5; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_4_5.EntityHuman; import net.minecraft.server.v1_4_5.ItemStack; import net.minecraft.server.v1_4_5.PlayerInventory; -import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -247,14 +228,10 @@ private int getReversedArmorSlotNum(int i) { @Override public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); } - return player.name; + return player.getName(); } - @Override - public boolean a_(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java index 706cdf8e..4fc97476 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_4_6; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,10 +29,10 @@ import org.bukkit.craftbukkit.v1_4_6.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -51,4 +53,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java index d5107fd9..c1659e80 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_4_6.EntityHuman; import net.minecraft.server.v1_4_6.IInventory; import net.minecraft.server.v1_4_6.InventoryEnderChest; import net.minecraft.server.v1_4_6.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - @Override - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java index 1d8114d3..f4fe43fa 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_4_6; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_4_6.EntityHuman; import net.minecraft.server.v1_4_6.ItemStack; import net.minecraft.server.v1_4_6.PlayerInventory; -import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -247,14 +228,10 @@ private int getReversedArmorSlotNum(int i) { @Override public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); } - return player.name; + return player.getName(); } - @Override - public boolean a_(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java index 41a3bbd2..70226c6d 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_4_R1; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -28,10 +30,10 @@ import org.bukkit.craftbukkit.v1_4_R1.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -52,4 +54,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java index 8ce73569..86d9982c 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; // Volatile -import com.lishid.openinv.internal.ISpecialEnderChest; - -import net.minecraft.server.v1_4_R1.EntityHuman; import net.minecraft.server.v1_4_R1.IInventory; import net.minecraft.server.v1_4_R1.InventoryEnderChest; import net.minecraft.server.v1_4_R1.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - @Override - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java index 7d3064c0..e3c760ef 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_4_R1; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -import net.minecraft.server.v1_4_R1.EntityHuman; +// Volatile import net.minecraft.server.v1_4_R1.ItemStack; import net.minecraft.server.v1_4_R1.PlayerInventory; -// Volatile -import org.bukkit.craftbukkit.v1_4_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -247,14 +228,10 @@ private int getReversedArmorSlotNum(int i) { @Override public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); } - return player.name; + return player.getName(); } - @Override - public boolean a_(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java index 1eb2e372..6634cb16 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_5_R2; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,10 +29,10 @@ import org.bukkit.craftbukkit.v1_5_R2.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -51,4 +53,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java index 1676c70c..dc47b095 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_5_R2.EntityHuman; import net.minecraft.server.v1_5_R2.IInventory; import net.minecraft.server.v1_5_R2.InventoryEnderChest; import net.minecraft.server.v1_5_R2.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java index b679046b..244dd148 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_5_R2; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_5_R2.EntityHuman; import net.minecraft.server.v1_5_R2.ItemStack; import net.minecraft.server.v1_5_R2.PlayerInventory; -import org.bukkit.craftbukkit.v1_5_R2.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -247,14 +228,10 @@ private int getReversedArmorSlotNum(int i) { @Override public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); } - return player.name; + return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java index b902c3cb..b587fe40 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_5_R3; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,10 +29,10 @@ import org.bukkit.craftbukkit.v1_5_R3.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -51,4 +53,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java index c7383579..2c54d6fc 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_5_R3.EntityHuman; import net.minecraft.server.v1_5_R3.IInventory; import net.minecraft.server.v1_5_R3.InventoryEnderChest; import net.minecraft.server.v1_5_R3.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java index 4e7445f5..349c107e 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_5_R3; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_5_R3.EntityHuman; import net.minecraft.server.v1_5_R3.ItemStack; import net.minecraft.server.v1_5_R3.PlayerInventory; -import org.bukkit.craftbukkit.v1_5_R3.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -247,14 +228,10 @@ private int getReversedArmorSlotNum(int i) { @Override public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); } - return player.name; + return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java index ee2ae258..6b45bd3d 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_6_R1; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,10 +29,10 @@ import org.bukkit.craftbukkit.v1_6_R1.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -51,4 +53,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java index 242cebe2..b1f7b7c7 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_6_R1.EntityHuman; import net.minecraft.server.v1_6_R1.IInventory; import net.minecraft.server.v1_6_R1.InventoryEnderChest; import net.minecraft.server.v1_6_R1.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java index aa34c547..e1b2aada 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java @@ -16,34 +16,26 @@ package com.lishid.openinv.internal.v1_6_R1; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_6_R1.EntityHuman; import net.minecraft.server.v1_6_R1.ItemStack; import net.minecraft.server.v1_6_R1.PlayerInventory; -import org.bukkit.craftbukkit.v1_6_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory; - public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -54,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -75,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -217,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -254,8 +234,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java index ec810fcd..c8f20f6a 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_6_R2; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,10 +29,10 @@ import org.bukkit.craftbukkit.v1_6_R2.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -51,4 +53,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java index 608e30c9..74b355a1 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_6_R2.EntityHuman; import net.minecraft.server.v1_6_R2.IInventory; import net.minecraft.server.v1_6_R2.InventoryEnderChest; import net.minecraft.server.v1_6_R2.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java index 0f3bbae8..b36df8e9 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_6_R2; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_6_R2.EntityHuman; import net.minecraft.server.v1_6_R2.ItemStack; import net.minecraft.server.v1_6_R2.PlayerInventory; -import org.bukkit.craftbukkit.v1_6_R2.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java index f5fa7d1f..626ef7b2 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_6_R3; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -27,10 +29,10 @@ import org.bukkit.craftbukkit.v1_6_R3.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -51,4 +53,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java index 3c5763f2..fc01228c 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_6_R3.EntityHuman; import net.minecraft.server.v1_6_R3.IInventory; import net.minecraft.server.v1_6_R3.InventoryEnderChest; import net.minecraft.server.v1_6_R3.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java index b13a5ed7..1bba7595 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_6_R3; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_6_R3.EntityHuman; import net.minecraft.server.v1_6_R3.ItemStack; import net.minecraft.server.v1_6_R3.PlayerInventory; -import org.bukkit.craftbukkit.v1_6_R3.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack); + player.drop(itemstack); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java index 7f336199..b857c3eb 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_7_R1; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -28,10 +30,10 @@ import org.bukkit.craftbukkit.v1_7_R1.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); GameProfile profile = new GameProfile(null, offline.getName()); @@ -53,4 +55,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java index a3fc7483..ba4a7604 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_7_R1.EntityHuman; import net.minecraft.server.v1_7_R1.IInventory; import net.minecraft.server.v1_7_R1.InventoryEnderChest; import net.minecraft.server.v1_7_R1.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,9 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java index 3e6beb29..975974b5 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_7_R1; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_7_R1.EntityHuman; import net.minecraft.server.v1_7_R1.ItemStack; import net.minecraft.server.v1_7_R1.PlayerInventory; -import org.bukkit.craftbukkit.v1_7_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getInventoryName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java index 57b899c1..15c98dc5 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_7_R2; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -28,10 +30,10 @@ import org.bukkit.craftbukkit.v1_7_R2.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); GameProfile profile = new GameProfile(null, offline.getName()); @@ -53,4 +55,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getName(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java index 14c67cc9..88f3a5d6 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_7_R2.EntityHuman; import net.minecraft.server.v1_7_R2.IInventory; import net.minecraft.server.v1_7_R2.InventoryEnderChest; import net.minecraft.server.v1_7_R2.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java index ab19a620..5c884cb5 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_7_R2; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_7_R2.EntityHuman; import net.minecraft.server.v1_7_R2.ItemStack; import net.minecraft.server.v1_7_R2.PlayerInventory; -import org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getInventoryName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java index e16bb46b..56b2c0cd 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_7_R3; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -28,10 +30,10 @@ import org.bukkit.craftbukkit.v1_7_R3.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); @@ -53,4 +55,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java index 7b369a46..fe1bc434 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - // Volatile -import net.minecraft.server.v1_7_R3.EntityHuman; import net.minecraft.server.v1_7_R3.IInventory; import net.minecraft.server.v1_7_R3.InventoryEnderChest; import net.minecraft.server.v1_7_R3.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java index 97468319..05db8b5d 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_7_R3; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_7_R3.EntityHuman; import net.minecraft.server.v1_7_R3.ItemStack; import net.minecraft.server.v1_7_R3.PlayerInventory; -import org.bukkit.craftbukkit.v1_7_R3.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getInventoryName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java index a0c28dbd..279b3107 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java @@ -16,6 +16,8 @@ package com.lishid.openinv.internal.v1_7_R4; +import com.lishid.openinv.internal.IPlayerDataManager; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -28,10 +30,10 @@ import org.bukkit.craftbukkit.v1_7_R4.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); @@ -53,4 +55,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java index 2634a7ff..a7b070bd 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java @@ -20,16 +20,14 @@ import java.util.ArrayList; import java.util.List; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - //Volatile -import net.minecraft.server.v1_7_R4.EntityHuman; import net.minecraft.server.v1_7_R4.IInventory; import net.minecraft.server.v1_7_R4.InventoryEnderChest; import net.minecraft.server.v1_7_R4.InventorySubcontainer; @@ -41,7 +39,6 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); public List transaction = new ArrayList(); @@ -49,9 +46,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento private CraftPlayer owner; private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { + public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; CraftPlayer player = (CraftPlayer) p; this.enderChest = player.getHandle().getEnderChest(); this.owner = player; @@ -63,15 +59,6 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { @@ -88,9 +75,13 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override @@ -106,7 +97,6 @@ public void onOpen(CraftHumanEntity who) { @Override public void onClose(CraftHumanEntity who) { transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override @@ -129,22 +119,10 @@ public int getMaxStackSize() { return maxStack; } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - @Override - public void startOpen() { - - } - - public void f() { - - } - @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java index 637952fa..40d5d4a8 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_7_R4; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_7_R4.EntityHuman; import net.minecraft.server.v1_7_R4.ItemStack; import net.minecraft.server.v1_7_R4.PlayerInventory; -import org.bukkit.craftbukkit.v1_7_R4.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getInventoryName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java index 823fba12..1213010c 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java @@ -16,12 +16,14 @@ package com.lishid.openinv.internal.v1_8_R1; +import com.lishid.openinv.internal.IPlayerDataManager; + +import com.mojang.authlib.GameProfile; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import com.mojang.authlib.GameProfile; - import net.minecraft.server.v1_8_R1.EntityPlayer; import net.minecraft.server.v1_8_R1.MinecraftServer; import net.minecraft.server.v1_8_R1.PlayerInteractManager; @@ -29,10 +31,10 @@ //Volatile import org.bukkit.craftbukkit.v1_8_R1.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -53,4 +55,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java index 1d9c891f..2cb7cdac 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java @@ -17,44 +17,31 @@ package com.lishid.openinv.internal.v1_8_R1; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.entity.HumanEntity; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import net.minecraft.server.v1_8_R1.EntityHuman; +//Volatile import net.minecraft.server.v1_8_R1.IInventory; import net.minecraft.server.v1_8_R1.InventoryEnderChest; import net.minecraft.server.v1_8_R1.InventorySubcontainer; -import net.minecraft.server.v1_8_R1.ItemStack; -//Volatile -import org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); - public List transaction = new ArrayList(); public boolean playerOnline = false; - private CraftPlayer owner; - private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; + 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; this.items = enderChest.getContents(); } @@ -63,21 +50,13 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { try { - owner = (CraftPlayer) player; - InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); + this.bukkitOwner = player; + CraftPlayer craftPlayer = (CraftPlayer) player; + InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest(); Field field = playerEnderChest.getClass().getField("items"); field.setAccessible(true); field.set(playerEnderChest, this.items); @@ -88,62 +67,19 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); - } - - @Override - public ItemStack[] getContents() { - return this.items; - } - - @Override - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - @Override - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.inventoryRemovalCheck(true); } @Override - public List getViewers() { - return transaction; - } - - @Override - public InventoryHolder getOwner() { - return this.owner; - } - - @Override - public void setMaxStackSize(int size) { - maxStack = size; - } - - @Override - public int getMaxStackSize() { - return maxStack; - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java index 24e8fdf1..d33caeb4 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_8_R1; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -import net.minecraft.server.v1_8_R1.EntityHuman; -import net.minecraft.server.v1_8_R1.ItemStack; //Volatile +import net.minecraft.server.v1_8_R1.ItemStack; import net.minecraft.server.v1_8_R1.PlayerInventory; -import org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java index b724cb1e..faed23f2 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java @@ -16,12 +16,14 @@ package com.lishid.openinv.internal.v1_8_R2; +import com.lishid.openinv.internal.IPlayerDataManager; + +import com.mojang.authlib.GameProfile; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import com.mojang.authlib.GameProfile; - // Volatile import net.minecraft.server.v1_8_R2.EntityPlayer; import net.minecraft.server.v1_8_R2.MinecraftServer; @@ -29,10 +31,10 @@ import org.bukkit.craftbukkit.v1_8_R2.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); @@ -54,4 +56,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java index 2a9a2df6..4d6a062a 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java @@ -17,44 +17,31 @@ package com.lishid.openinv.internal.v1_8_R2; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.entity.HumanEntity; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; // Volatile -import net.minecraft.server.v1_8_R2.EntityHuman; import net.minecraft.server.v1_8_R2.IInventory; import net.minecraft.server.v1_8_R2.InventoryEnderChest; import net.minecraft.server.v1_8_R2.InventorySubcontainer; -import net.minecraft.server.v1_8_R2.ItemStack; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); - public List transaction = new ArrayList(); public boolean playerOnline = false; - private CraftPlayer owner; - private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; + 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; this.items = enderChest.getContents(); } @@ -63,21 +50,13 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { try { - owner = (CraftPlayer) player; - InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); + this.bukkitOwner = player; + CraftPlayer craftPlayer = (CraftPlayer) player; + InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest(); Field field = playerEnderChest.getClass().getField("items"); field.setAccessible(true); field.set(playerEnderChest, this.items); @@ -88,62 +67,19 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); - } - - @Override - public ItemStack[] getContents() { - return this.items; - } - - @Override - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - @Override - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.inventoryRemovalCheck(true); - } - - @Override - public List getViewers() { - return transaction; - } - - @Override - public InventoryHolder getOwner() { - return this.owner; - } - - @Override - public void setMaxStackSize(int size) { - maxStack = size; - } - - @Override - public int getMaxStackSize() { - return maxStack; } @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java index 603377aa..4f32da2f 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_8_R2; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_8_R2.EntityHuman; import net.minecraft.server.v1_8_R2.ItemStack; import net.minecraft.server.v1_8_R2.PlayerInventory; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(armor, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java index cb449fe3..eba27e11 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/PlayerDataManager.java @@ -16,12 +16,14 @@ package com.lishid.openinv.internal.v1_8_R3; +import com.lishid.openinv.internal.IPlayerDataManager; + +import com.mojang.authlib.GameProfile; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import com.mojang.authlib.GameProfile; - import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.PlayerInteractManager; @@ -29,10 +31,10 @@ //Volatile import org.bukkit.craftbukkit.v1_8_R3.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); @@ -54,4 +56,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java index ee41e9ae..c761557f 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialEnderChest.java @@ -17,44 +17,31 @@ package com.lishid.openinv.internal.v1_8_R3; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.entity.HumanEntity; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; // Volatile -import net.minecraft.server.v1_8_R3.EntityHuman; import net.minecraft.server.v1_8_R3.IInventory; import net.minecraft.server.v1_8_R3.InventoryEnderChest; import net.minecraft.server.v1_8_R3.InventorySubcontainer; -import net.minecraft.server.v1_8_R3.ItemStack; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); - public List transaction = new ArrayList(); public boolean playerOnline = false; - private CraftPlayer owner; - private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; + 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; this.items = enderChest.getContents(); } @@ -63,21 +50,13 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { try { - owner = (CraftPlayer) player; - InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); + this.bukkitOwner = player; + CraftPlayer craftPlayer = (CraftPlayer) player; + InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest(); Field field = playerEnderChest.getClass().getField("items"); field.setAccessible(true); field.set(playerEnderChest, this.items); @@ -88,62 +67,19 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); - } - - @Override - public ItemStack[] getContents() { - return this.items; - } - - @Override - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - @Override - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.inventoryRemovalCheck(true); - } - - @Override - public List getViewers() { - return transaction; - } - - @Override - public InventoryHolder getOwner() { - return this.owner; - } - - @Override - public void setMaxStackSize(int size) { - maxStack = size; - } - - @Override - public int getMaxStackSize() { - return maxStack; } @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java index a5af339a..5430e265 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_8_R3/SpecialPlayerInventory.java @@ -16,33 +16,26 @@ package com.lishid.openinv.internal.v1_8_R3; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - //Volatile -import net.minecraft.server.v1_8_R3.EntityHuman; import net.minecraft.server.v1_8_R3.ItemStack; import net.minecraft.server.v1_8_R3.PlayerInventory; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[5]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; this.items = player.inventory.items; this.armor = player.inventory.armor; @@ -53,20 +46,10 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); this.player.inventory.items = this.items; this.player.inventory.armor = this.armor; playerOnline = true; @@ -74,23 +57,21 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(armor, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + return contents; } @Override @@ -216,13 +197,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -253,8 +234,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java index 83bedd8f..e59e2345 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/PlayerDataManager.java @@ -16,12 +16,14 @@ package com.lishid.openinv.internal.v1_9_R1; +import com.lishid.openinv.internal.IPlayerDataManager; + +import com.mojang.authlib.GameProfile; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import com.mojang.authlib.GameProfile; - // Volatile import net.minecraft.server.v1_9_R1.EntityPlayer; import net.minecraft.server.v1_9_R1.MinecraftServer; @@ -29,10 +31,10 @@ import org.bukkit.craftbukkit.v1_9_R1.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { if (offline == null || !offline.hasPlayedBefore()) { return null; } @@ -56,4 +58,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java index a52391b5..3fd247d9 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialEnderChest.java @@ -17,44 +17,31 @@ package com.lishid.openinv.internal.v1_9_R1; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.entity.HumanEntity; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; // Volatile -import net.minecraft.server.v1_9_R1.EntityHuman; import net.minecraft.server.v1_9_R1.IInventory; import net.minecraft.server.v1_9_R1.InventoryEnderChest; import net.minecraft.server.v1_9_R1.InventorySubcontainer; -import net.minecraft.server.v1_9_R1.ItemStack; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); - public List transaction = new ArrayList(); public boolean playerOnline = false; - private CraftPlayer owner; - private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; + 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; this.items = enderChest.getContents(); } @@ -63,21 +50,13 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { try { - owner = (CraftPlayer) player; - InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); + this.bukkitOwner = player; + CraftPlayer craftPlayer = (CraftPlayer) player; + InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest(); Field field = playerEnderChest.getClass().getField("items"); field.setAccessible(true); field.set(playerEnderChest, this.items); @@ -88,62 +67,19 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); - } - - @Override - public ItemStack[] getContents() { - return this.items; - } - - @Override - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - @Override - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.inventoryRemovalCheck(true); - } - - @Override - public List getViewers() { - return transaction; - } - - @Override - public InventoryHolder getOwner() { - return this.owner; - } - - @Override - public void setMaxStackSize(int size) { - maxStack = size; - } - - @Override - public int getMaxStackSize() { - return maxStack; } @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java index 4b49371e..768dabeb 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R1/SpecialPlayerInventory.java @@ -19,33 +19,26 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_9_R1.EntityHuman; import net.minecraft.server.v1_9_R1.ItemStack; import net.minecraft.server.v1_9_R1.PlayerInventory; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[4]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots); } @@ -92,44 +85,32 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); setItemArrays(this.player.inventory, items, armor, extraSlots); playerOnline = true; } } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); } @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.inventoryRemovalCheck(true); + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(armor, 0, C, items.length, armor.length); - System.arraycopy(extraSlots, 0, C, items.length + armor.length, extraSlots.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + System.arraycopy(extraSlots, 0, contents, items.length + armor.length, extraSlots.length); + return contents; } @Override @@ -277,13 +258,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -314,8 +295,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java index 61f5cf18..566ccb96 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R2/PlayerDataManager.java @@ -16,12 +16,14 @@ package com.lishid.openinv.internal.v1_9_R2; +import com.lishid.openinv.internal.IPlayerDataManager; + +import com.mojang.authlib.GameProfile; + import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import com.mojang.authlib.GameProfile; - // Volatile import net.minecraft.server.v1_9_R2.EntityPlayer; import net.minecraft.server.v1_9_R2.MinecraftServer; @@ -29,10 +31,10 @@ import org.bukkit.craftbukkit.v1_9_R2.CraftServer; -public class PlayerDataManager extends com.lishid.openinv.internal.PlayerDataManager { +public class PlayerDataManager implements IPlayerDataManager { @Override - public Player loadOfflinePlayer(OfflinePlayer offline) { + public Player loadPlayer(OfflinePlayer offline) { if (offline == null || !offline.hasPlayedBefore()) { return null; } @@ -56,4 +58,5 @@ public Player loadOfflinePlayer(OfflinePlayer offline) { public String getPlayerDataID(OfflinePlayer player) { return player.getUniqueId().toString(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialEnderChest.java index d1037c4a..51116b7a 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialEnderChest.java @@ -17,44 +17,31 @@ package com.lishid.openinv.internal.v1_9_R2; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.entity.HumanEntity; +import com.lishid.openinv.internal.ISpecialEnderChest; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; // Volatile -import net.minecraft.server.v1_9_R2.EntityHuman; import net.minecraft.server.v1_9_R2.IInventory; import net.minecraft.server.v1_9_R2.InventoryEnderChest; import net.minecraft.server.v1_9_R2.InventorySubcontainer; -import net.minecraft.server.v1_9_R2.ItemStack; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventory; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - private final OpenInv plugin; private final InventoryEnderChest enderChest; private final CraftInventory inventory = new CraftInventory(this); - public List transaction = new ArrayList(); public boolean playerOnline = false; - private CraftPlayer owner; - private int maxStack = MAX_STACK; - public SpecialEnderChest(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - this.plugin = plugin; - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; + 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; this.items = enderChest.getContents(); } @@ -63,21 +50,13 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { try { - owner = (CraftPlayer) player; - InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest(); + this.bukkitOwner = player; + CraftPlayer craftPlayer = (CraftPlayer) player; + InventoryEnderChest playerEnderChest = craftPlayer.getHandle().getEnderChest(); Field field = playerEnderChest.getClass().getField("items"); field.setAccessible(true); field.set(playerEnderChest, this.items); @@ -88,62 +67,19 @@ public void setPlayerOnline(Player player) { } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return inventoryRemovalCheck(false); - } - - @Override - public ItemStack[] getContents() { - return this.items; - } - - @Override - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - @Override - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.inventoryRemovalCheck(true); - } - - @Override - public List getViewers() { - return transaction; - } - - @Override - public InventoryHolder getOwner() { - return this.owner; - } - - @Override - public void setMaxStackSize(int size) { - maxStack = size; - } - - @Override - public int getMaxStackSize() { - return maxStack; } @Override - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public void update() { + super.update(); enderChest.update(); } + } diff --git a/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialPlayerInventory.java index b6fef8a0..48ad6a0d 100644 --- a/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/v1_9_R2/SpecialPlayerInventory.java @@ -19,14 +19,12 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import com.lishid.openinv.internal.ISpecialPlayerInventory; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - // Volatile -import net.minecraft.server.v1_9_R2.EntityHuman; import net.minecraft.server.v1_9_R2.ItemStack; import net.minecraft.server.v1_9_R2.PlayerInventory; @@ -36,16 +34,12 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - private final OpenInv plugin; private final ItemStack[] extra = new ItemStack[4]; private final CraftInventory inventory = new CraftInventory(this); - private CraftPlayer owner; private boolean playerOnline = false; - public SpecialPlayerInventory(OpenInv plugin, Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.plugin = plugin; - this.owner = ((CraftPlayer) p); + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); this.playerOnline = online; setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots); } @@ -92,44 +86,37 @@ public Inventory getBukkitInventory() { return inventory; } - @Override - public boolean inventoryRemovalCheck(boolean save) { - boolean offline = transaction.isEmpty() && !playerOnline; - if (offline && save && !plugin.disableSaving()) { - owner.saveData(); - } - return offline; - } - @Override public void setPlayerOnline(Player player) { if (!playerOnline) { - owner = (CraftPlayer) player; - this.player = owner.getHandle(); + this.player = ((CraftPlayer) player).getHandle(); setItemArrays(this.player.inventory, items, armor, extraSlots); playerOnline = true; } } @Override - public boolean setPlayerOffline() { + public void setPlayerOffline() { playerOnline = false; - return this.inventoryRemovalCheck(false); + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); } @Override public void onClose(CraftHumanEntity who) { super.onClose(who); - this.inventoryRemovalCheck(true); } @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(armor, 0, C, items.length, armor.length); - System.arraycopy(extraSlots, 0, C, items.length + armor.length, extraSlots.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(items, 0, contents, 0, items.length); + System.arraycopy(armor, 0, contents, items.length, armor.length); + System.arraycopy(extraSlots, 0, contents, items.length + armor.length, extraSlots.length); + return contents; } @Override @@ -277,13 +264,13 @@ else if (is == this.armor) { // Effects if (is == this.extra) { - owner.getHandle().drop(itemstack, true); + player.drop(itemstack, true); itemstack = null; } is[i] = itemstack; - owner.getHandle().defaultContainer.b(); + player.defaultContainer.b(); } private int getReversedItemSlotNum(int i) { @@ -314,8 +301,4 @@ public String getName() { return player.getName(); } - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } } diff --git a/src/main/java/com/lishid/openinv/util/Cache.java b/src/main/java/com/lishid/openinv/util/Cache.java new file mode 100644 index 00000000..5a552b3d --- /dev/null +++ b/src/main/java/com/lishid/openinv/util/Cache.java @@ -0,0 +1,160 @@ +package com.lishid.openinv.util; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import com.google.common.collect.Multimap; +import com.google.common.collect.TreeMultimap; + +/** + * A minimal time-based cache implementation backed by a HashMap and TreeMultimap. + * + * @author Jikoo + */ +public class Cache { + + private final Map internal; + private final Multimap expiry; + private final long retention; + private final Function inUseCheck, postRemoval; + + /** + * Constructs a Cache with the specified retention duration, in use function, and post-removal function. + * + * @param retention duration after which keys are automatically invalidated if not in use + * @param inUseCheck Function used to check if a key is considered in use + * @param postRemoval Function used to perform any operations required when a key is invalidated + */ + public Cache(long retention, Function inUseCheck, Function postRemoval) { + this.internal = new HashMap(); + + this.expiry = TreeMultimap.create(new Comparator() { + @Override + public int compare(Long long1, Long long2) { + return long1.compareTo(long2); + } + }, + new Comparator() { + @Override + public int compare(K k1, K k2) { + return 0; + } + }); + + this.retention = retention; + this.inUseCheck = inUseCheck; + this.postRemoval = postRemoval; + } + + /** + * Set a key and value pair. Keys are unique. Using an existing key will cause the old value to + * be overwritten and the expiration timer to be reset. + * + * @param key key with which the specified value is to be associated + * @param value value to be associated with the specified key + */ + public void put(K key, V value) { + // Invalidate key - runs lazy check and ensures value won't be cleaned up early + invalidate(key); + + internal.put(key, value); + expiry.put(System.currentTimeMillis() + 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) { + // Run lazy check to clean cache + lazyCheck(); + + return 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) { + // Run lazy check to clean cache + lazyCheck(); + + return 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) { + // Run lazy check to clean cache + lazyCheck(); + + if (!internal.containsKey(key)) { + // Value either not present or cleaned by lazy check. Either way, we're good + return; + } + + // Remove stored object + internal.remove(key); + + // Remove expiration entry - prevents more work later, plus prevents issues with values invalidating early + for (Iterator> iterator = expiry.entries().iterator(); iterator.hasNext();) { + if (key.equals(iterator.next().getValue())) { + iterator.remove(); + break; + } + } + } + + /** + * Forcibly invalidates all keys, even if they are considered to be in use. + */ + public void invalidateAll() { + for (V value : internal.values()) { + postRemoval.run(value); + } + expiry.clear(); + internal.clear(); + } + + /** + * Invalidate all expired keys that are not considered in use. If a key is expired but is + * considered in use by the provided Function, its expiration time is reset. + */ + private void lazyCheck() { + long now = System.currentTimeMillis(); + long nextExpiry = now + retention; + for (Iterator> iterator = expiry.entries().iterator(); iterator.hasNext();) { + Map.Entry entry = iterator.next(); + + if (entry.getKey() > now) { + break; + } + + iterator.remove(); + + if (inUseCheck.run(internal.get(entry.getValue()))) { + expiry.put(nextExpiry, entry.getValue()); + continue; + } + + V value = internal.remove(entry.getValue()); + + if (value == null) { + continue; + } + + postRemoval.run(value); + } + } + +} diff --git a/src/main/java/com/lishid/openinv/util/Function.java b/src/main/java/com/lishid/openinv/util/Function.java new file mode 100644 index 00000000..37894c1c --- /dev/null +++ b/src/main/java/com/lishid/openinv/util/Function.java @@ -0,0 +1,12 @@ +package com.lishid.openinv.util; + +/** + * Abstraction for some simple cache calls. + * + * @author Jikoo + */ +public abstract class Function { + + public abstract boolean run(V value); + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 35c0f65e..d62b000f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: com.lishid.openinv.OpenInv -version: 2.4.9 +version: 2.5.0 author: lishid authors: [Jikoo] description: > @@ -9,31 +9,31 @@ commands: openinv: aliases: [oi, inv, open] description: Open a player's inventory - permission: OpenInv.openinv + permission: OpenInv.*;OpenInv.openinv usage: | / - Open last person's inventory / - Open a player's inventory openender: aliases: [oe] description: Opens the enderchest of a player - permission: OpenInv.openender + permission: OpenInv.*;OpenInv.openender usage: | / - Opens a player's enderchest searchinv: aliases: [si] description: Search and list players having a specific item - permission: OpenInv.search + permission: OpenInv.*;OpenInv.search usage: | / [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered. silentchest: aliases: [sc, silent] description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound. - permission: OpenInv.silent + permission: OpenInv.*;OpenInv.silent usage: | / [Check] - Checks whether silent chest is enabled anychest: aliases: [ac] description: Toggle anychest function, which allows opening of blocked chests. - permission: OpenInv.anychest + permission: OpenInv.*;OpenInv.anychest usage: | / [Check] - Checks whether anychest is enabled