minor refactor + update internal chest logic
This commit is contained in:
		@@ -17,6 +17,7 @@
 | 
			
		||||
package com.lishid.openinv;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.logging.Logger;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
@@ -33,20 +34,17 @@ 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.utils.UpdateManager;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Open other player's inventory
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @author lishid
 | 
			
		||||
 */
 | 
			
		||||
public class OpenInv extends JavaPlugin {
 | 
			
		||||
    public static final Logger logger = Logger.getLogger("Minecraft.OpenInv");
 | 
			
		||||
 | 
			
		||||
    public static HashMap<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
 | 
			
		||||
    public static HashMap<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
 | 
			
		||||
 | 
			
		||||
    private UpdateManager updater = new UpdateManager();
 | 
			
		||||
    public static Map<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
 | 
			
		||||
    public static Map<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
 | 
			
		||||
 | 
			
		||||
    public static OpenInv mainPlugin;
 | 
			
		||||
 | 
			
		||||
@@ -95,8 +93,6 @@ public class OpenInv extends JavaPlugin {
 | 
			
		||||
        getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
 | 
			
		||||
        getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
 | 
			
		||||
        getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
 | 
			
		||||
 | 
			
		||||
        updater.Initialize(this, getFile());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean NotifySilentChest() {
 | 
			
		||||
@@ -107,10 +103,6 @@ public class OpenInv extends JavaPlugin {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("NotifyAnyChest", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean GetCheckForUpdates() {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("CheckForUpdates", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean GetPlayerItemOpenInvStatus(String name) {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("ItemOpenInv." + name.toLowerCase() + ".toggle", false);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -38,13 +38,13 @@ public class OpenInvPlayerListener implements Listener {
 | 
			
		||||
        ISpecialPlayerInventory inventory = OpenInv.inventories.get(event.getPlayer().getName().toLowerCase());
 | 
			
		||||
 | 
			
		||||
        if (inventory != null) {
 | 
			
		||||
            inventory.PlayerGoOnline(event.getPlayer());
 | 
			
		||||
            inventory.playerOnline(event.getPlayer());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ISpecialEnderChest chest = OpenInv.enderChests.get(event.getPlayer().getName().toLowerCase());
 | 
			
		||||
 | 
			
		||||
        if (chest != null) {
 | 
			
		||||
            chest.PlayerGoOnline(event.getPlayer());
 | 
			
		||||
            chest.playerOnline(event.getPlayer());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -52,11 +52,11 @@ public class OpenInvPlayerListener implements Listener {
 | 
			
		||||
    public void onPlayerQuit(PlayerQuitEvent event) {
 | 
			
		||||
        ISpecialPlayerInventory inventory = OpenInv.inventories.get(event.getPlayer().getName().toLowerCase());
 | 
			
		||||
        if (inventory != null) {
 | 
			
		||||
            inventory.PlayerGoOffline();
 | 
			
		||||
            inventory.playerOffline();
 | 
			
		||||
        }
 | 
			
		||||
        ISpecialEnderChest chest = OpenInv.enderChests.get(event.getPlayer().getName().toLowerCase());
 | 
			
		||||
        if (chest != null) {
 | 
			
		||||
            chest.PlayerGoOffline();
 | 
			
		||||
            chest.playerOffline();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -22,10 +22,8 @@ import org.bukkit.inventory.Inventory;
 | 
			
		||||
public interface ISpecialEnderChest {
 | 
			
		||||
    public Inventory getBukkitInventory();
 | 
			
		||||
 | 
			
		||||
    public void InventoryRemovalCheck();
 | 
			
		||||
    public void playerOnline(Player p);
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p);
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline();
 | 
			
		||||
    public void playerOffline();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -22,9 +22,7 @@ import org.bukkit.inventory.Inventory;
 | 
			
		||||
public interface ISpecialPlayerInventory {
 | 
			
		||||
    public Inventory getBukkitInventory();
 | 
			
		||||
 | 
			
		||||
    public void InventoryRemovalCheck();
 | 
			
		||||
    public void playerOnline(Player p);
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p);
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline();
 | 
			
		||||
    public void playerOffline();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
@@ -75,7 +75,7 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,6 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
@@ -56,7 +55,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
@@ -67,7 +66,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -16,9 +16,8 @@
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_8_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
@@ -33,90 +32,106 @@ import org.bukkit.craftbukkit.v1_8_R1.entity.*;
 | 
			
		||||
public class AnySilentChest implements IAnySilentChest {
 | 
			
		||||
    public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        BlockPosition position = new BlockPosition(x, y, z);
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        BlockChest chest = (BlockChest) Block.getByName("chest");
 | 
			
		||||
 | 
			
		||||
        // If block on top
 | 
			
		||||
        if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()){
 | 
			
		||||
        if (topBlocking(world, position)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block on top
 | 
			
		||||
        if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
 | 
			
		||||
            return true;
 | 
			
		||||
        if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
 | 
			
		||||
            return true;
 | 
			
		||||
        if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
 | 
			
		||||
            return true;
 | 
			
		||||
        if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
 | 
			
		||||
            return true;
 | 
			
		||||
        for (EnumDirection direction : EnumDirectionList.HORIZONTAL) {
 | 
			
		||||
            BlockPosition sidePosition = position.shift(direction);
 | 
			
		||||
            Block var8 = world.getType(sidePosition).getBlock();
 | 
			
		||||
            if (var8 == chest) {
 | 
			
		||||
                if (this.topBlocking(world, sidePosition)) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    private boolean topBlocking(World world, BlockPosition position) {
 | 
			
		||||
        return this.blockOnTop(world, position) || this.ocelotOnTop(world, position);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean blockOnTop(World world, BlockPosition position) {
 | 
			
		||||
        return world.getType(position.up()).getBlock().isOccluding();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean ocelotOnTop(World world, BlockPosition position) {
 | 
			
		||||
        Iterator var3 = world.a(EntityOcelot.class,
 | 
			
		||||
                new AxisAlignedBB((double) position.getX(), (double) (position.getY() + 1),
 | 
			
		||||
                        (double) position.getZ(), (double) (position.getX() + 1),
 | 
			
		||||
                        (double) (position.getY() + 2), (double) (position.getZ() + 1))).iterator();
 | 
			
		||||
 | 
			
		||||
        EntityOcelot var5;
 | 
			
		||||
        do {
 | 
			
		||||
            if (!var3.hasNext()) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Entity var4 = (Entity) var3.next();
 | 
			
		||||
            var5 = (EntityOcelot) var4;
 | 
			
		||||
        } while (!var5.isSitting());
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        BlockPosition position = new BlockPosition(x, y, z);
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z));
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
        if (world.isStatic) {
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
 | 
			
		||||
 | 
			
		||||
        if (!anychest) {
 | 
			
		||||
            if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
 | 
			
		||||
                return true;
 | 
			
		||||
            if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
 | 
			
		||||
                return true;
 | 
			
		||||
            if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
 | 
			
		||||
                return true;
 | 
			
		||||
            if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
 | 
			
		||||
                return true;
 | 
			
		||||
            if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
 | 
			
		||||
                return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
 | 
			
		||||
        	chest = new InventoryLargeChest("Large chest", (ITileInventory) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (ITileInventory) world.getTileEntity(new BlockPosition(x + 1, y, z)));
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (ITileInventory) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (ITileInventory) world.getTileEntity(new BlockPosition(x, y, z + 1)));
 | 
			
		||||
        BlockChest chest = (BlockChest) Block.getByName("chest");
 | 
			
		||||
 | 
			
		||||
        TileEntity tileEntity = world.getTileEntity(position);
 | 
			
		||||
        if (!(tileEntity instanceof TileEntityChest)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ITileInventory tileInventory = (ITileInventory) tileEntity;
 | 
			
		||||
        if (!anychest && this.topBlocking(world, position)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (EnumDirection direction : EnumDirectionList.HORIZONTAL) {
 | 
			
		||||
            BlockPosition side = position.shift(direction);
 | 
			
		||||
            Block block = world.getType(side).getBlock();
 | 
			
		||||
            if (block == chest) {
 | 
			
		||||
                if (!anychest && this.topBlocking(world, side)) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                TileEntity sideTileEntity = world.getTileEntity(side);
 | 
			
		||||
                if (sideTileEntity instanceof TileEntityChest) {
 | 
			
		||||
                    if (direction != EnumDirection.WEST && direction != EnumDirection.NORTH) {
 | 
			
		||||
                        tileInventory = new InventoryLargeChest("container.chestDouble", tileInventory, (TileEntityChest) sideTileEntity);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        tileInventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) sideTileEntity, tileInventory);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = true;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            try {
 | 
			
		||||
                int windowId = 0;
 | 
			
		||||
                try {
 | 
			
		||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
			
		||||
                    windowID.setAccessible(true);
 | 
			
		||||
                    windowId = windowID.getInt(player);
 | 
			
		||||
                    windowId = windowId % 100 + 1;
 | 
			
		||||
                    windowID.setInt(player, windowId);
 | 
			
		||||
                }
 | 
			
		||||
                catch (NoSuchFieldException e) {}
 | 
			
		||||
                player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", new ChatComponentText(((IInventory) chest).getName()), ((IInventory) chest).getSize()));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                if (OpenInv.NotifySilentChest()) {
 | 
			
		||||
                    p.sendMessage("You are opening a chest silently.");
 | 
			
		||||
                }
 | 
			
		||||
                returnValue = false;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
        if (silentchest) {
 | 
			
		||||
            tileInventory = new SilentInventory(tileInventory);
 | 
			
		||||
            if (OpenInv.NotifySilentChest()) {
 | 
			
		||||
                p.sendMessage("You are opening a chest silently.");
 | 
			
		||||
            }
 | 
			
		||||
            returnValue = false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        player.openContainer(tileInventory);
 | 
			
		||||
 | 
			
		||||
        if (anychest && OpenInv.NotifyAnyChest()) {
 | 
			
		||||
            p.sendMessage("You are opening a blocked chest.");
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package com.lishid.openinv.internal.v1_8_R1;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.Iterators;
 | 
			
		||||
import net.minecraft.server.v1_8_R1.*;
 | 
			
		||||
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
 | 
			
		||||
public enum EnumDirectionList implements Iterable<EnumDirection> {
 | 
			
		||||
    HORIZONTAL(EnumDirectionLimit.HORIZONTAL),
 | 
			
		||||
    VERTICAL(EnumDirectionLimit.VERTICAL);
 | 
			
		||||
 | 
			
		||||
    private EnumDirectionLimit list;
 | 
			
		||||
 | 
			
		||||
    private EnumDirectionList(EnumDirectionLimit list) {
 | 
			
		||||
        this.list = list;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Iterator<EnumDirection> iterator() {
 | 
			
		||||
        return Iterators.forArray(list.a());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,161 @@
 | 
			
		||||
package com.lishid.openinv.internal.v1_8_R1;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.server.v1_8_R1.*;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftHumanEntity;
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.InventoryHolder;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class SilentInventory implements ITileInventory {
 | 
			
		||||
    public ITileInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentInventory(ITileInventory inv) {
 | 
			
		||||
        this.inv = inv;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean q_() {
 | 
			
		||||
        return inv.q_();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void a(ChestLock chestLock) {
 | 
			
		||||
        inv.a(chestLock);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ChestLock i() {
 | 
			
		||||
        return inv.i();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getSize() {
 | 
			
		||||
        return inv.getSize();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack getItem(int i) {
 | 
			
		||||
        return inv.getItem(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitStack(int i, int i1) {
 | 
			
		||||
        return inv.splitStack(i, i1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
        return inv.splitWithoutUpdate(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemStack) {
 | 
			
		||||
        inv.setItem(i, itemStack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return inv.getMaxStackSize();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        inv.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean a(EntityHuman entityHuman) {
 | 
			
		||||
        return inv.a(entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void startOpen(EntityHuman entityHuman) {
 | 
			
		||||
        inv.startOpen(entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void closeContainer(EntityHuman entityHuman) {
 | 
			
		||||
        inv.closeContainer(entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean b(int i, ItemStack itemStack) {
 | 
			
		||||
        return inv.b(i, itemStack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getProperty(int i) {
 | 
			
		||||
        return inv.getProperty(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(int i, int i1) {
 | 
			
		||||
        inv.b(i, i1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int g() {
 | 
			
		||||
        return inv.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void l() {
 | 
			
		||||
        inv.l();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return inv.getContents();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onOpen(CraftHumanEntity craftHumanEntity) {
 | 
			
		||||
        inv.onOpen(craftHumanEntity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity craftHumanEntity) {
 | 
			
		||||
        inv.onClose(craftHumanEntity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return inv.getViewers();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return inv.getOwner();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setMaxStackSize(int i) {
 | 
			
		||||
        inv.setMaxStackSize(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        return inv.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean hasCustomName() {
 | 
			
		||||
        return inv.hasCustomName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IChatBaseComponent getScoreboardDisplayName() {
 | 
			
		||||
        return inv.getScoreboardDisplayName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Container createContainer(PlayerInventory playerInventory, EntityHuman entityHuman) {
 | 
			
		||||
        return inv.createContainer(playerInventory, entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getContainerName() {
 | 
			
		||||
        return inv.getContainerName();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -34,94 +34,69 @@ import net.minecraft.server.v1_8_R1.*;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R1.entity.*;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R1.inventory.*;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private InventoryEnderChest enderChest;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements ISpecialEnderChest {
 | 
			
		||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private InventoryEnderChest enderChest;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer player = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
			
		||||
        this.owner = player;
 | 
			
		||||
    public SpecialEnderChest(Player p, boolean online) {
 | 
			
		||||
        this(p, ((CraftPlayer) p).getHandle().getEnderChest(), online);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player p, InventoryEnderChest enderchest, boolean online) {
 | 
			
		||||
        super(enderchest.getName(), enderchest.hasCustomName(), enderchest.getSize());
 | 
			
		||||
        this.owner = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = enderchest;
 | 
			
		||||
        this.items = enderChest.getContents();
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void saveOnExit() {
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
            owner.saveData();
 | 
			
		||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void linkInventory(InventoryEnderChest inventory) {
 | 
			
		||||
        inventory.items = this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOnline(Player p) {
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            linkInventory(((CraftPlayer) p).getHandle().getEnderChest());
 | 
			
		||||
            p.saveData();
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        owner.loadData();
 | 
			
		||||
        linkInventory(owner.getHandle().getEnderChest());
 | 
			
		||||
        saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onOpen(CraftHumanEntity who) {
 | 
			
		||||
        transaction.add(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        transaction.remove(who);
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return transaction;
 | 
			
		||||
        super.onClose(who);
 | 
			
		||||
        saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return this.owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMaxStackSize(int size) {
 | 
			
		||||
        maxStack = size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return maxStack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean a(EntityHuman entityhuman) {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void startOpen() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void f() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -29,54 +29,56 @@ import org.bukkit.craftbukkit.v1_8_R1.entity.*;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R1.inventory.*;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
    CraftPlayer owner;
 | 
			
		||||
    public boolean playerOnline = false;
 | 
			
		||||
    private ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
			
		||||
    public SpecialPlayerInventory(Player p, boolean online) {
 | 
			
		||||
        super(((CraftPlayer) p).getHandle());
 | 
			
		||||
        this.owner = ((CraftPlayer) p);
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        this.owner = (CraftPlayer) p;
 | 
			
		||||
        this.items = player.inventory.items;
 | 
			
		||||
        this.armor = player.inventory.armor;
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void InventoryRemovalCheck() {
 | 
			
		||||
        owner.saveData();
 | 
			
		||||
    private void saveOnExit() {
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
            owner.saveData();
 | 
			
		||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOnline(Player player) {
 | 
			
		||||
    private void linkInventory(PlayerInventory inventory) {
 | 
			
		||||
        inventory.items = this.items;
 | 
			
		||||
        inventory.armor = this.armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            p.getHandle().inventory.items = this.items;
 | 
			
		||||
            p.getHandle().inventory.armor = this.armor;
 | 
			
		||||
            linkInventory(p.getHandle().inventory);
 | 
			
		||||
            p.saveData();
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void PlayerGoOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
        owner.loadData();
 | 
			
		||||
        linkInventory(owner.getHandle().inventory);
 | 
			
		||||
        saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        super.onClose(who);
 | 
			
		||||
        this.InventoryRemovalCheck();
 | 
			
		||||
        this.saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -99,16 +101,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -122,16 +122,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -142,8 +140,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
            } else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -151,8 +148,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -164,16 +160,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -182,8 +176,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -195,16 +188,14 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -239,10 +230,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getInventoryName() {
 | 
			
		||||
        if (player.getName().length() > 16) {
 | 
			
		||||
            return player.getName().substring(0, 16);
 | 
			
		||||
        }
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean hasCustomName() {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -250,4 +244,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    public boolean a(EntityHuman entityhuman) {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        player.inventory.update();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,510 +0,0 @@
 | 
			
		||||
package com.lishid.openinv.utils;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Constructor;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
 | 
			
		||||
public final class ReflectionUtil {
 | 
			
		||||
    private ReflectionUtil() {}
 | 
			
		||||
 | 
			
		||||
    public static Class<?> getClass(String name, PackageType type) throws Exception {
 | 
			
		||||
        return Class.forName(type + "." + name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Class<?> getClass(String name, SubPackageType type) throws Exception {
 | 
			
		||||
        return Class.forName(type + "." + name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes) {
 | 
			
		||||
        Class<?>[] p = DataType.convertToPrimitive(parameterTypes);
 | 
			
		||||
        for (Constructor<?> c : clazz.getConstructors())
 | 
			
		||||
            if (DataType.equalsArray(DataType.convertToPrimitive(c.getParameterTypes()), p))
 | 
			
		||||
                return c;
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Constructor<?> getConstructor(String className, PackageType type, Class<?>... parameterTypes) throws Exception {
 | 
			
		||||
        return getConstructor(getClass(className, type), parameterTypes);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Constructor<?> getConstructor(String className, SubPackageType type, Class<?>... parameterTypes) throws Exception {
 | 
			
		||||
        return getConstructor(getClass(className, type), parameterTypes);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object newInstance(Class<?> clazz, Object... args) throws Exception {
 | 
			
		||||
        return getConstructor(clazz, DataType.convertToPrimitive(args)).newInstance(args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object newInstance(String className, PackageType type, Object... args) throws Exception {
 | 
			
		||||
        return newInstance(getClass(className, type), args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object newInstance(String className, SubPackageType type, Object... args) throws Exception {
 | 
			
		||||
        return newInstance(getClass(className, type), args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes) {
 | 
			
		||||
        Class<?>[] p = DataType.convertToPrimitive(parameterTypes);
 | 
			
		||||
        for (Method m : clazz.getMethods())
 | 
			
		||||
            if (m.getName().equals(name) && DataType.equalsArray(DataType.convertToPrimitive(m.getParameterTypes()), p))
 | 
			
		||||
                return m;
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Method getMethod(String className, PackageType type, String name, Class<?>... parameterTypes) throws Exception {
 | 
			
		||||
        return getMethod(getClass(className, type), name, parameterTypes);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Method getMethod(String className, SubPackageType type, String name, Class<?>... parameterTypes) throws Exception {
 | 
			
		||||
        return getMethod(getClass(className, type), name, parameterTypes);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object invokeMethod(String name, Object instance, Object... args) throws Exception {
 | 
			
		||||
        return getMethod(instance.getClass(), name, DataType.convertToPrimitive(args)).invoke(instance, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object invokeMethod(Class<?> clazz, String name, Object instance, Object... args) throws Exception {
 | 
			
		||||
        return getMethod(clazz, name, DataType.convertToPrimitive(args)).invoke(instance, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object invokeMethod(String className, PackageType type, String name, Object instance, Object... args) throws Exception {
 | 
			
		||||
        return invokeMethod(getClass(className, type), name, instance, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object invokeMethod(String className, SubPackageType type, String name, Object instance, Object... args) throws Exception {
 | 
			
		||||
        return invokeMethod(getClass(className, type), name, instance, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Field getField(Class<?> clazz, String name) throws Exception {
 | 
			
		||||
        Field f = clazz.getField(name);
 | 
			
		||||
        f.setAccessible(true);
 | 
			
		||||
        return f;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Field getField(String className, PackageType type, String name) throws Exception {
 | 
			
		||||
        return getField(getClass(className, type), name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Field getField(String className, SubPackageType type, String name) throws Exception {
 | 
			
		||||
        return getField(getClass(className, type), name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Field getDeclaredField(Class<?> clazz, String name) throws Exception {
 | 
			
		||||
        Field f = clazz.getDeclaredField(name);
 | 
			
		||||
        f.setAccessible(true);
 | 
			
		||||
        return f;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Field getDeclaredField(String className, PackageType type, String name) throws Exception {
 | 
			
		||||
        return getDeclaredField(getClass(className, type), name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Field getDeclaredField(String className, SubPackageType type, String name) throws Exception {
 | 
			
		||||
        return getDeclaredField(getClass(className, type), name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getValue(Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getField(instance.getClass(), fieldName).get(instance);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getValue(Class<?> clazz, Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getField(clazz, fieldName).get(instance);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getValue(String className, PackageType type, Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getValue(getClass(className, type), instance, fieldName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getValue(String className, SubPackageType type, Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getValue(getClass(className, type), instance, fieldName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getDeclaredValue(Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getDeclaredField(instance.getClass(), fieldName).get(instance);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getDeclaredValue(Class<?> clazz, Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getDeclaredField(clazz, fieldName).get(instance);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getDeclaredValue(String className, PackageType type, Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getDeclaredValue(getClass(className, type), instance, fieldName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getDeclaredValue(String className, SubPackageType type, Object instance, String fieldName) throws Exception {
 | 
			
		||||
        return getDeclaredValue(getClass(className, type), instance, fieldName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        Field f = getField(instance.getClass(), fieldName);
 | 
			
		||||
        f.set(instance, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setValue(instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(Class<?> clazz, Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        Field f = getField(clazz, fieldName);
 | 
			
		||||
        f.set(instance, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(Class<?> clazz, Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setValue(clazz, instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(String className, PackageType type, Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        setValue(getClass(className, type), instance, fieldName, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(String className, PackageType type, Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setValue(className, type, instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(String className, SubPackageType type, Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        setValue(getClass(className, type), instance, fieldName, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValue(String className, SubPackageType type, Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setValue(className, type, instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValues(Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        for (FieldPair pair : pairs)
 | 
			
		||||
            setValue(instance, pair);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValues(Class<?> clazz, Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        for (FieldPair pair : pairs)
 | 
			
		||||
            setValue(clazz, instance, pair);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValues(String className, PackageType type, Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        setValues(getClass(className, type), instance, pairs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setValues(String className, SubPackageType type, Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        setValues(getClass(className, type), instance, pairs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        Field f = getDeclaredField(instance.getClass(), fieldName);
 | 
			
		||||
        f.set(instance, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setDeclaredValue(instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(Class<?> clazz, Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        Field f = getDeclaredField(clazz, fieldName);
 | 
			
		||||
        f.set(instance, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(Class<?> clazz, Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setDeclaredValue(clazz, instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(String className, PackageType type, Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        setDeclaredValue(getClass(className, type), instance, fieldName, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(String className, PackageType type, Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setDeclaredValue(className, type, instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(String className, SubPackageType type, Object instance, String fieldName, Object fieldValue) throws Exception {
 | 
			
		||||
        setDeclaredValue(getClass(className, type), instance, fieldName, fieldValue);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValue(String className, SubPackageType type, Object instance, FieldPair pair) throws Exception {
 | 
			
		||||
        setDeclaredValue(className, type, instance, pair.getName(), pair.getValue());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValues(Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        for (FieldPair pair : pairs)
 | 
			
		||||
            setDeclaredValue(instance, pair);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValues(Class<?> clazz, Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        for (FieldPair pair : pairs)
 | 
			
		||||
            setDeclaredValue(clazz, instance, pair);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValues(String className, PackageType type, Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        setDeclaredValues(getClass(className, type), instance, pairs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDeclaredValues(String className, SubPackageType type, Object instance, FieldPair... pairs) throws Exception {
 | 
			
		||||
        setDeclaredValues(getClass(className, type), instance, pairs);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public enum DataType {
 | 
			
		||||
        BYTE(byte.class, Byte.class),
 | 
			
		||||
        SHORT(short.class, Short.class),
 | 
			
		||||
        INTEGER(int.class, Integer.class),
 | 
			
		||||
        LONG(long.class, Long.class),
 | 
			
		||||
        CHARACTER(char.class, Character.class),
 | 
			
		||||
        FLOAT(float.class, Float.class),
 | 
			
		||||
        DOUBLE(double.class, Double.class),
 | 
			
		||||
        BOOLEAN(boolean.class, Boolean.class);
 | 
			
		||||
 | 
			
		||||
        private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>();
 | 
			
		||||
        private final Class<?> primitive;
 | 
			
		||||
        private final Class<?> reference;
 | 
			
		||||
 | 
			
		||||
        static {
 | 
			
		||||
            for (DataType t : values()) {
 | 
			
		||||
                CLASS_MAP.put(t.primitive, t);
 | 
			
		||||
                CLASS_MAP.put(t.reference, t);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private DataType(Class<?> primitive, Class<?> reference) {
 | 
			
		||||
            this.primitive = primitive;
 | 
			
		||||
            this.reference = reference;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Class<?> getPrimitive() {
 | 
			
		||||
            return this.primitive;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Class<?> getReference() {
 | 
			
		||||
            return this.reference;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static DataType fromClass(Class<?> c) {
 | 
			
		||||
            return CLASS_MAP.get(c);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static Class<?> getPrimitive(Class<?> c) {
 | 
			
		||||
            DataType t = fromClass(c);
 | 
			
		||||
            return t == null ? c : t.getPrimitive();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static Class<?> getReference(Class<?> c) {
 | 
			
		||||
            DataType t = fromClass(c);
 | 
			
		||||
            return t == null ? c : t.getReference();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static Class<?>[] convertToPrimitive(Class<?>[] classes) {
 | 
			
		||||
            int length = classes == null ? 0 : classes.length;
 | 
			
		||||
            Class<?>[] types = new Class<?>[length];
 | 
			
		||||
            for (int i = 0; i < length; i++)
 | 
			
		||||
                types[i] = getPrimitive(classes[i]);
 | 
			
		||||
            return types;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static Class<?>[] convertToPrimitive(Object[] objects) {
 | 
			
		||||
            int length = objects == null ? 0 : objects.length;
 | 
			
		||||
            Class<?>[] types = new Class<?>[length];
 | 
			
		||||
            for (int i = 0; i < length; i++)
 | 
			
		||||
                types[i] = getPrimitive(objects[i].getClass());
 | 
			
		||||
            return types;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static boolean equalsArray(Class<?>[] a1, Class<?>[] a2) {
 | 
			
		||||
            if (a1 == null || a2 == null || a1.length != a2.length)
 | 
			
		||||
                return false;
 | 
			
		||||
            for (int i = 0; i < a1.length; i++)
 | 
			
		||||
                if (!a1[i].equals(a2[i]) && !a1[i].isAssignableFrom(a2[i]))
 | 
			
		||||
                    return false;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public final class FieldPair {
 | 
			
		||||
        private final String name;
 | 
			
		||||
        private final Object value;
 | 
			
		||||
 | 
			
		||||
        public FieldPair(String name, Object value) {
 | 
			
		||||
            this.name = name;
 | 
			
		||||
            this.value = value;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getName() {
 | 
			
		||||
            return this.name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Object getValue() {
 | 
			
		||||
            return this.value;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public enum PackageType {
 | 
			
		||||
        MINECRAFT_SERVER("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().substring(23)),
 | 
			
		||||
        CRAFTBUKKIT(Bukkit.getServer().getClass().getPackage().getName());
 | 
			
		||||
 | 
			
		||||
        private final String name;
 | 
			
		||||
 | 
			
		||||
        private PackageType(String name) {
 | 
			
		||||
            this.name = name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getName() {
 | 
			
		||||
            return this.name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public String toString() {
 | 
			
		||||
            return name;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public enum SubPackageType {
 | 
			
		||||
        BLOCK,
 | 
			
		||||
        CHUNKIO,
 | 
			
		||||
        COMMAND,
 | 
			
		||||
        CONVERSATIONS,
 | 
			
		||||
        ENCHANTMENS,
 | 
			
		||||
        ENTITY,
 | 
			
		||||
        EVENT,
 | 
			
		||||
        GENERATOR,
 | 
			
		||||
        HELP,
 | 
			
		||||
        INVENTORY,
 | 
			
		||||
        MAP,
 | 
			
		||||
        METADATA,
 | 
			
		||||
        POTION,
 | 
			
		||||
        PROJECTILES,
 | 
			
		||||
        SCHEDULER,
 | 
			
		||||
        SCOREBOARD,
 | 
			
		||||
        UPDATER,
 | 
			
		||||
        UTIL;
 | 
			
		||||
 | 
			
		||||
        private final String name;
 | 
			
		||||
 | 
			
		||||
        private SubPackageType() {
 | 
			
		||||
            name = PackageType.CRAFTBUKKIT + "." + name().toLowerCase();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getName() {
 | 
			
		||||
            return this.name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public String toString() {
 | 
			
		||||
            return name;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public enum PacketType {
 | 
			
		||||
        HANDSHAKING_IN_SET_PROTOCOL("PacketHandshakingInSetProtocol"),
 | 
			
		||||
        LOGIN_IN_ENCRYPTION_BEGIN("PacketLoginInEncryptionBegin"),
 | 
			
		||||
        LOGIN_IN_START("PacketLoginInStart"),
 | 
			
		||||
        LOGIN_OUT_DISCONNECT("PacketLoginOutDisconnect"),
 | 
			
		||||
        LOGIN_OUT_ENCRYPTION_BEGIN("PacketLoginOutEncryptionBegin"),
 | 
			
		||||
        LOGIN_OUT_SUCCESS("PacketLoginOutSuccess"),
 | 
			
		||||
        PLAY_IN_ABILITIES("PacketPlayInAbilities"),
 | 
			
		||||
        PLAY_IN_ARM_ANIMATION("PacketPlayInArmAnimation"),
 | 
			
		||||
        PLAY_IN_BLOCK_DIG("PacketPlayInBlockDig"),
 | 
			
		||||
        PLAY_IN_BLOCK_PLACE("PacketPlayInBlockPlace"),
 | 
			
		||||
        PLAY_IN_CHAT("PacketPlayInChat"),
 | 
			
		||||
        PLAY_IN_CLIENT_COMMAND("PacketPlayInClientCommand"),
 | 
			
		||||
        PLAY_IN_CLOSE_WINDOW("PacketPlayInCloseWindow"),
 | 
			
		||||
        PLAY_IN_CUSTOM_PAYLOAD("PacketPlayInCustomPayload"),
 | 
			
		||||
        PLAY_IN_ENCHANT_ITEM("PacketPlayInEnchantItem"),
 | 
			
		||||
        PLAY_IN_ENTITY_ACTION("PacketPlayInEntityAction"),
 | 
			
		||||
        PLAY_IN_FLYING("PacketPlayInFlying"),
 | 
			
		||||
        PLAY_IN_HELD_ITEM_SLOT("PacketPlayInHeldItemSlot"),
 | 
			
		||||
        PLAY_IN_KEEP_ALIVE("PacketPlayInKeepAlive"),
 | 
			
		||||
        PLAY_IN_LOOK("PacketPlayInLook"),
 | 
			
		||||
        PLAY_IN_POSITION("PacketPlayInPosition"),
 | 
			
		||||
        PLAY_IN_POSITION_LOOK("PacketPlayInPositionLook"),
 | 
			
		||||
        PLAY_IN_SET_CREATIVE_SLOT("PacketPlayInSetCreativeSlot "),
 | 
			
		||||
        PLAY_IN_SETTINGS("PacketPlayInSettings"),
 | 
			
		||||
        PLAY_IN_STEER_VEHICLE("PacketPlayInSteerVehicle"),
 | 
			
		||||
        PLAY_IN_TAB_COMPLETE("PacketPlayInTabComplete"),
 | 
			
		||||
        PLAY_IN_TRANSACTION("PacketPlayInTransaction"),
 | 
			
		||||
        PLAY_IN_UPDATE_SIGN("PacketPlayInUpdateSign"),
 | 
			
		||||
        PLAY_IN_USE_ENTITY("PacketPlayInUseEntity"),
 | 
			
		||||
        PLAY_IN_WINDOW_CLICK("PacketPlayInWindowClick"),
 | 
			
		||||
        PLAY_OUT_ABILITIES("PacketPlayOutAbilities"),
 | 
			
		||||
        PLAY_OUT_ANIMATION("PacketPlayOutAnimation"),
 | 
			
		||||
        PLAY_OUT_ATTACH_ENTITY("PacketPlayOutAttachEntity"),
 | 
			
		||||
        PLAY_OUT_BED("PacketPlayOutBed"),
 | 
			
		||||
        PLAY_OUT_BLOCK_ACTION("PacketPlayOutBlockAction"),
 | 
			
		||||
        PLAY_OUT_BLOCK_BREAK_ANIMATION("PacketPlayOutBlockBreakAnimation"),
 | 
			
		||||
        PLAY_OUT_BLOCK_CHANGE("PacketPlayOutBlockChange"),
 | 
			
		||||
        PLAY_OUT_CHAT("PacketPlayOutChat"),
 | 
			
		||||
        PLAY_OUT_CLOSE_WINDOW("PacketPlayOutCloseWindow"),
 | 
			
		||||
        PLAY_OUT_COLLECT("PacketPlayOutCollect"),
 | 
			
		||||
        PLAY_OUT_CRAFT_PROGRESS_BAR("PacketPlayOutCraftProgressBar"),
 | 
			
		||||
        PLAY_OUT_CUSTOM_PAYLOAD("PacketPlayOutCustomPayload"),
 | 
			
		||||
        PLAY_OUT_ENTITY("PacketPlayOutEntity"),
 | 
			
		||||
        PLAY_OUT_ENTITY_DESTROY("PacketPlayOutEntityDestroy"),
 | 
			
		||||
        PLAY_OUT_ENTITY_EFFECT("PacketPlayOutEntityEffect"),
 | 
			
		||||
        PLAY_OUT_ENTITY_EQUIPMENT("PacketPlayOutEntityEquipment"),
 | 
			
		||||
        PLAY_OUT_ENTITY_HEAD_ROTATION("PacketPlayOutEntityHeadRotation"),
 | 
			
		||||
        PLAY_OUT_ENTITY_LOOK("PacketPlayOutEntityLook"),
 | 
			
		||||
        PLAY_OUT_ENTITY_METADATA("PacketPlayOutEntityMetadata"),
 | 
			
		||||
        PLAY_OUT_ENTITY_STATUS("PacketPlayOutEntityStatus"),
 | 
			
		||||
        PLAY_OUT_ENTITY_TELEPORT("PacketPlayOutEntityTeleport"),
 | 
			
		||||
        PLAY_OUT_ENTITY_VELOCITY("PacketPlayOutEntityVelocity"),
 | 
			
		||||
        PLAY_OUT_EXPERIENCE("PacketPlayOutExperience"),
 | 
			
		||||
        PLAY_OUT_EXPLOSION("PacketPlayOutExplosion"),
 | 
			
		||||
        PLAY_OUT_GAME_STATE_CHANGE("PacketPlayOutGameStateChange"),
 | 
			
		||||
        PLAY_OUT_HELD_ITEM_SLOT("PacketPlayOutHeldItemSlot"),
 | 
			
		||||
        PLAY_OUT_KEEP_ALIVE("PacketPlayOutKeepAlive"),
 | 
			
		||||
        PLAY_OUT_KICK_DISCONNECT("PacketPlayOutKickDisconnect"),
 | 
			
		||||
        PLAY_OUT_LOGIN("PacketPlayOutLogin"),
 | 
			
		||||
        PLAY_OUT_MAP("PacketPlayOutMap"),
 | 
			
		||||
        PLAY_OUT_MAP_CHUNK("PacketPlayOutMapChunk"),
 | 
			
		||||
        PLAY_OUT_MAP_CHUNK_BULK("PacketPlayOutMapChunkBulk"),
 | 
			
		||||
        PLAY_OUT_MULTI_BLOCK_CHANGE("PacketPlayOutMultiBlockChange"),
 | 
			
		||||
        PLAY_OUT_NAMED_ENTITY_SPAWN("PacketPlayOutNamedEntitySpawn"),
 | 
			
		||||
        PLAY_OUT_NAMED_SOUND_EFFECT("PacketPlayOutNamedSoundEffect"),
 | 
			
		||||
        PLAY_OUT_OPEN_SIGN_EDITOR("PacketPlayOutOpenSignEditor"),
 | 
			
		||||
        PLAY_OUT_OPEN_WINDOW("PacketPlayOutOpenWindow"),
 | 
			
		||||
        PLAY_OUT_PLAYER_INFO("PacketPlayOutPlayerInfo"),
 | 
			
		||||
        PLAY_OUT_POSITION("PacketPlayOutPosition"),
 | 
			
		||||
        PLAY_OUT_REL_ENTITY_MOVE("PacketPlayOutRelEntityMove"),
 | 
			
		||||
        PLAY_OUT_REL_ENTITY_MOVE_LOOK("PacketPlayOutRelEntityMoveLook"),
 | 
			
		||||
        PLAY_OUT_REMOVE_ENTITY_EFFECT("PacketPlayOutRemoveEntityEffect"),
 | 
			
		||||
        PLAY_OUT_RESPAWN("PacketPlayOutRespawn"),
 | 
			
		||||
        PLAY_OUT_SCOREBOARD_DISPLAY_OBJECTIVE("PacketPlayOutScoreboardDisplayObjective"),
 | 
			
		||||
        PLAY_OUT_SCOREBOARD_OBJECTIVE("PacketPlayOutScoreboardObjective"),
 | 
			
		||||
        PLAY_OUT_SCOREBOARD_SCORE("PacketPlayOutScoreboardScore"),
 | 
			
		||||
        PLAY_OUT_SCOREBOARD_TEAM("PacketPlayOutScoreboardTeam"),
 | 
			
		||||
        PLAY_OUT_SET_SLOT("PacketPlayOutSetSlot"),
 | 
			
		||||
        PLAY_OUT_SPAWN_ENTITY("PacketPlayOutSpawnEntity"),
 | 
			
		||||
        PLAY_OUT_SPAWN_ENTITY_EXPERIENCE_ORB("PacketPlayOutSpawnEntityExperienceOrb"),
 | 
			
		||||
        PLAY_OUT_SPAWN_ENTITY_LIVING("PacketPlayOutSpawnEntityLiving"),
 | 
			
		||||
        PLAY_OUT_SPAWN_ENTITY_PAINTING("PacketPlayOutSpawnEntityPainting"),
 | 
			
		||||
        PLAY_OUT_SPAWN_ENTITY_WEATHER("PacketPlayOutSpawnEntityWeather"),
 | 
			
		||||
        PLAY_OUT_SPAWN_POSITION("PacketPlayOutSpawnPosition"),
 | 
			
		||||
        PLAY_OUT_STATISTIC("PacketPlayOutStatistic"),
 | 
			
		||||
        PLAY_OUT_TAB_COMPLETE("PacketPlayOutTabComplete"),
 | 
			
		||||
        PLAY_OUT_TILE_ENTITY_DATA("PacketPlayOutTileEntityData"),
 | 
			
		||||
        PLAY_OUT_TRANSACTION("PacketPlayOutTransaction"),
 | 
			
		||||
        PLAY_OUT_UPDATE_ATTRIBUTES("PacketPlayOutUpdateAttributes"),
 | 
			
		||||
        PLAY_OUT_UPDATE_HEALTH("PacketPlayOutUpdateHealth"),
 | 
			
		||||
        PLAY_OUT_UPDATE_SIGN("PacketPlayOutUpdateSign"),
 | 
			
		||||
        PLAY_OUT_UPDATE_TIME("PacketPlayOutUpdateTime"),
 | 
			
		||||
        PLAY_OUT_WINDOW_ITEMS("PacketPlayOutWindowItems"),
 | 
			
		||||
        PLAY_OUT_WORLD_EVENT("PacketPlayOutWorldEvent"),
 | 
			
		||||
        PLAY_OUT_WORLD_PARTICLES("PacketPlayOutWorldParticles"),
 | 
			
		||||
        STATUS_IN_PING("PacketStatusInPing"),
 | 
			
		||||
        STATUS_IN_START("PacketStatusInStart"),
 | 
			
		||||
        STATUS_OUT_PONG("PacketStatusOutPong"),
 | 
			
		||||
        STATUS_OUT_SERVER_INFO("PacketStatusOutServerInfo");
 | 
			
		||||
 | 
			
		||||
        private final String name;
 | 
			
		||||
        private Class<?> packet;
 | 
			
		||||
 | 
			
		||||
        private PacketType(String name) {
 | 
			
		||||
            this.name = name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getName() {
 | 
			
		||||
            return this.getName();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Class<?> getPacket() throws Exception {
 | 
			
		||||
            return packet == null ? packet = ReflectionUtil.getClass(name, PackageType.MINECRAFT_SERVER) : packet;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,34 +0,0 @@
 | 
			
		||||
package com.lishid.openinv.utils;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.utils.Updater.UpdateResult;
 | 
			
		||||
 | 
			
		||||
public class UpdateManager {
 | 
			
		||||
    public Updater updater;
 | 
			
		||||
 | 
			
		||||
    public void Initialize(OpenInv plugin, File file) {
 | 
			
		||||
        updater = new Updater(plugin, 31432, file);
 | 
			
		||||
 | 
			
		||||
        // Create task to update
 | 
			
		||||
        plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void run() {
 | 
			
		||||
                // Check for updates
 | 
			
		||||
                if (OpenInv.GetCheckForUpdates()) {
 | 
			
		||||
                    UpdateResult result = updater.update();
 | 
			
		||||
                    if (result != UpdateResult.NO_UPDATE) {
 | 
			
		||||
                        if (result == UpdateResult.SUCCESS) {
 | 
			
		||||
                            OpenInv.log("Update found! Downloaded new version.");
 | 
			
		||||
                            OpenInv.log("This behaviour can be disabled in the config.yml");
 | 
			
		||||
                        }
 | 
			
		||||
                        else {
 | 
			
		||||
                            OpenInv.log("Update failed, reason: " + result.toString());
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }, 0, 20 * 60 * 1000); // Update every once a while
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,412 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Updater for Bukkit.
 | 
			
		||||
 *
 | 
			
		||||
 * This class provides the means to safely and easily update a plugin, or check to see if it is updated using dev.bukkit.org
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.utils;
 | 
			
		||||
 | 
			
		||||
import java.io.BufferedInputStream;
 | 
			
		||||
import java.io.BufferedOutputStream;
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.FileOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStreamReader;
 | 
			
		||||
import java.net.MalformedURLException;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.net.URLConnection;
 | 
			
		||||
import java.util.Enumeration;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
import java.util.zip.ZipEntry;
 | 
			
		||||
import java.util.zip.ZipFile;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.plugin.Plugin;
 | 
			
		||||
import org.json.simple.JSONArray;
 | 
			
		||||
import org.json.simple.JSONObject;
 | 
			
		||||
import org.json.simple.JSONValue;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed.
 | 
			
		||||
 * <p/>
 | 
			
		||||
 * <b>VERY, VERY IMPORTANT</b>: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed
 | 
			
		||||
 * auto-updating. <br>
 | 
			
		||||
 * It is a <b>BUKKIT POLICY</b> that you include a boolean value in your config that prevents the auto-updater from running <b>AT ALL</b>. <br>
 | 
			
		||||
 * If you fail to include this option in your config, your plugin will be <b>REJECTED</b> when you attempt to submit it to dev.bukkit.org.
 | 
			
		||||
 * <p/>
 | 
			
		||||
 * An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater. <br>
 | 
			
		||||
 * If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Gravity
 | 
			
		||||
 * @version 2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class Updater {
 | 
			
		||||
 | 
			
		||||
    private Plugin plugin;
 | 
			
		||||
    private String versionName;
 | 
			
		||||
    private String versionLink;
 | 
			
		||||
    @SuppressWarnings("unused")
 | 
			
		||||
    private String versionType;
 | 
			
		||||
    @SuppressWarnings("unused")
 | 
			
		||||
    private String versionGameVersion;
 | 
			
		||||
 | 
			
		||||
    private boolean announce; // Whether to announce file downloads
 | 
			
		||||
 | 
			
		||||
    private URL url; // Connecting to RSS
 | 
			
		||||
    private File file; // The plugin's file
 | 
			
		||||
 | 
			
		||||
    private int id = 31432; // Project's Curse ID
 | 
			
		||||
    // SEE https://dev.bukkit.org/home/servermods-apikey/
 | 
			
		||||
    private String apiKey = null; // BukkitDev ServerMods API key
 | 
			
		||||
    private static final String TITLE_VALUE = "name"; // Gets remote file's title
 | 
			
		||||
    private static final String LINK_VALUE = "downloadUrl"; // Gets remote file's download link
 | 
			
		||||
    private static final String TYPE_VALUE = "releaseType"; // Gets remote file's release type
 | 
			
		||||
    private static final String VERSION_VALUE = "gameVersion"; // Gets remote file's build version
 | 
			
		||||
    private static final String QUERY = "/servermods/files?projectIds="; // Path to GET
 | 
			
		||||
    private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed
 | 
			
		||||
 | 
			
		||||
    private static final String[] NO_UPDATE_TAG = { "-DEV", "-PRE", "-SNAPSHOT" }; // If the version number contains one of these, don't update.
 | 
			
		||||
    private static final int BYTE_SIZE = 1024; // Used for downloading files
 | 
			
		||||
    private String updateFolder;// The folder that downloads will be placed in
 | 
			
		||||
    private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gives the dev the result of the update process. Can be obtained by called getResult().
 | 
			
		||||
     */
 | 
			
		||||
    public enum UpdateResult {
 | 
			
		||||
        /**
 | 
			
		||||
         * The updater found an update, and has readied it to be loaded the next time the server restarts/reloads.
 | 
			
		||||
         */
 | 
			
		||||
        SUCCESS,
 | 
			
		||||
        /**
 | 
			
		||||
         * The updater did not find an update, and nothing was downloaded.
 | 
			
		||||
         */
 | 
			
		||||
        NO_UPDATE,
 | 
			
		||||
        /**
 | 
			
		||||
         * The server administrator has disabled the updating system
 | 
			
		||||
         */
 | 
			
		||||
        DISABLED,
 | 
			
		||||
        /**
 | 
			
		||||
         * The updater found an update, but was unable to download it.
 | 
			
		||||
         */
 | 
			
		||||
        FAIL_DOWNLOAD,
 | 
			
		||||
        /**
 | 
			
		||||
         * For some reason, the updater was unable to contact dev.bukkit.org to download the file.
 | 
			
		||||
         */
 | 
			
		||||
        FAIL_DBO,
 | 
			
		||||
        /**
 | 
			
		||||
         * When running the version check, the file on DBO did not contain the a version in the format 'vVersion' such as 'v1.0'.
 | 
			
		||||
         */
 | 
			
		||||
        FAIL_NOVERSION,
 | 
			
		||||
        /**
 | 
			
		||||
         * The id provided by the plugin running the updater was invalid and doesn't exist on DBO.
 | 
			
		||||
         */
 | 
			
		||||
        FAIL_BADID,
 | 
			
		||||
        /**
 | 
			
		||||
         * The server administrator has improperly configured their API key in the configuration
 | 
			
		||||
         */
 | 
			
		||||
        FAIL_APIKEY,
 | 
			
		||||
        /**
 | 
			
		||||
         * The updater found an update, but because of the UpdateType being set to NO_DOWNLOAD, it wasn't downloaded.
 | 
			
		||||
         */
 | 
			
		||||
        UPDATE_AVAILABLE
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Initialize the updater
 | 
			
		||||
     * 
 | 
			
		||||
     * @param plugin The plugin that is checking for an update.
 | 
			
		||||
     * @param id The dev.bukkit.org id of the project
 | 
			
		||||
     * @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class.
 | 
			
		||||
     */
 | 
			
		||||
    public Updater(Plugin plugin, int id, File file) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
        this.file = file;
 | 
			
		||||
        this.id = id;
 | 
			
		||||
        this.updateFolder = plugin.getServer().getUpdateFolder();
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            this.url = new URL(Updater.HOST + Updater.QUERY + id);
 | 
			
		||||
        }
 | 
			
		||||
        catch (final MalformedURLException e) {
 | 
			
		||||
            plugin.getLogger().severe("The project ID provided for updating, " + id + " is invalid.");
 | 
			
		||||
            this.result = UpdateResult.FAIL_BADID;
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Save an update from dev.bukkit.org into the server's update folder.
 | 
			
		||||
     */
 | 
			
		||||
    private void saveFile(File folder, String file, String u) {
 | 
			
		||||
        if (!folder.exists()) {
 | 
			
		||||
            folder.mkdir();
 | 
			
		||||
        }
 | 
			
		||||
        BufferedInputStream in = null;
 | 
			
		||||
        FileOutputStream fout = null;
 | 
			
		||||
        try {
 | 
			
		||||
            // Download the file
 | 
			
		||||
            final URL url = new URL(u);
 | 
			
		||||
            final int fileLength = url.openConnection().getContentLength();
 | 
			
		||||
            in = new BufferedInputStream(url.openStream());
 | 
			
		||||
            fout = new FileOutputStream(folder.getAbsolutePath() + "/" + file);
 | 
			
		||||
 | 
			
		||||
            final byte[] data = new byte[Updater.BYTE_SIZE];
 | 
			
		||||
            int count;
 | 
			
		||||
            if (this.announce) {
 | 
			
		||||
                this.plugin.getLogger().info("About to download a new update: " + this.versionName);
 | 
			
		||||
            }
 | 
			
		||||
            long downloaded = 0;
 | 
			
		||||
            while ((count = in.read(data, 0, Updater.BYTE_SIZE)) != -1) {
 | 
			
		||||
                downloaded += count;
 | 
			
		||||
                fout.write(data, 0, count);
 | 
			
		||||
                final int percent = (int) ((downloaded * 100) / fileLength);
 | 
			
		||||
                if (this.announce && ((percent % 10) == 0)) {
 | 
			
		||||
                    this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes.");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            // Just a quick check to make sure we didn't leave any files from last time...
 | 
			
		||||
            for (final File xFile : new File(this.plugin.getDataFolder().getParent(), this.updateFolder).listFiles()) {
 | 
			
		||||
                if (xFile.getName().endsWith(".zip")) {
 | 
			
		||||
                    xFile.delete();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            // Check to see if it's a zip file, if it is, unzip it.
 | 
			
		||||
            final File dFile = new File(folder.getAbsolutePath() + "/" + file);
 | 
			
		||||
            if (dFile.getName().endsWith(".zip")) {
 | 
			
		||||
                // Unzip
 | 
			
		||||
                this.unzip(dFile.getCanonicalPath());
 | 
			
		||||
            }
 | 
			
		||||
            if (this.announce) {
 | 
			
		||||
                this.plugin.getLogger().info("Finished updating.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (final Exception ex) {
 | 
			
		||||
            this.plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful.");
 | 
			
		||||
            this.result = Updater.UpdateResult.FAIL_DOWNLOAD;
 | 
			
		||||
        }
 | 
			
		||||
        finally {
 | 
			
		||||
            try {
 | 
			
		||||
                if (in != null) {
 | 
			
		||||
                    in.close();
 | 
			
		||||
                }
 | 
			
		||||
                if (fout != null) {
 | 
			
		||||
                    fout.close();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (final Exception ex) {}
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Part of Zip-File-Extractor, modified by Gravity for use with Bukkit
 | 
			
		||||
     */
 | 
			
		||||
    private void unzip(String file) {
 | 
			
		||||
        try {
 | 
			
		||||
            final File fSourceZip = new File(file);
 | 
			
		||||
            final String zipPath = file.substring(0, file.length() - 4);
 | 
			
		||||
            ZipFile zipFile = new ZipFile(fSourceZip);
 | 
			
		||||
            Enumeration<? extends ZipEntry> e = zipFile.entries();
 | 
			
		||||
            while (e.hasMoreElements()) {
 | 
			
		||||
                ZipEntry entry = e.nextElement();
 | 
			
		||||
                File destinationFilePath = new File(zipPath, entry.getName());
 | 
			
		||||
                destinationFilePath.getParentFile().mkdirs();
 | 
			
		||||
                if (entry.isDirectory()) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
 | 
			
		||||
                    int b;
 | 
			
		||||
                    final byte buffer[] = new byte[Updater.BYTE_SIZE];
 | 
			
		||||
                    final FileOutputStream fos = new FileOutputStream(destinationFilePath);
 | 
			
		||||
                    final BufferedOutputStream bos = new BufferedOutputStream(fos, Updater.BYTE_SIZE);
 | 
			
		||||
                    while ((b = bis.read(buffer, 0, Updater.BYTE_SIZE)) != -1) {
 | 
			
		||||
                        bos.write(buffer, 0, b);
 | 
			
		||||
                    }
 | 
			
		||||
                    bos.flush();
 | 
			
		||||
                    bos.close();
 | 
			
		||||
                    bis.close();
 | 
			
		||||
                    final String name = destinationFilePath.getName();
 | 
			
		||||
                    if (name.endsWith(".jar") && this.pluginFile(name)) {
 | 
			
		||||
                        destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                entry = null;
 | 
			
		||||
                destinationFilePath = null;
 | 
			
		||||
            }
 | 
			
		||||
            e = null;
 | 
			
		||||
            zipFile.close();
 | 
			
		||||
            zipFile = null;
 | 
			
		||||
 | 
			
		||||
            // Move any plugin data folders that were included to the right place, Bukkit won't do this for us.
 | 
			
		||||
            for (final File dFile : new File(zipPath).listFiles()) {
 | 
			
		||||
                if (dFile.isDirectory()) {
 | 
			
		||||
                    if (this.pluginFile(dFile.getName())) {
 | 
			
		||||
                        final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir
 | 
			
		||||
                        final File[] contents = oFile.listFiles(); // List of existing files in the current dir
 | 
			
		||||
                        for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir
 | 
			
		||||
                        {
 | 
			
		||||
                            boolean found = false;
 | 
			
		||||
                            for (final File xFile : contents) // Loop through contents to see if it exists
 | 
			
		||||
                            {
 | 
			
		||||
                                if (xFile.getName().equals(cFile.getName())) {
 | 
			
		||||
                                    found = true;
 | 
			
		||||
                                    break;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            if (!found) {
 | 
			
		||||
                                // Move the new file into the current dir
 | 
			
		||||
                                cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName()));
 | 
			
		||||
                            }
 | 
			
		||||
                            else {
 | 
			
		||||
                                // This file already exists, so we don't need it anymore.
 | 
			
		||||
                                cFile.delete();
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                dFile.delete();
 | 
			
		||||
            }
 | 
			
		||||
            new File(zipPath).delete();
 | 
			
		||||
            fSourceZip.delete();
 | 
			
		||||
        }
 | 
			
		||||
        catch (final IOException ex) {
 | 
			
		||||
            this.plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful.");
 | 
			
		||||
            this.result = Updater.UpdateResult.FAIL_DOWNLOAD;
 | 
			
		||||
            ex.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        new File(file).delete();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip.
 | 
			
		||||
     */
 | 
			
		||||
    private boolean pluginFile(String name) {
 | 
			
		||||
        for (final File file : new File("plugins").listFiles()) {
 | 
			
		||||
            if (file.getName().equals(name)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be updated
 | 
			
		||||
     */
 | 
			
		||||
    private boolean versionCheck(String title) {
 | 
			
		||||
        final String version = this.plugin.getDescription().getVersion();
 | 
			
		||||
        if (title.split(" ").length == 2) {
 | 
			
		||||
            final String remoteVersion = title.split(" ")[1].split(" ")[0]; // Get the newest file's version number
 | 
			
		||||
 | 
			
		||||
            if (this.hasTag(version) || version.equalsIgnoreCase(remoteVersion) || !isNewer(version, remoteVersion)) {
 | 
			
		||||
                // We already have the latest version, or this build is tagged for no-update
 | 
			
		||||
                this.result = Updater.UpdateResult.NO_UPDATE;
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            this.plugin.getLogger().warning("File versions should follow the format 'PluginName VERSION'");
 | 
			
		||||
            this.result = Updater.UpdateResult.FAIL_NOVERSION;
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Evaluate whether the version number is marked showing that it should not be updated by this program
 | 
			
		||||
     */
 | 
			
		||||
    private boolean hasTag(String version) {
 | 
			
		||||
        for (final String string : Updater.NO_UPDATE_TAG) {
 | 
			
		||||
            if (version.contains(string)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean read() {
 | 
			
		||||
        try {
 | 
			
		||||
            final URLConnection conn = this.url.openConnection();
 | 
			
		||||
            conn.setConnectTimeout(5000);
 | 
			
		||||
 | 
			
		||||
            if (this.apiKey != null) {
 | 
			
		||||
                conn.addRequestProperty("X-API-Key", this.apiKey);
 | 
			
		||||
            }
 | 
			
		||||
            conn.addRequestProperty("User-Agent", "Updater");
 | 
			
		||||
 | 
			
		||||
            conn.setDoOutput(true);
 | 
			
		||||
 | 
			
		||||
            final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
 | 
			
		||||
            final String response = reader.readLine();
 | 
			
		||||
 | 
			
		||||
            final JSONArray array = (JSONArray) JSONValue.parse(response);
 | 
			
		||||
 | 
			
		||||
            if (array.size() == 0) {
 | 
			
		||||
                this.plugin.getLogger().warning("The updater could not find any files for the project id " + this.id);
 | 
			
		||||
                this.result = UpdateResult.FAIL_BADID;
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.versionName = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TITLE_VALUE);
 | 
			
		||||
            this.versionLink = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.LINK_VALUE);
 | 
			
		||||
            this.versionType = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TYPE_VALUE);
 | 
			
		||||
            this.versionGameVersion = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.VERSION_VALUE);
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        catch (final IOException e) {
 | 
			
		||||
            if (e.getMessage().contains("HTTP response code: 403")) {
 | 
			
		||||
                this.plugin.getLogger().warning("dev.bukkit.org rejected the API key provided in plugins/Updater/config.yml");
 | 
			
		||||
                this.plugin.getLogger().warning("Please double-check your configuration to ensure it is correct.");
 | 
			
		||||
                this.result = UpdateResult.FAIL_APIKEY;
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                this.plugin.getLogger().warning("The updater could not contact curse for updating.");
 | 
			
		||||
                this.result = UpdateResult.FAIL_DBO;
 | 
			
		||||
            }
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static boolean isNewer(String oldVers, String newVers) {
 | 
			
		||||
        String s1 = normalisedVersion(oldVers);
 | 
			
		||||
        String s2 = normalisedVersion(newVers);
 | 
			
		||||
        int cmp = s1.compareTo(s2);
 | 
			
		||||
        return cmp < 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String normalisedVersion(String version) {
 | 
			
		||||
        return normalisedVersion(version, ".", 3);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String normalisedVersion(String version, String sep, int maxWidth) {
 | 
			
		||||
        String[] split = Pattern.compile(sep, Pattern.LITERAL).split(version);
 | 
			
		||||
        StringBuilder sb = new StringBuilder();
 | 
			
		||||
        for (String s : split) {
 | 
			
		||||
            sb.append(String.format("%" + maxWidth + 's', s));
 | 
			
		||||
        }
 | 
			
		||||
        return sb.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UpdateResult update() {
 | 
			
		||||
        if (Updater.this.url != null) {
 | 
			
		||||
            // Obtain the results of the project's file feed
 | 
			
		||||
            if (Updater.this.read()) {
 | 
			
		||||
                if (Updater.this.versionCheck(Updater.this.versionName)) {
 | 
			
		||||
                    if (Updater.this.versionLink != null) {
 | 
			
		||||
                        String name = Updater.this.file.getName();
 | 
			
		||||
                        // If it's a zip file, it shouldn't be downloaded as the plugin's name
 | 
			
		||||
                        if (Updater.this.versionLink.endsWith(".zip")) {
 | 
			
		||||
                            final String[] split = Updater.this.versionLink.split("/");
 | 
			
		||||
                            name = split[split.length - 1];
 | 
			
		||||
                        }
 | 
			
		||||
                        Updater.this.saveFile(new File(Updater.this.plugin.getDataFolder().getParent(), Updater.this.updateFolder), name, Updater.this.versionLink);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return this.result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user