Migrate to UUID usage
This commit is contained in:
		
							
								
								
									
										62
									
								
								pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
				
			|||||||
 | 
					<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
				
			||||||
 | 
					         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
				
			||||||
 | 
					    <modelVersion>4.0.0</modelVersion>
 | 
				
			||||||
 | 
					    <groupId>com.lishid</groupId>
 | 
				
			||||||
 | 
					    <artifactId>openinv</artifactId>
 | 
				
			||||||
 | 
					    <packaging>jar</packaging>
 | 
				
			||||||
 | 
					    <version>2.2.9</version>
 | 
				
			||||||
 | 
					    <name>OpenInv</name>
 | 
				
			||||||
 | 
					    <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <properties>
 | 
				
			||||||
 | 
					        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
				
			||||||
 | 
					    </properties>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <repositories>
 | 
				
			||||||
 | 
					        <repository>
 | 
				
			||||||
 | 
					            <id>bukkit-repo</id>
 | 
				
			||||||
 | 
					            <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
 | 
				
			||||||
 | 
					        </repository>
 | 
				
			||||||
 | 
					    </repositories>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <dependencies>
 | 
				
			||||||
 | 
					        <dependency>
 | 
				
			||||||
 | 
					            <groupId>org.bukkit</groupId>
 | 
				
			||||||
 | 
					            <artifactId>bukkit</artifactId>
 | 
				
			||||||
 | 
					            <version>1.8.7-R0.1-SNAPSHOT</version>
 | 
				
			||||||
 | 
					            <scope>provided</scope>
 | 
				
			||||||
 | 
					        </dependency>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <dependency>
 | 
				
			||||||
 | 
					            <groupId>org.bukkit</groupId>
 | 
				
			||||||
 | 
					            <artifactId>craftbukkit</artifactId>
 | 
				
			||||||
 | 
					            <version>1.8.7-R0.1-SNAPSHOT</version>
 | 
				
			||||||
 | 
					            <scope>provided</scope>
 | 
				
			||||||
 | 
					        </dependency>
 | 
				
			||||||
 | 
					    </dependencies>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <build>
 | 
				
			||||||
 | 
					        <defaultGoal>clean install</defaultGoal>
 | 
				
			||||||
 | 
					        <sourceDirectory>src/main/java</sourceDirectory>
 | 
				
			||||||
 | 
					        <resources>
 | 
				
			||||||
 | 
					            <resource>
 | 
				
			||||||
 | 
					                <directory>src/main/resources</directory>
 | 
				
			||||||
 | 
					                <filtering>true</filtering>
 | 
				
			||||||
 | 
					                <excludes>
 | 
				
			||||||
 | 
					                    <exclude>**/*.java</exclude>
 | 
				
			||||||
 | 
					                </excludes>
 | 
				
			||||||
 | 
					            </resource>
 | 
				
			||||||
 | 
					        </resources>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <plugins>
 | 
				
			||||||
 | 
					            <plugin>
 | 
				
			||||||
 | 
					                <artifactId>maven-compiler-plugin</artifactId>
 | 
				
			||||||
 | 
					                <version>2.3.2</version>
 | 
				
			||||||
 | 
					                <configuration>
 | 
				
			||||||
 | 
					                    <source>1.6</source>
 | 
				
			||||||
 | 
					                    <target>1.6</target>
 | 
				
			||||||
 | 
					                </configuration>
 | 
				
			||||||
 | 
					            </plugin>
 | 
				
			||||||
 | 
					        </plugins>
 | 
				
			||||||
 | 
					    </build>
 | 
				
			||||||
 | 
					</project>
 | 
				
			||||||
@@ -18,6 +18,7 @@ package com.lishid.openinv;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.util.HashMap;
 | 
					import java.util.HashMap;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
import java.util.logging.Logger;
 | 
					import java.util.logging.Logger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
@@ -28,12 +29,14 @@ import org.bukkit.plugin.PluginManager;
 | 
				
			|||||||
import org.bukkit.plugin.java.JavaPlugin;
 | 
					import org.bukkit.plugin.java.JavaPlugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.commands.*;
 | 
					import com.lishid.openinv.commands.*;
 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					import com.lishid.openinv.internal.AnySilentChest;
 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					import com.lishid.openinv.internal.InventoryAccess;
 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					import com.lishid.openinv.internal.PlayerDataManager;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					import com.lishid.openinv.internal.SpecialEnderChest;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
				
			||||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
					import com.lishid.openinv.listeners.OpenInvEntityListener;
 | 
				
			||||||
 | 
					import com.lishid.openinv.listeners.OpenInvInventoryListener;
 | 
				
			||||||
 | 
					import com.lishid.openinv.listeners.OpenInvPlayerListener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Open other player's inventory
 | 
					 * Open other player's inventory
 | 
				
			||||||
@@ -43,32 +46,23 @@ import com.lishid.openinv.internal.InternalAccessor;
 | 
				
			|||||||
public class OpenInv extends JavaPlugin {
 | 
					public class OpenInv extends JavaPlugin {
 | 
				
			||||||
    public static final Logger logger = Logger.getLogger("Minecraft.OpenInv");
 | 
					    public static final Logger logger = Logger.getLogger("Minecraft.OpenInv");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static Map<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
 | 
					    public static final Map<UUID, SpecialPlayerInventory> inventories = new HashMap<UUID, SpecialPlayerInventory>();
 | 
				
			||||||
    public static Map<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
 | 
					    public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static OpenInv mainPlugin;
 | 
					    public static OpenInv mainPlugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static IPlayerDataManager playerLoader;
 | 
					    public static PlayerDataManager playerLoader;
 | 
				
			||||||
    public static IInventoryAccess inventoryAccess;
 | 
					    public static InventoryAccess inventoryAccess;
 | 
				
			||||||
    public static IAnySilentChest anySilentChest;
 | 
					    public static AnySilentChest anySilentChest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
    public void onEnable() {
 | 
					    public void onEnable() {
 | 
				
			||||||
        // Get plugin manager
 | 
					        // Get plugin manager
 | 
				
			||||||
        PluginManager pm = getServer().getPluginManager();
 | 
					        PluginManager pm = getServer().getPluginManager();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Version check
 | 
					        playerLoader = new PlayerDataManager();
 | 
				
			||||||
        boolean success = InternalAccessor.Initialize(this.getServer());
 | 
					        inventoryAccess = new InventoryAccess();
 | 
				
			||||||
 | 
					        anySilentChest = new AnySilentChest();
 | 
				
			||||||
        if (!success) {
 | 
					 | 
				
			||||||
            OpenInv.log("Your version of CraftBukkit is not supported.");
 | 
					 | 
				
			||||||
            OpenInv.log("Please look for an updated version of OpenInv.");
 | 
					 | 
				
			||||||
            pm.disablePlugin(this);
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        playerLoader = InternalAccessor.Instance.newPlayerDataManager();
 | 
					 | 
				
			||||||
        inventoryAccess = InternalAccessor.Instance.newInventoryAccess();
 | 
					 | 
				
			||||||
        anySilentChest = InternalAccessor.Instance.newAnySilentChest();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        mainPlugin = this;
 | 
					        mainPlugin = this;
 | 
				
			||||||
        FileConfiguration config = getConfig();
 | 
					        FileConfiguration config = getConfig();
 | 
				
			||||||
@@ -90,8 +84,8 @@ public class OpenInv extends JavaPlugin {
 | 
				
			|||||||
        getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
 | 
					        getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
 | 
				
			||||||
        getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
 | 
					        getCommand("searchinv").setExecutor(new SearchInvPluginCommand());
 | 
				
			||||||
        getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
 | 
					        getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
 | 
				
			||||||
        getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
 | 
					        getCommand("silentchest").setExecutor(new SilentChestPluginCommand());
 | 
				
			||||||
        getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
 | 
					        getCommand("anychest").setExecutor(new AnyChestPluginCommand());
 | 
				
			||||||
        getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
 | 
					        getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,11 +26,9 @@ import com.lishid.openinv.OpenInv;
 | 
				
			|||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AnyChestPluginCommand implements CommandExecutor {
 | 
					public class AnyChestPluginCommand implements CommandExecutor {
 | 
				
			||||||
    public AnyChestPluginCommand(OpenInv plugin) {
 | 
					    @Override
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (command.getName().equalsIgnoreCase("anychest")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            if (!(sender instanceof Player)) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
					                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
@@ -54,4 +52,7 @@ public class AnyChestPluginCommand implements CommandExecutor {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@
 | 
				
			|||||||
package com.lishid.openinv.commands;
 | 
					package com.lishid.openinv.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
import java.util.concurrent.ConcurrentHashMap;
 | 
					import java.util.concurrent.ConcurrentHashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
@@ -28,18 +29,20 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					import com.lishid.openinv.internal.SpecialEnderChest;
 | 
				
			||||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
					import com.lishid.openinv.utils.UUIDUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class OpenEnderPluginCommand implements CommandExecutor {
 | 
					public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			||||||
    private final OpenInv plugin;
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
    public static Map<Player, String> openEnderHistory = new ConcurrentHashMap<Player, String>();
 | 
					    public static final Map<UUID, UUID> openEnderHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public OpenEnderPluginCommand(OpenInv plugin) {
 | 
					    public OpenEnderPluginCommand(OpenInv plugin) {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (command.getName().equalsIgnoreCase("openender")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            if (!(sender instanceof Player)) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
					                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
@@ -58,19 +61,19 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
            Player player = (Player) sender;
 | 
					            Player player = (Player) sender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // History management
 | 
					            // History management
 | 
				
			||||||
        String history = openEnderHistory.get(player);
 | 
					            UUID history = openEnderHistory.get(player.getUniqueId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (history == null || history == "") {
 | 
					            if (history == null) {
 | 
				
			||||||
            history = player.getName();
 | 
					                history = player.getUniqueId();
 | 
				
			||||||
            openEnderHistory.put(player, history);
 | 
					                openEnderHistory.put(player.getUniqueId(), history);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final String name;
 | 
					            final UUID uuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Read from history if target is not named
 | 
					            // Read from history if target is not named
 | 
				
			||||||
            if (args.length < 1) {
 | 
					            if (args.length < 1) {
 | 
				
			||||||
            if (history != null && history != "") {
 | 
					                if (history != null) {
 | 
				
			||||||
                name = history;
 | 
					                    uuid = history;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else {
 | 
					                else {
 | 
				
			||||||
                    sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
 | 
					                    sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
 | 
				
			||||||
@@ -78,11 +81,11 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
            name = args[0];
 | 
					                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final String playername = player.getName();
 | 
					            final UUID playerUUID = player.getUniqueId();
 | 
				
			||||||
        Player target = plugin.getServer().getPlayer(name);
 | 
					            Player target = Bukkit.getPlayer(uuid);
 | 
				
			||||||
            // Targeted player was not found online, start asynchron lookup in files
 | 
					            // Targeted player was not found online, start asynchron lookup in files
 | 
				
			||||||
            if (target == null) {
 | 
					            if (target == null) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
 | 
					                sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
 | 
				
			||||||
@@ -90,12 +93,12 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
                    @Override
 | 
					                    @Override
 | 
				
			||||||
                    public void run() {
 | 
					                    public void run() {
 | 
				
			||||||
                        // Try loading the player's data asynchronly
 | 
					                        // Try loading the player's data asynchronly
 | 
				
			||||||
                    final Player target = OpenInv.playerLoader.loadPlayer(name);
 | 
					                        final Player target = OpenInv.playerLoader.loadPlayer(uuid);
 | 
				
			||||||
                        // Back to synchron to send messages and display inventory
 | 
					                        // Back to synchron to send messages and display inventory
 | 
				
			||||||
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
					                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
				
			||||||
                            @Override
 | 
					                            @Override
 | 
				
			||||||
                            public void run() {
 | 
					                            public void run() {
 | 
				
			||||||
                            Player player = Bukkit.getPlayer(playername);
 | 
					                                Player player = Bukkit.getPlayer(playerUUID);
 | 
				
			||||||
                                // If sender is no longer online after loading the target. Abort!
 | 
					                                // If sender is no longer online after loading the target. Abort!
 | 
				
			||||||
                                if (player == null) {
 | 
					                                if (player == null) {
 | 
				
			||||||
                                    return;
 | 
					                                    return;
 | 
				
			||||||
@@ -112,6 +115,9 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void openInventory(Player player, Player target) {
 | 
					    private void openInventory(Player player, Player target) {
 | 
				
			||||||
        if (target == null) {
 | 
					        if (target == null) {
 | 
				
			||||||
            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
					            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
@@ -136,17 +142,15 @@ public class OpenEnderPluginCommand implements CommandExecutor {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Record the target
 | 
					        // Record the target
 | 
				
			||||||
        openEnderHistory.put(player, target.getName());
 | 
					        openEnderHistory.put(player.getUniqueId(), target.getUniqueId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create the inventory
 | 
					        // Create the inventory
 | 
				
			||||||
        ISpecialEnderChest chest = OpenInv.enderChests.get(target.getName().toLowerCase());
 | 
					        SpecialEnderChest chest = OpenInv.enderChests.get(target.getUniqueId());
 | 
				
			||||||
        if (chest == null) {
 | 
					        if (chest == null) {
 | 
				
			||||||
            chest = InternalAccessor.Instance.newSpecialEnderChest(target, target.isOnline());
 | 
					            chest = new SpecialEnderChest(target, target.isOnline());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Open the inventory
 | 
					        // Open the inventory
 | 
				
			||||||
        player.openInventory(chest.getBukkitInventory());
 | 
					        player.openInventory(chest.getBukkitInventory());
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@
 | 
				
			|||||||
package com.lishid.openinv.commands;
 | 
					package com.lishid.openinv.commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
import java.util.concurrent.ConcurrentHashMap;
 | 
					import java.util.concurrent.ConcurrentHashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
@@ -28,18 +29,20 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
				
			||||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
					import com.lishid.openinv.utils.UUIDUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class OpenInvPluginCommand implements CommandExecutor {
 | 
					public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			||||||
    private final OpenInv plugin;
 | 
					    private final OpenInv plugin;
 | 
				
			||||||
    public static Map<Player, String> openInvHistory = new ConcurrentHashMap<Player, String>();
 | 
					    public static final Map<UUID, UUID> openInvHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public OpenInvPluginCommand(OpenInv plugin) {
 | 
					    public OpenInvPluginCommand(OpenInv plugin) {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (command.getName().equalsIgnoreCase("openinv")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            if (!(sender instanceof Player)) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
					                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
@@ -57,24 +60,25 @@ public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
            Player player = (Player) sender;
 | 
					            Player player = (Player) sender;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // History management
 | 
					            // History management
 | 
				
			||||||
        String history = openInvHistory.get(player);
 | 
					            UUID history = openInvHistory.get(player.getUniqueId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (history == null || history == "") {
 | 
					            if (history == null) {
 | 
				
			||||||
            history = player.getName();
 | 
					                history = player.getUniqueId();
 | 
				
			||||||
            openInvHistory.put(player, history);
 | 
					                openInvHistory.put(player.getUniqueId(), history);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final String name;
 | 
					            final UUID uuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Read from history if target is not named
 | 
					            // Read from history if target is not named
 | 
				
			||||||
            if (args.length < 1) {
 | 
					            if (args.length < 1) {
 | 
				
			||||||
            name = history;
 | 
					                uuid = history;
 | 
				
			||||||
        } else {
 | 
					            }
 | 
				
			||||||
            name = args[0];
 | 
					            else {
 | 
				
			||||||
 | 
					                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final String playername = player.getName();
 | 
					            final UUID playerUUID = player.getUniqueId();
 | 
				
			||||||
        Player target = plugin.getServer().getPlayer(name);
 | 
					            Player target = Bukkit.getPlayer(uuid);
 | 
				
			||||||
            // Targeted player was not found online, start asynchron lookup in files
 | 
					            // Targeted player was not found online, start asynchron lookup in files
 | 
				
			||||||
            if (target == null) {
 | 
					            if (target == null) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
 | 
					                sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup.");
 | 
				
			||||||
@@ -82,12 +86,12 @@ public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
                    @Override
 | 
					                    @Override
 | 
				
			||||||
                    public void run() {
 | 
					                    public void run() {
 | 
				
			||||||
                        // Try loading the player's data asynchronly
 | 
					                        // Try loading the player's data asynchronly
 | 
				
			||||||
                    final Player target = OpenInv.playerLoader.loadPlayer(name);
 | 
					                        final Player target = OpenInv.playerLoader.loadPlayer(uuid);
 | 
				
			||||||
                        // Back to synchron to send messages and display inventory
 | 
					                        // Back to synchron to send messages and display inventory
 | 
				
			||||||
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
					                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
				
			||||||
                            @Override
 | 
					                            @Override
 | 
				
			||||||
                            public void run() {
 | 
					                            public void run() {
 | 
				
			||||||
                            Player player = Bukkit.getPlayer(playername);
 | 
					                                Player player = Bukkit.getPlayer(playerUUID);
 | 
				
			||||||
                                // If sender is no longer online after loading the target. Abort!
 | 
					                                // If sender is no longer online after loading the target. Abort!
 | 
				
			||||||
                                if (player == null) {
 | 
					                                if (player == null) {
 | 
				
			||||||
                                    return;
 | 
					                                    return;
 | 
				
			||||||
@@ -100,9 +104,13 @@ public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                openInventory(player, target);
 | 
					                openInventory(player, target);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void openInventory(Player player, Player target) {
 | 
					    private void openInventory(Player player, Player target) {
 | 
				
			||||||
        if (target == null) {
 | 
					        if (target == null) {
 | 
				
			||||||
            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
					            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
				
			||||||
@@ -128,17 +136,15 @@ public class OpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Record the target
 | 
					        // Record the target
 | 
				
			||||||
        openInvHistory.put(player, target.getName());
 | 
					        openInvHistory.put(player.getUniqueId(), target.getUniqueId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create the inventory
 | 
					        // Create the inventory
 | 
				
			||||||
        ISpecialPlayerInventory inv = OpenInv.inventories.get(target.getName().toLowerCase());
 | 
					        SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId());
 | 
				
			||||||
        if (inv == null) {
 | 
					        if (inv == null) {
 | 
				
			||||||
            inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, target.isOnline());
 | 
					            inv = new SpecialPlayerInventory(target, target.isOnline());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Open the inventory
 | 
					        // Open the inventory
 | 
				
			||||||
        player.openInventory(inv.getBukkitInventory());
 | 
					        player.openInventory(inv.getBukkitInventory());
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,11 +28,9 @@ import com.lishid.openinv.OpenInv;
 | 
				
			|||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SearchInvPluginCommand implements CommandExecutor {
 | 
					public class SearchInvPluginCommand implements CommandExecutor {
 | 
				
			||||||
    public SearchInvPluginCommand() {
 | 
					    @Override
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (command.getName().equalsIgnoreCase("searchinv")) {
 | 
				
			||||||
            if (sender instanceof Player) {
 | 
					            if (sender instanceof Player) {
 | 
				
			||||||
                if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
 | 
					                if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
 | 
				
			||||||
                    sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
 | 
					                    sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
 | 
				
			||||||
@@ -40,7 +38,7 @@ public class SearchInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String PlayerList = "";
 | 
					            String playerList = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Material material = null;
 | 
					            Material material = null;
 | 
				
			||||||
            int count = 1;
 | 
					            int count = 1;
 | 
				
			||||||
@@ -67,11 +65,15 @@ public class SearchInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            for (Player templayer : Bukkit.getServer().getOnlinePlayers()) {
 | 
					            for (Player templayer : Bukkit.getServer().getOnlinePlayers()) {
 | 
				
			||||||
                if (templayer.getInventory().contains(material, count)) {
 | 
					                if (templayer.getInventory().contains(material, count)) {
 | 
				
			||||||
                PlayerList += templayer.getName() + "  ";
 | 
					                    playerList += templayer.getName() + "  ";
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        sender.sendMessage("Players with the item " + material.toString() + ":  " + PlayerList);
 | 
					            sender.sendMessage("Players with the item " + material.toString() + ":  " + playerList);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,11 +26,9 @@ import com.lishid.openinv.OpenInv;
 | 
				
			|||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SilentChestPluginCommand implements CommandExecutor {
 | 
					public class SilentChestPluginCommand implements CommandExecutor {
 | 
				
			||||||
    public SilentChestPluginCommand(OpenInv plugin) {
 | 
					    @Override
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (command.getName().equalsIgnoreCase("silentchest")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            if (!(sender instanceof Player)) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
					                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
@@ -54,4 +52,7 @@ public class SilentChestPluginCommand implements CommandExecutor {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,9 +26,11 @@ import org.bukkit.entity.Player;
 | 
				
			|||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@SuppressWarnings("deprecation")
 | 
				
			||||||
public class ToggleOpenInvPluginCommand implements CommandExecutor {
 | 
					public class ToggleOpenInvPluginCommand implements CommandExecutor {
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
					    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
				
			||||||
 | 
					        if (command.getName().equalsIgnoreCase("toggleopeninv")) {
 | 
				
			||||||
            if (!(sender instanceof Player)) {
 | 
					            if (!(sender instanceof Player)) {
 | 
				
			||||||
                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
					                sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
@@ -57,4 +59,7 @@ public class ToggleOpenInvPluginCommand implements CommandExecutor {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,22 +14,20 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Volatile
 | 
					//Volatile
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.*;
 | 
					import net.minecraft.server.v1_8_R3.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AnySilentChest implements IAnySilentChest {
 | 
					public class AnySilentChest {
 | 
				
			||||||
    public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
 | 
					    public boolean IsAnyChestNeeded(Player p, int x, int y, int z) {
 | 
				
			||||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
					        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
				
			||||||
        BlockPosition position = new BlockPosition(x, y, z);
 | 
					        BlockPosition position = new BlockPosition(x, y, z);
 | 
				
			||||||
@@ -1,11 +1,12 @@
 | 
				
			|||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.google.common.collect.Iterators;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.EnumDirection;
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_8_R3.EnumDirection.EnumDirectionLimit;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.common.collect.Iterators;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_8_R3.EnumDirection;
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_8_R3.EnumDirection.EnumDirectionLimit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public enum EnumDirectionList implements Iterable<EnumDirection> {
 | 
					public enum EnumDirectionList implements Iterable<EnumDirection> {
 | 
				
			||||||
    HORIZONTAL(EnumDirectionLimit.HORIZONTAL),
 | 
					    HORIZONTAL(EnumDirectionLimit.HORIZONTAL),
 | 
				
			||||||
    VERTICAL(EnumDirectionLimit.VERTICAL);
 | 
					    VERTICAL(EnumDirectionLimit.VERTICAL);
 | 
				
			||||||
@@ -20,5 +21,4 @@ public enum EnumDirectionList implements Iterable<EnumDirection> {
 | 
				
			|||||||
    public Iterator<EnumDirection> iterator() {
 | 
					    public Iterator<EnumDirection> iterator() {
 | 
				
			||||||
        return Iterators.forArray(list.a());
 | 
					        return Iterators.forArray(list.a());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,25 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface IAnySilentChest {
 | 
					 | 
				
			||||||
    public boolean IsAnyChestNeeded(Player p, int x, int y, int z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,24 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,23 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,29 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface ISpecialEnderChest {
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOnline(Player p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,28 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public interface ISpecialPlayerInventory {
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOnline(Player p);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,105 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Server;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InternalAccessor {
 | 
					 | 
				
			||||||
    public static InternalAccessor Instance;
 | 
					 | 
				
			||||||
    private String version;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
     * Returns false if version not supported
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public static boolean Initialize(Server server) {
 | 
					 | 
				
			||||||
        Instance = new InternalAccessor();
 | 
					 | 
				
			||||||
        String packageName = server.getClass().getPackage().getName();
 | 
					 | 
				
			||||||
        Instance.version = packageName.substring(packageName.lastIndexOf('.') + 1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            Class.forName("com.lishid.openinv.internal." + Instance.version + ".AnySilentChest");
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void PrintError() {
 | 
					 | 
				
			||||||
        OpenInv.log("OpenInv encountered an error with the CraftBukkit version \"" + Instance.version + "\". Please look for an updated version of OpenInv.");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public IPlayerDataManager newPlayerDataManager() {
 | 
					 | 
				
			||||||
        return (IPlayerDataManager) createObject(IPlayerDataManager.class, "PlayerDataManager");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public IInventoryAccess newInventoryAccess() {
 | 
					 | 
				
			||||||
        return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public IAnySilentChest newAnySilentChest() {
 | 
					 | 
				
			||||||
        return (IAnySilentChest) createObject(IAnySilentChest.class, "AnySilentChest");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialPlayerInventory");
 | 
					 | 
				
			||||||
            if (ISpecialPlayerInventory.class.isAssignableFrom(internalClass)) {
 | 
					 | 
				
			||||||
                return (ISpecialPlayerInventory) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            PrintError();
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ISpecialEnderChest newSpecialEnderChest(Player player, boolean offline) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + ".SpecialEnderChest");
 | 
					 | 
				
			||||||
            if (ISpecialEnderChest.class.isAssignableFrom(internalClass)) {
 | 
					 | 
				
			||||||
                return (ISpecialEnderChest) internalClass.getConstructor(Player.class, Boolean.class).newInstance(player, offline);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            PrintError();
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private Object createObject(Class<? extends Object> assignableClass, String className) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
 | 
					 | 
				
			||||||
            if (assignableClass.isAssignableFrom(internalClass)) {
 | 
					 | 
				
			||||||
                return internalClass.getConstructor().newInstance();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            PrintError();
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -14,23 +14,22 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					import java.lang.reflect.Field;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					import com.lishid.openinv.Permissions;
 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Volatile
 | 
					//Volatile
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.*;
 | 
					import net.minecraft.server.v1_8_R3.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					public class InventoryAccess {
 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					    public boolean check(Inventory inventory, HumanEntity player) {
 | 
				
			||||||
        IInventory inv = grabInventory(inventory);
 | 
					        IInventory inv = grabInventory(inventory);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@@ -14,7 +14,7 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -23,7 +23,6 @@ import org.bukkit.OfflinePlayer;
 | 
				
			|||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
import com.mojang.authlib.GameProfile;
 | 
					import com.mojang.authlib.GameProfile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Volatile
 | 
					//Volatile
 | 
				
			||||||
@@ -31,14 +30,9 @@ import net.minecraft.server.v1_8_R3.*;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					public class PlayerDataManager {
 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					    public Player loadPlayer(UUID uuid) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            UUID uuid = matchUser(name);
 | 
					 | 
				
			||||||
            if (uuid == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
					            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
				
			||||||
            if (player == null) {
 | 
					            if (player == null) {
 | 
				
			||||||
                return null;
 | 
					                return null;
 | 
				
			||||||
@@ -63,39 +57,4 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static UUID matchUser(String search) {
 | 
					 | 
				
			||||||
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(search);
 | 
					 | 
				
			||||||
        if (offlinePlayer != null && offlinePlayer.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return offlinePlayer.getUniqueId();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        UUID found = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = 2147483647;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
 | 
					 | 
				
			||||||
        for (OfflinePlayer player : offlinePlayers) {
 | 
					 | 
				
			||||||
            String name = player.getName();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (name == null){
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (name.equalsIgnoreCase(search)){
 | 
					 | 
				
			||||||
                return player.getUniqueId();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (name.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                int curDelta = name.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
                if (curDelta < delta) {
 | 
					 | 
				
			||||||
                    found = player.getUniqueId();
 | 
					 | 
				
			||||||
                    delta = curDelta;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if (curDelta == 0) {
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -14,12 +14,11 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Volatile
 | 
					//Volatile
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.*;
 | 
					import net.minecraft.server.v1_8_R3.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					public class SilentContainerChest extends ContainerChest {
 | 
				
			||||||
    public IInventory inv;
 | 
					    public IInventory inv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,11 +1,13 @@
 | 
				
			|||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					import org.bukkit.entity.HumanEntity;
 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					//Volatile
 | 
				
			||||||
 | 
					import net.minecraft.server.v1_8_R3.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SilentInventory implements ITileInventory {
 | 
					public class SilentInventory implements ITileInventory {
 | 
				
			||||||
    public ITileInventory inv;
 | 
					    public ITileInventory inv;
 | 
				
			||||||
@@ -109,12 +111,10 @@ public class SilentInventory implements ITileInventory {
 | 
				
			|||||||
        return inv.getContents();
 | 
					        return inv.getContents();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity craftHumanEntity) {
 | 
					    public void onOpen(CraftHumanEntity craftHumanEntity) {
 | 
				
			||||||
        inv.onOpen(craftHumanEntity);
 | 
					        inv.onOpen(craftHumanEntity);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity craftHumanEntity) {
 | 
					    public void onClose(CraftHumanEntity craftHumanEntity) {
 | 
				
			||||||
        inv.onClose(craftHumanEntity);
 | 
					        inv.onClose(craftHumanEntity);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -14,21 +14,20 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					import org.bukkit.inventory.InventoryHolder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Volatile
 | 
					//Volatile
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.*;
 | 
					import net.minecraft.server.v1_8_R3.*;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SpecialEnderChest extends InventorySubcontainer implements ISpecialEnderChest {
 | 
					public class SpecialEnderChest extends InventorySubcontainer {
 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					    private CraftInventory inventory = new CraftInventory(this);
 | 
				
			||||||
    private InventoryEnderChest enderChest;
 | 
					    private InventoryEnderChest enderChest;
 | 
				
			||||||
    private CraftPlayer owner;
 | 
					    private CraftPlayer owner;
 | 
				
			||||||
@@ -44,13 +43,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements ISpecial
 | 
				
			|||||||
        this.enderChest = enderchest;
 | 
					        this.enderChest = enderchest;
 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					        this.items = enderChest.getContents();
 | 
				
			||||||
        this.playerOnline = online;
 | 
					        this.playerOnline = online;
 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					        OpenInv.enderChests.put(owner.getUniqueId(), this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void saveOnExit() {
 | 
					    private void saveOnExit() {
 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					        if (transaction.isEmpty() && !playerOnline) {
 | 
				
			||||||
            owner.saveData();
 | 
					            owner.saveData();
 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					            OpenInv.enderChests.remove(owner.getUniqueId());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -14,21 +14,19 @@
 | 
				
			|||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.lishid.openinv.internal.v1_8_R3;
 | 
					package com.lishid.openinv.internal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					import org.bukkit.inventory.Inventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					import com.lishid.openinv.OpenInv;
 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
//Volatile
 | 
					//Volatile
 | 
				
			||||||
import net.minecraft.server.v1_8_R3.*;
 | 
					import net.minecraft.server.v1_8_R3.*;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
				
			||||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
					import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
					public class SpecialPlayerInventory extends PlayerInventory {
 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					    private CraftInventory inventory = new CraftInventory(this);
 | 
				
			||||||
    private ItemStack[] extra = new ItemStack[5];
 | 
					    private ItemStack[] extra = new ItemStack[5];
 | 
				
			||||||
    private CraftPlayer owner;
 | 
					    private CraftPlayer owner;
 | 
				
			||||||
@@ -40,7 +38,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
        this.items = player.inventory.items;
 | 
					        this.items = player.inventory.items;
 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					        this.armor = player.inventory.armor;
 | 
				
			||||||
        this.playerOnline = online;
 | 
					        this.playerOnline = online;
 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					        OpenInv.inventories.put(owner.getUniqueId(), this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					    public Inventory getBukkitInventory() {
 | 
				
			||||||
@@ -50,7 +48,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
				
			|||||||
    private void saveOnExit() {
 | 
					    private void saveOnExit() {
 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					        if (transaction.isEmpty() && !playerOnline) {
 | 
				
			||||||
            owner.saveData();
 | 
					            owner.saveData();
 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					            OpenInv.inventories.remove(owner.getUniqueId());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,120 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.craftbukkit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        boolean returnValue = true;
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer((IInventory) chest);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                int id = 0;
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
					 | 
				
			||||||
                    windowID.setAccessible(true);
 | 
					 | 
				
			||||||
                    id = windowID.getInt(player);
 | 
					 | 
				
			||||||
                    id = id % 100 + 1;
 | 
					 | 
				
			||||||
                    windowID.setInt(player, id);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                catch (NoSuchFieldException e) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                player.activeContainer.windowId = id;
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.craftbukkit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.craftbukkit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new ItemInWorldManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.craftbukkit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.f();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.craftbukkit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.craftbukkit;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.name.length() > 16) {
 | 
					 | 
				
			||||||
            return player.name.substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.name;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a_(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,120 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        boolean returnValue = true;
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer((IInventory) chest);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                int id = 0;
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
					 | 
				
			||||||
                    windowID.setAccessible(true);
 | 
					 | 
				
			||||||
                    id = windowID.getInt(player);
 | 
					 | 
				
			||||||
                    id = id % 100 + 1;
 | 
					 | 
				
			||||||
                    windowID.setInt(player, id);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                catch (NoSuchFieldException e) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                player.activeContainer.windowId = id;
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new ItemInWorldManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.f();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_5;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_5.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_5.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.name.length() > 16) {
 | 
					 | 
				
			||||||
            return player.name.substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.name;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a_(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,120 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        boolean returnValue = true;
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer((IInventory) chest);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                int id = 0;
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
					 | 
				
			||||||
                    windowID.setAccessible(true);
 | 
					 | 
				
			||||||
                    id = windowID.getInt(player);
 | 
					 | 
				
			||||||
                    id = id % 100 + 1;
 | 
					 | 
				
			||||||
                    windowID.setInt(player, id);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                catch (NoSuchFieldException e) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                player.activeContainer.windowId = id;
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.f();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_6;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_6.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_6.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.name.length() > 16) {
 | 
					 | 
				
			||||||
            return player.name.substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.name;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a_(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,120 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.s(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        boolean returnValue = true;
 | 
					 | 
				
			||||||
        if (!silentchest) {
 | 
					 | 
				
			||||||
            player.openContainer((IInventory) chest);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            try {
 | 
					 | 
				
			||||||
                int id = 0;
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
					 | 
				
			||||||
                    windowID.setAccessible(true);
 | 
					 | 
				
			||||||
                    id = windowID.getInt(player);
 | 
					 | 
				
			||||||
                    id = id % 100 + 1;
 | 
					 | 
				
			||||||
                    windowID.setInt(player, id);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                catch (NoSuchFieldException e) {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                player.activeContainer.windowId = id;
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.f();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_4_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_4_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_R1.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_4_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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.name.length() > 16) {
 | 
					 | 
				
			||||||
            return player.name.substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.name;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a_(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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 Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R2.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.name.length() > 16) {
 | 
					 | 
				
			||||||
            return player.name.substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.name;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.v1_5_R3.SilentContainerChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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 Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_5_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_5_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_5_R3.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.name.length() > 16) {
 | 
					 | 
				
			||||||
            return player.name.substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.name;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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 Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R1.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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 Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R2.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R3.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = world.getTypeId(x, y, z);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.t(x, y + 1, z))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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 Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,97 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.g();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R3.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_6_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_6_R3.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.b(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.b(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x - 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x + 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x, y, z - 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x, y, z + 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,99 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            GameProfile profile = new GameProfile(null, playername);
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R1.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.l_();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R1;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R1.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack, true);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getInventoryName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R2.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.b(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.b(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x - 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x + 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x, y, z - 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x, y, z + 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,99 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (playername == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            GameProfile profile = new GameProfile(null, playername);
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @author Balor (aka Antoine Aflalo)
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    private static String matchUser(final Collection<File> container, final String search) {
 | 
					 | 
				
			||||||
        String found = null;
 | 
					 | 
				
			||||||
        if (search == null) {
 | 
					 | 
				
			||||||
            return found;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        final String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = Integer.MAX_VALUE;
 | 
					 | 
				
			||||||
        for (final File file : container) {
 | 
					 | 
				
			||||||
            final String filename = file.getName();
 | 
					 | 
				
			||||||
            final String str = filename.substring(0, filename.length() - 4);
 | 
					 | 
				
			||||||
            if (!str.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            final int curDelta = str.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
            if (curDelta < delta) {
 | 
					 | 
				
			||||||
                found = str;
 | 
					 | 
				
			||||||
                delta = curDelta;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (curDelta == 0) {
 | 
					 | 
				
			||||||
                break;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R2.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.l_();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R2.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R2.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R2.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack, true);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getInventoryName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,124 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R3.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.b(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.b(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x - 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x + 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x, y, z - 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.b(world.getType(x, y, z + 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,48 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R3.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,105 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.UUID;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            UUID uuid = matchUser(name);
 | 
					 | 
				
			||||||
            if (uuid == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
					 | 
				
			||||||
            if (player == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            GameProfile profile = new GameProfile(uuid, player.getName());
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static UUID matchUser(String search) {
 | 
					 | 
				
			||||||
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(search);
 | 
					 | 
				
			||||||
        if (offlinePlayer != null && offlinePlayer.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return offlinePlayer.getUniqueId();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        UUID found = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = 2147483647;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
 | 
					 | 
				
			||||||
        for (OfflinePlayer player : offlinePlayers) {
 | 
					 | 
				
			||||||
            String name = player.getName();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (name.equalsIgnoreCase(search))
 | 
					 | 
				
			||||||
                return player.getUniqueId();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (name.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                int curDelta = name.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
                if (curDelta < delta) {
 | 
					 | 
				
			||||||
                    found = player.getUniqueId();
 | 
					 | 
				
			||||||
                    delta = curDelta;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if (curDelta == 0) {
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R3.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.l_();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R3.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R3.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R3;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R3.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R3.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R3.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack, true);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getInventoryName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,125 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R4;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IAnySilentChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R4.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R4.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
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        // If block on top
 | 
					 | 
				
			||||||
        if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.getId(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // If block next to chest is chest and has a block on top
 | 
					 | 
				
			||||||
        if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
					 | 
				
			||||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
					 | 
				
			||||||
        World world = player.world;
 | 
					 | 
				
			||||||
        Object chest = (TileEntityChest) world.getTileEntity(x, y, z);
 | 
					 | 
				
			||||||
        if (chest == null)
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int id = Block.getId(world.getType(x, y, z));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!anychest) {
 | 
					 | 
				
			||||||
            if (world.getType(x, y + 1, z).c())
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
            if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
 | 
					 | 
				
			||||||
                return true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (Block.getId(world.getType(x - 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.getId(world.getType(x + 1, y, z)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
					 | 
				
			||||||
        if (Block.getId(world.getType(x, y, z - 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
					 | 
				
			||||||
        if (Block.getId(world.getType(x, y, z + 1)) == id)
 | 
					 | 
				
			||||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        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, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
 | 
					 | 
				
			||||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
					 | 
				
			||||||
                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 (anychest && OpenInv.NotifyAnyChest()) {
 | 
					 | 
				
			||||||
            p.sendMessage("You are opening a blocked chest.");
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return returnValue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,73 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R4;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.Permissions;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R4.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R4.inventory.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class InventoryAccess implements IInventoryAccess {
 | 
					 | 
				
			||||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
					 | 
				
			||||||
        IInventory inv = grabInventory(inventory);
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else if (inv instanceof SpecialEnderChest) {
 | 
					 | 
				
			||||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    private IInventory grabInventory(Inventory inventory) {
 | 
					 | 
				
			||||||
        if(inventory instanceof CraftInventory) {
 | 
					 | 
				
			||||||
            return ((CraftInventory) inventory).getInventory();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        //Use reflection to find the iiventory
 | 
					 | 
				
			||||||
        Class<? extends Inventory> clazz = inventory.getClass();
 | 
					 | 
				
			||||||
        IInventory result = null;
 | 
					 | 
				
			||||||
        for(Field f : clazz.getDeclaredFields()) {
 | 
					 | 
				
			||||||
            f.setAccessible(true);
 | 
					 | 
				
			||||||
            if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    result = (IInventory) f.get(inventory);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                catch (Exception e) {
 | 
					 | 
				
			||||||
                    OpenInv.log(e);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return result;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,108 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R4;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.io.File;
 | 
					 | 
				
			||||||
import java.util.UUID;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					 | 
				
			||||||
import org.bukkit.OfflinePlayer;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
					 | 
				
			||||||
import net.minecraft.util.com.mojang.authlib.GameProfile;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R4.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R4.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
					 | 
				
			||||||
    public Player loadPlayer(String name) {
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            UUID uuid = matchUser(name);
 | 
					 | 
				
			||||||
            if (uuid == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Default player folder
 | 
					 | 
				
			||||||
            File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata");
 | 
					 | 
				
			||||||
            if (!playerfolder.exists()) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
					 | 
				
			||||||
            if (player == null) {
 | 
					 | 
				
			||||||
                return null;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            GameProfile profile = new GameProfile(uuid, player.getName());
 | 
					 | 
				
			||||||
            MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
					 | 
				
			||||||
            // Create an entity to load the player data
 | 
					 | 
				
			||||||
            EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // Get the bukkit entity
 | 
					 | 
				
			||||||
            Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
					 | 
				
			||||||
            if (target != null) {
 | 
					 | 
				
			||||||
                // Load data
 | 
					 | 
				
			||||||
                target.loadData();
 | 
					 | 
				
			||||||
                // Return the entity
 | 
					 | 
				
			||||||
                return target;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        catch (Exception e) {
 | 
					 | 
				
			||||||
            OpenInv.log(e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return null;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private static UUID matchUser(String search) {
 | 
					 | 
				
			||||||
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(search);
 | 
					 | 
				
			||||||
        if (offlinePlayer != null && offlinePlayer.hasPlayedBefore()) {
 | 
					 | 
				
			||||||
            return offlinePlayer.getUniqueId();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        UUID found = null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        String lowerSearch = search.toLowerCase();
 | 
					 | 
				
			||||||
        int delta = 2147483647;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
 | 
					 | 
				
			||||||
        for (OfflinePlayer player : offlinePlayers) {
 | 
					 | 
				
			||||||
            String name = player.getName();
 | 
					 | 
				
			||||||
           
 | 
					 | 
				
			||||||
            if (name == null){
 | 
					 | 
				
			||||||
                continue;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (name.equalsIgnoreCase(search)){
 | 
					 | 
				
			||||||
                return player.getUniqueId();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (name.toLowerCase().startsWith(lowerSearch)) {
 | 
					 | 
				
			||||||
                int curDelta = name.length() - lowerSearch.length();
 | 
					 | 
				
			||||||
                if (curDelta < delta) {
 | 
					 | 
				
			||||||
                    found = player.getUniqueId();
 | 
					 | 
				
			||||||
                    delta = curDelta;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if (curDelta == 0) {
 | 
					 | 
				
			||||||
                    break;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return found;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,36 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R4;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R4.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
public class SilentContainerChest extends ContainerChest {
 | 
					 | 
				
			||||||
    public IInventory inv;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
					 | 
				
			||||||
        super(i1, i2);
 | 
					 | 
				
			||||||
        inv = i2;
 | 
					 | 
				
			||||||
        // close signal
 | 
					 | 
				
			||||||
        inv.closeContainer();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void b(EntityHuman paramEntityHuman) {
 | 
					 | 
				
			||||||
        // Don't send close signal twice, might screw up
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,126 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R4;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.lang.reflect.Field;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.HumanEntity;
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.InventoryHolder;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R4.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R4.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;
 | 
					 | 
				
			||||||
    private CraftInventory inventory = new CraftInventory(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
					 | 
				
			||||||
        CraftPlayer player = (CraftPlayer) p;
 | 
					 | 
				
			||||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
					 | 
				
			||||||
        this.owner = player;
 | 
					 | 
				
			||||||
        this.items = enderChest.getContents();
 | 
					 | 
				
			||||||
        OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.enderChests.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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) {}
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        return this.items;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onOpen(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.add(who);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        transaction.remove(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public List<HumanEntity> getViewers() {
 | 
					 | 
				
			||||||
        return transaction;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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() {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void update() {
 | 
					 | 
				
			||||||
        enderChest.update();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,252 +0,0 @@
 | 
				
			|||||||
/*
 | 
					 | 
				
			||||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is free software: you can redistribute it and/or modify
 | 
					 | 
				
			||||||
 * it under the terms of the GNU General Public License as published by
 | 
					 | 
				
			||||||
 * the Free Software Foundation,  version 3.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * This program is distributed in the hope that it will be useful,
 | 
					 | 
				
			||||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					 | 
				
			||||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					 | 
				
			||||||
 * GNU General Public License for more details.
 | 
					 | 
				
			||||||
 * 
 | 
					 | 
				
			||||||
 * You should have received a copy of the GNU General Public License
 | 
					 | 
				
			||||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
package com.lishid.openinv.internal.v1_7_R4;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					 | 
				
			||||||
import org.bukkit.inventory.Inventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.lishid.openinv.OpenInv;
 | 
					 | 
				
			||||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//Volatile
 | 
					 | 
				
			||||||
import net.minecraft.server.v1_7_R4.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.*;
 | 
					 | 
				
			||||||
import org.bukkit.craftbukkit.v1_7_R4.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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public SpecialPlayerInventory(Player p, Boolean online) {
 | 
					 | 
				
			||||||
        super(((CraftPlayer) p).getHandle());
 | 
					 | 
				
			||||||
        this.owner = ((CraftPlayer) p);
 | 
					 | 
				
			||||||
        this.playerOnline = online;
 | 
					 | 
				
			||||||
        this.items = player.inventory.items;
 | 
					 | 
				
			||||||
        this.armor = player.inventory.armor;
 | 
					 | 
				
			||||||
        OpenInv.inventories.put(owner.getName().toLowerCase(), this);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public Inventory getBukkitInventory() {
 | 
					 | 
				
			||||||
        return inventory;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void InventoryRemovalCheck() {
 | 
					 | 
				
			||||||
        owner.saveData();
 | 
					 | 
				
			||||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
					 | 
				
			||||||
            OpenInv.inventories.remove(owner.getName().toLowerCase());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOnline(Player player) {
 | 
					 | 
				
			||||||
        if (!playerOnline) {
 | 
					 | 
				
			||||||
            CraftPlayer p = (CraftPlayer) player;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.items = this.items;
 | 
					 | 
				
			||||||
            p.getHandle().inventory.armor = this.armor;
 | 
					 | 
				
			||||||
            p.saveData();
 | 
					 | 
				
			||||||
            playerOnline = true;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void playerOffline() {
 | 
					 | 
				
			||||||
        playerOnline = false;
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void onClose(CraftHumanEntity who) {
 | 
					 | 
				
			||||||
        super.onClose(who);
 | 
					 | 
				
			||||||
        this.InventoryRemovalCheck();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack[] getContents() {
 | 
					 | 
				
			||||||
        ItemStack[] C = new ItemStack[getSize()];
 | 
					 | 
				
			||||||
        System.arraycopy(items, 0, C, 0, items.length);
 | 
					 | 
				
			||||||
        System.arraycopy(armor, 0, C, items.length, armor.length);
 | 
					 | 
				
			||||||
        return C;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public int getSize() {
 | 
					 | 
				
			||||||
        return super.getSize() + 5;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack getItem(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return is[i];
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitStack(int i, int j) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (is[i].count <= j) {
 | 
					 | 
				
			||||||
                itemstack = is[i];
 | 
					 | 
				
			||||||
                is[i] = null;
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                itemstack = is[i].a(j);
 | 
					 | 
				
			||||||
                if (is[i].count == 0) {
 | 
					 | 
				
			||||||
                    is[i] = null;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return itemstack;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (is[i] != null) {
 | 
					 | 
				
			||||||
            ItemStack itemstack = is[i];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            is[i] = null;
 | 
					 | 
				
			||||||
            return itemstack;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public void setItem(int i, ItemStack itemstack) {
 | 
					 | 
				
			||||||
        ItemStack[] is = this.items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.armor;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            i = getReversedItemSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (i >= is.length) {
 | 
					 | 
				
			||||||
            i -= is.length;
 | 
					 | 
				
			||||||
            is = this.extra;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        else if (is == this.armor) {
 | 
					 | 
				
			||||||
            i = getReversedArmorSlotNum(i);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Effects
 | 
					 | 
				
			||||||
        if (is == this.extra) {
 | 
					 | 
				
			||||||
            owner.getHandle().drop(itemstack, true);
 | 
					 | 
				
			||||||
            itemstack = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        is[i] = itemstack;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        owner.getHandle().defaultContainer.b();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedItemSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i >= 27)
 | 
					 | 
				
			||||||
            return i - 27;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i + 9;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private int getReversedArmorSlotNum(int i) {
 | 
					 | 
				
			||||||
        if (i == 0)
 | 
					 | 
				
			||||||
            return 3;
 | 
					 | 
				
			||||||
        if (i == 1)
 | 
					 | 
				
			||||||
            return 2;
 | 
					 | 
				
			||||||
        if (i == 2)
 | 
					 | 
				
			||||||
            return 1;
 | 
					 | 
				
			||||||
        if (i == 3)
 | 
					 | 
				
			||||||
            return 0;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            return i;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public String getInventoryName() {
 | 
					 | 
				
			||||||
        if (player.getName().length() > 16) {
 | 
					 | 
				
			||||||
            return player.getName().substring(0, 16);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return player.getName();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public boolean a(EntityHuman entityhuman) {
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user