Compare commits
	
		
			1 Commits
		
	
	
		
			3.0.0
			...
			uuid-rewor
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					e4c23a777e | 
							
								
								
									
										19
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,10 +1,9 @@
 | 
			
		||||
**/.settings
 | 
			
		||||
**/.gitignore
 | 
			
		||||
**/.project
 | 
			
		||||
**/.classpath
 | 
			
		||||
**/.idea
 | 
			
		||||
**/target
 | 
			
		||||
**/bin
 | 
			
		||||
**/lib
 | 
			
		||||
**/out
 | 
			
		||||
**dependency-reduced-pom.xml
 | 
			
		||||
/.settings
 | 
			
		||||
/.gitignore
 | 
			
		||||
/.project
 | 
			
		||||
/.classpath
 | 
			
		||||
/.idea
 | 
			
		||||
/target
 | 
			
		||||
/bin
 | 
			
		||||
/lib
 | 
			
		||||
/out
 | 
			
		||||
 
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_4_5</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_4_5</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>craftbukkit</artifactId>
 | 
			
		||||
      <version>1.4.5-R1.0</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,168 +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 com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_5.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_4_5.BlockEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_4_5.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_4_5.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_4_5.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.TileEntityEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
			
		||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
			
		||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, int x, int y, int z) {
 | 
			
		||||
        for (Object localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
			
		||||
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
 | 
			
		||||
        // Silent ender chest is API-only
 | 
			
		||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            p.openInventory(p.getEnderChest());
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tile instanceof TileEntityEnderChest) {
 | 
			
		||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
			
		||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
			
		||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
			
		||||
            player.openContainer(enderChest);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof IInventory)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
			
		||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) tile);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } 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.netServerHandler.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) tile).getName(), ((IInventory) tile).getSize()));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +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 com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_5.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            return (SpecialPlayerInventory) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            return (SpecialEnderChest) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,62 +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 com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_5.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_4_5.ItemInWorldManager;
 | 
			
		||||
import net.minecraft.server.v1_4_5.MinecraftServer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.CraftServer;
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure the player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,46 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_4_5;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_5.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_4_5.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_5.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_4_5.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.f();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,128 +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.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.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_5.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.InventorySubcontainer;
 | 
			
		||||
import net.minecraft.server.v1_4_5.ItemStack;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftHumanEntity;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
 | 
			
		||||
    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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                owner = (CraftPlayer) player;
 | 
			
		||||
                InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onOpen(CraftHumanEntity who) {
 | 
			
		||||
        transaction.add(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        transaction.remove(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return transaction;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return this.owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setMaxStackSize(int size) {
 | 
			
		||||
        maxStack = size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return maxStack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,237 +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 com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_5.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_4_5.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        this.items = player.inventory.items;
 | 
			
		||||
        this.armor = player.inventory.armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            this.player.inventory.items = this.items;
 | 
			
		||||
            this.player.inventory.armor = this.armor;
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        ItemStack[] contents = new ItemStack[getSize()];
 | 
			
		||||
        System.arraycopy(items, 0, contents, 0, items.length);
 | 
			
		||||
        System.arraycopy(armor, 0, contents, items.length, armor.length);
 | 
			
		||||
        return contents;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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) {
 | 
			
		||||
            player.drop(itemstack);
 | 
			
		||||
            itemstack = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        is[i] = itemstack;
 | 
			
		||||
 | 
			
		||||
        player.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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_4_6</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_4_6</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>craftbukkit</artifactId>
 | 
			
		||||
      <version>1.4.6-R0.3</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,168 +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 com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_6.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_4_6.BlockEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_4_6.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_4_6.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_4_6.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.TileEntityEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
			
		||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
			
		||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, int x, int y, int z) {
 | 
			
		||||
        for (Object localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
			
		||||
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
 | 
			
		||||
        // Silent ender chest is API-only
 | 
			
		||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            p.openInventory(p.getEnderChest());
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tile instanceof TileEntityEnderChest) {
 | 
			
		||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
			
		||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
			
		||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
			
		||||
            player.openContainer(enderChest);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof IInventory)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
			
		||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) tile);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } 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) tile).getName(), ((IInventory) tile).getSize()));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +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 com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_6.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            return (SpecialPlayerInventory) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            return (SpecialEnderChest) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,62 +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 com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_6.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_4_6.MinecraftServer;
 | 
			
		||||
import net.minecraft.server.v1_4_6.PlayerInteractManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.CraftServer;
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure the player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,46 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_4_6;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_6.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_4_6.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_6.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_4_6.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.f();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,128 +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.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.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_6.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.InventorySubcontainer;
 | 
			
		||||
import net.minecraft.server.v1_4_6.ItemStack;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftHumanEntity;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
 | 
			
		||||
    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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                owner = (CraftPlayer) player;
 | 
			
		||||
                InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onOpen(CraftHumanEntity who) {
 | 
			
		||||
        transaction.add(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        transaction.remove(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return transaction;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return this.owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setMaxStackSize(int size) {
 | 
			
		||||
        maxStack = size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return maxStack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,229 +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 com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_6.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_4_6.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        this.items = player.inventory.items;
 | 
			
		||||
        this.armor = player.inventory.armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            this.player.inventory.items = this.items;
 | 
			
		||||
            this.player.inventory.armor = this.armor;
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        ItemStack[] contents = new ItemStack[getSize()];
 | 
			
		||||
        System.arraycopy(items, 0, contents, 0, items.length);
 | 
			
		||||
        System.arraycopy(armor, 0, contents, items.length, armor.length);
 | 
			
		||||
        return contents;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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) {
 | 
			
		||||
            player.drop(itemstack);
 | 
			
		||||
            itemstack = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        is[i] = itemstack;
 | 
			
		||||
 | 
			
		||||
        player.defaultContainer.b();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        if (player.getName().length() > 16) {
 | 
			
		||||
            return player.getName().substring(0, 16);
 | 
			
		||||
        }
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								README
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								README
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
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/>.
 | 
			
		||||
							
								
								
									
										139
									
								
								README.MD
									
									
									
									
									
								
							
							
						
						
									
										139
									
								
								README.MD
									
									
									
									
									
								
							@@ -1,139 +0,0 @@
 | 
			
		||||
## About
 | 
			
		||||
OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) which allows users to open and edit anyone's inventory or ender chest - online or not!
 | 
			
		||||
 | 
			
		||||
## Features
 | 
			
		||||
- **OpenInv**: Open anyone's inventory, even if they're offline.
 | 
			
		||||
  - Read-only mode! No edits allowed! Don't grant the permission `OpenInv.editinv`
 | 
			
		||||
  - Cross-world support! Don't grant `OpenInv.crossworld`
 | 
			
		||||
  - No self-opening! Don't grant `OpenInv.openself`
 | 
			
		||||
  - Drop items as the player! Place items in the unused slots to the right of the armor to drop them
 | 
			
		||||
- **OpenEnder**: Open anyone's inventory, even if they're offline.
 | 
			
		||||
  - Read-only mode! No edits allowed! Don't grant `OpenInv.editender`
 | 
			
		||||
  - Cross-world support! Don't grant `OpenInv.crossworld`
 | 
			
		||||
  - No self-opening! Don't grant `OpenInv.openself`
 | 
			
		||||
- **SilentChest**: Open containers without displaying an animation or making sound.
 | 
			
		||||
- **AnyChest**: Open containers, even if blocked by ocelots or blocks.
 | 
			
		||||
 | 
			
		||||
## Commands
 | 
			
		||||
<table width=100%>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <th width=175px>Command</th>
 | 
			
		||||
    <th>Aliases</th>
 | 
			
		||||
    <th>Description</th>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>/openinv [player]</td>
 | 
			
		||||
    <td>oi, inv, open</td>
 | 
			
		||||
    <td>Open a player's inventory. If unspecified, will select last player opened or own if none opened previously.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>/openender [player]</td>
 | 
			
		||||
    <td>oe</td>
 | 
			
		||||
    <td>Open a player's ender chest. If unspecified, will select last player opened or own if none opened previously.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>/searchinv <item> [minAmount]</td>
 | 
			
		||||
    <td>si</td>
 | 
			
		||||
    <td>Lists all online players that have a certain item in their inventory.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>/searchender <item> [minAmount]</td>
 | 
			
		||||
    <td>se</td>
 | 
			
		||||
    <td>Lists all online players that have a certain item in their ender chest.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>/anychest [check]</td>
 | 
			
		||||
    <td>ac</td>
 | 
			
		||||
    <td>Check or toggle the AnyChest function, allowing opening blocked containers.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>/silentchest [check]</td>
 | 
			
		||||
    <td>sc</td>
 | 
			
		||||
    <td>Check or toggle the SilentChest function, allowing opening containers silently.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
## Permissions
 | 
			
		||||
<table>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <th>Node</th>
 | 
			
		||||
    <th>Description</th>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.*</td>
 | 
			
		||||
    <td>Gives permission to use all of OpenInv.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.openinv</td>
 | 
			
		||||
    <td>Required to use /openinv.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.openself</td>
 | 
			
		||||
    <td>Required to open own inventory.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.editinv</td>
 | 
			
		||||
    <td>Required to make changes to open inventories.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.openender</td>
 | 
			
		||||
    <td>Required to use /openender.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.editinv</td>
 | 
			
		||||
    <td>Required to make changes to open ender chests.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.openenderall</td>
 | 
			
		||||
    <td>Allows users to open others' ender chests. Without it, users can only open their own.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.exempt</td>
 | 
			
		||||
    <td>Prevents the player's inventory being opened by others.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.override</td>
 | 
			
		||||
    <td>Allows bypassing of the exempt permission.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.crossworld</td>
 | 
			
		||||
    <td>Allows cross-world usage of /openinv and /openender.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.search</td>
 | 
			
		||||
    <td>Required to use /searchinv and /searchender.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.anychest</td>
 | 
			
		||||
    <td>Required to use /anychest.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
  <tr>
 | 
			
		||||
    <td>OpenInv.silent</td>
 | 
			
		||||
    <td>Required to use /silentchest.</td>
 | 
			
		||||
  </tr>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
## For Developers
 | 
			
		||||
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.  
 | 
			
		||||
Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
 | 
			
		||||
 | 
			
		||||
Compiling OpenInv for a specific version is very easy - just compile the correct module.
 | 
			
		||||
 | 
			
		||||
Compiling for a set of versions is slightly more complex. You'll need to use a profile for the versions you want to compile. Provided profiles are latest, modern (versions 1.8+), and all. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
 | 
			
		||||
 | 
			
		||||
## License
 | 
			
		||||
```
 | 
			
		||||
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/>.
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										208
									
								
								assembly/pom.xml
									
									
									
									
									
								
							
							
						
						
									
										208
									
								
								assembly/pom.xml
									
									
									
									
									
								
							@@ -1,208 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvassembly</artifactId>
 | 
			
		||||
  <name>OpenInvAssembly</name>
 | 
			
		||||
 | 
			
		||||
  <profiles>
 | 
			
		||||
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>latest</id>
 | 
			
		||||
      <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
      </dependencies>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>modern</id>
 | 
			
		||||
      <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_10_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
      </dependencies>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>all</id>
 | 
			
		||||
      <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_4_5</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_4_6</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_4_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_5_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_5_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_6_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_6_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_6_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R4</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_10_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
      </dependencies>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
  </profiles>
 | 
			
		||||
 | 
			
		||||
  <build>
 | 
			
		||||
    <directory>../target</directory>
 | 
			
		||||
    <finalName>OpenInv</finalName>
 | 
			
		||||
 | 
			
		||||
    <plugins>
 | 
			
		||||
      <plugin>
 | 
			
		||||
        <groupId>org.apache.maven.plugins</groupId>
 | 
			
		||||
        <artifactId>maven-shade-plugin</artifactId>
 | 
			
		||||
        <version>2.4.3</version>
 | 
			
		||||
        <configuration>
 | 
			
		||||
          <!--
 | 
			
		||||
            ~ This keeps the final file clean, but may cause issues for people not familiar with the setup.
 | 
			
		||||
            ~ If you're having trouble with the final product missing files, remove or tweak this configuration.
 | 
			
		||||
           -->
 | 
			
		||||
          <minimizeJar>true</minimizeJar>
 | 
			
		||||
          <filters>
 | 
			
		||||
            <filter>
 | 
			
		||||
              <artifact>com.lishid:*</artifact>
 | 
			
		||||
              <includes>
 | 
			
		||||
                <include>com/lishid/openinv/**/*</include>
 | 
			
		||||
                <include>plugin.yml</include>
 | 
			
		||||
              </includes>
 | 
			
		||||
            </filter>
 | 
			
		||||
          </filters>
 | 
			
		||||
        </configuration>
 | 
			
		||||
        <executions>
 | 
			
		||||
          <execution>
 | 
			
		||||
            <phase>package</phase>
 | 
			
		||||
            <goals>
 | 
			
		||||
              <goal>shade</goal>
 | 
			
		||||
            </goals>
 | 
			
		||||
          </execution>
 | 
			
		||||
        </executions>
 | 
			
		||||
      </plugin>
 | 
			
		||||
    </plugins>
 | 
			
		||||
  </build>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,23 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvinternal</artifactId>
 | 
			
		||||
  <name>OpenInvInternal</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>bukkit</artifactId>
 | 
			
		||||
      <version>1.4.5-R1.0</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,37 +0,0 @@
 | 
			
		||||
package com.lishid.openinv.internal;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
public interface IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if the given block is a container which can be unblocked or silenced.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param block the BlockState
 | 
			
		||||
     * @return true if the Block is a supported container
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isAnySilentContainer(Block block);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if the container at the given coordinates is blocked.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player opening the container
 | 
			
		||||
     * @param block the Block
 | 
			
		||||
     * @return true if the container is blocked
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player player, Block block);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Opens the container at the given coordinates for the Player. If you do not want blocked
 | 
			
		||||
     * containers to open, be sure to check {@link #isAnyContainerNeeded(Player, Block)}
 | 
			
		||||
     * first.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player
 | 
			
		||||
     * @param silentchest whether the container's noise is to be silenced
 | 
			
		||||
     * @param block the Block
 | 
			
		||||
     * @return true if the container can be opened
 | 
			
		||||
     */
 | 
			
		||||
    public boolean activateContainer(Player player, boolean silentchest, Block block);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,57 +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.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
public interface IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check if an Inventory is an ISpecialPlayerInventory implementation.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param inventory the Inventory
 | 
			
		||||
     * @return true if the Inventory is backed by an ISpecialPlayerInventory
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets an ISpecialPlayerInventory from an Inventory or null if the Inventory is not backed by
 | 
			
		||||
     * an ISpecialPlayerInventory.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param inventory the Inventory
 | 
			
		||||
     * @return the ISpecialPlayerInventory or null
 | 
			
		||||
     */
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check if an Inventory is an ISpecialEnderChest implementation.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param inventory the Inventory
 | 
			
		||||
     * @return true if the Inventory is backed by an ISpecialEnderChest
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets an ISpecialEnderChest from an Inventory or null if the Inventory is not backed by an
 | 
			
		||||
     * ISpecialEnderChest.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param inventory the Inventory
 | 
			
		||||
     * @return the ISpecialEnderChest or null
 | 
			
		||||
     */
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,50 +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 {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the Inventory associated with this ISpecialEnderChest.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the Inventory
 | 
			
		||||
     */
 | 
			
		||||
    public Inventory getBukkitInventory();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the Player associated with this ISpecialEnderChest online.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player coming online
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerOnline(Player player);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the Player associated with this ISpecialEnderChest offline.
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerOffline();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets whether or not this ISpecialEnderChest is in use.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true if the ISpecialEnderChest is in use
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isInUse();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,50 +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 {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the Inventory associated with this ISpecialPlayerInventory.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the Inventory
 | 
			
		||||
     */
 | 
			
		||||
    public Inventory getBukkitInventory();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the Player associated with this ISpecialPlayerInventory online.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player coming online
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerOnline(Player player);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the Player associated with this ISpecialPlayerInventory offline.
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerOffline();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets whether or not this ISpecialPlayerInventory is in use.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true if the ISpecialPlayerInventory is in use
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isInUse();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,180 +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 java.lang.reflect.Constructor;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.plugin.Plugin;
 | 
			
		||||
 | 
			
		||||
public class InternalAccessor {
 | 
			
		||||
 | 
			
		||||
    private final Plugin plugin;
 | 
			
		||||
 | 
			
		||||
    private final String version;
 | 
			
		||||
    private boolean supported = false;
 | 
			
		||||
 | 
			
		||||
    public InternalAccessor(Plugin plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
 | 
			
		||||
        String packageName = plugin.getServer().getClass().getPackage().getName();
 | 
			
		||||
        version = packageName.substring(packageName.lastIndexOf('.') + 1);
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            Class.forName("com.lishid.openinv.internal." + version + ".PlayerDataManager");
 | 
			
		||||
            supported = true;
 | 
			
		||||
        } catch (Exception e) {}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the server implementation version. If not initialized, returns the string "null"
 | 
			
		||||
     * instead.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the version, or "null"
 | 
			
		||||
     */
 | 
			
		||||
    public String getVersion() {
 | 
			
		||||
        return this.version != null ? this.version : "null";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if the server implementation is supported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true if initialized for a supported server version
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isSupported() {
 | 
			
		||||
        return this.supported;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates an instance of the IPlayerDataManager implementation for the current server version,
 | 
			
		||||
     * or null if unsupported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the IPlayerDataManager
 | 
			
		||||
     */
 | 
			
		||||
    public IPlayerDataManager newPlayerDataManager() {
 | 
			
		||||
        return createObject(IPlayerDataManager.class, "PlayerDataManager");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates an instance of the IInventoryAccess implementation for the current server version, or
 | 
			
		||||
     * null if unsupported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the IInventoryAccess
 | 
			
		||||
     */
 | 
			
		||||
    public IInventoryAccess newInventoryAccess() {
 | 
			
		||||
        return createObject(IInventoryAccess.class, "InventoryAccess");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates an instance of the IAnySilentContainer implementation for the current server version,
 | 
			
		||||
     * or null if unsupported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the IAnySilentContainer
 | 
			
		||||
     */
 | 
			
		||||
    public IAnySilentContainer newAnySilentContainer() {
 | 
			
		||||
        return createObject(IAnySilentContainer.class, "AnySilentContainer");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates an instance of the ISpecialPlayerInventory implementation for the given Player, or
 | 
			
		||||
     * null if the current version is unsupported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player
 | 
			
		||||
     * @param online true if the Player is online
 | 
			
		||||
     * @return the ISpecialPlayerInventory created
 | 
			
		||||
     */
 | 
			
		||||
    public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean online) {
 | 
			
		||||
        return createObject(ISpecialPlayerInventory.class, "SpecialPlayerInventory", player, online);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates an instance of the ISpecialEnderChest implementation for the given Player, or
 | 
			
		||||
     * null if the current version is unsupported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player
 | 
			
		||||
     * @param online true if the Player is online
 | 
			
		||||
     * @return the ISpecialEnderChest created
 | 
			
		||||
     */
 | 
			
		||||
    public ISpecialEnderChest newSpecialEnderChest(Player player, boolean online) {
 | 
			
		||||
        return createObject(ISpecialEnderChest.class, "SpecialEnderChest", player, online);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private <T> T createObject(Class<? extends T> assignableClass, String className, Object... params) {
 | 
			
		||||
        try {
 | 
			
		||||
            // Check if internal versioned class exists
 | 
			
		||||
            Class<?> internalClass = Class.forName("com.lishid.openinv.internal." + version + "." + className);
 | 
			
		||||
            if (!assignableClass.isAssignableFrom(internalClass)) {
 | 
			
		||||
                plugin.getLogger().warning("Found class " + internalClass.getName() + " but cannot cast to " + assignableClass.getName());
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Quick return: no parameters, no need to fiddle about finding the correct constructor.
 | 
			
		||||
            if (params.length == 0) {
 | 
			
		||||
                return assignableClass.cast(internalClass.getConstructor().newInstance());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Search constructors for one matching the given parameters
 | 
			
		||||
            nextConstructor: for (Constructor<?> constructor : internalClass.getConstructors()) {
 | 
			
		||||
                Class<?>[] requiredClasses = constructor.getParameterTypes();
 | 
			
		||||
                if (requiredClasses.length != params.length) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                for (int i = 0; i < params.length; ++i) {
 | 
			
		||||
                    if (!requiredClasses[i].isAssignableFrom(params[i].getClass())) {
 | 
			
		||||
                        continue nextConstructor;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                return assignableClass.cast(constructor.newInstance(params));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            StringBuilder message = new StringBuilder("Found class ").append(internalClass.getName())
 | 
			
		||||
                    .append(" but cannot find any matching constructors for [");
 | 
			
		||||
            for (Object object : params) {
 | 
			
		||||
                message.append(object.getClass().getName()).append(", ");
 | 
			
		||||
            }
 | 
			
		||||
            if (params.length > 0) {
 | 
			
		||||
                message.delete(message.length() - 2, message.length());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            plugin.getLogger().warning(message.append(']').toString());
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            plugin.getLogger().warning("OpenInv encountered an error with the CraftBukkit version \"" + version + "\". Please look for an updated version of OpenInv.");
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <T> T grabFieldOfTypeFromObject(Class<T> type, Object object) {
 | 
			
		||||
        // Use reflection to find the iinventory
 | 
			
		||||
        Class<?> clazz = object.getClass();
 | 
			
		||||
        T result = null;
 | 
			
		||||
        for (Field f : clazz.getDeclaredFields()) {
 | 
			
		||||
            f.setAccessible(true);
 | 
			
		||||
            if (type.isAssignableFrom(f.getDeclaringClass())) {
 | 
			
		||||
                try {
 | 
			
		||||
                    result = type.cast(f.get(object));
 | 
			
		||||
                } catch (Exception e) {
 | 
			
		||||
                    e.printStackTrace();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,38 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvplugin</artifactId>
 | 
			
		||||
  <name>OpenInvPlugin</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>bukkit</artifactId>
 | 
			
		||||
      <!-- Really should use 1.4.5-R1.0, but the InventoryDragEvent doesn't exist. TODO separate module? -->
 | 
			
		||||
      <version>1.11-R0.1-SNAPSHOT</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvinternal</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
  <build>
 | 
			
		||||
    <resources>
 | 
			
		||||
      <resource>
 | 
			
		||||
        <directory>src/main/resources</directory>
 | 
			
		||||
        <filtering>true</filtering>
 | 
			
		||||
      </resource>
 | 
			
		||||
    </resources>
 | 
			
		||||
  </build>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,590 +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;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.concurrent.Callable;
 | 
			
		||||
import java.util.concurrent.ExecutionException;
 | 
			
		||||
import java.util.concurrent.Future;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.commands.AnyChestPluginCommand;
 | 
			
		||||
import com.lishid.openinv.commands.OpenEnderPluginCommand;
 | 
			
		||||
import com.lishid.openinv.commands.OpenInvPluginCommand;
 | 
			
		||||
import com.lishid.openinv.commands.SearchInvPluginCommand;
 | 
			
		||||
import com.lishid.openinv.commands.SilentChestPluginCommand;
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
import com.lishid.openinv.util.Cache;
 | 
			
		||||
import com.lishid.openinv.util.Function;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.command.PluginCommand;
 | 
			
		||||
import org.bukkit.configuration.file.FileConfiguration;
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
import org.bukkit.plugin.PluginManager;
 | 
			
		||||
import org.bukkit.plugin.java.JavaPlugin;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Open other player's inventory
 | 
			
		||||
 * 
 | 
			
		||||
 * @author lishid
 | 
			
		||||
 */
 | 
			
		||||
public class OpenInv extends JavaPlugin {
 | 
			
		||||
 | 
			
		||||
    private final Map<String, ISpecialPlayerInventory> inventories = new HashMap<String, ISpecialPlayerInventory>();
 | 
			
		||||
    private final Map<String, ISpecialEnderChest> enderChests = new HashMap<String, ISpecialEnderChest>();
 | 
			
		||||
    private final Cache<String, Player> playerCache = new Cache<String, Player>(300000L,
 | 
			
		||||
            new Function<Player>() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public boolean run(Player value) {
 | 
			
		||||
                    String key = playerLoader.getPlayerDataID(value);
 | 
			
		||||
                    return inventories.containsKey(key) && inventories.get(key).isInUse()
 | 
			
		||||
                            || enderChests.containsKey(key) && enderChests.get(key).isInUse();
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            new Function<Player>() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public boolean run(Player value) {
 | 
			
		||||
                    String key = playerLoader.getPlayerDataID(value);
 | 
			
		||||
 | 
			
		||||
                    // Check if inventory is stored, and if it is, remove it and eject all viewers
 | 
			
		||||
                    if (inventories.containsKey(key)) {
 | 
			
		||||
                        Inventory inv = inventories.remove(key).getBukkitInventory();
 | 
			
		||||
                        for (HumanEntity entity : inv.getViewers()) {
 | 
			
		||||
                            entity.closeInventory();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // Check if ender chest is stored, and if it is, remove it and eject all viewers
 | 
			
		||||
                    if (enderChests.containsKey(key)) {
 | 
			
		||||
                        Inventory inv = enderChests.remove(key).getBukkitInventory();
 | 
			
		||||
                        for (HumanEntity entity : inv.getViewers()) {
 | 
			
		||||
                            entity.closeInventory();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (!OpenInv.this.disableSaving() && !value.isOnline()) {
 | 
			
		||||
                        value.saveData();
 | 
			
		||||
                    }
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
    private InternalAccessor accessor;
 | 
			
		||||
    private IPlayerDataManager playerLoader;
 | 
			
		||||
    private IInventoryAccess inventoryAccess;
 | 
			
		||||
    private IAnySilentContainer anySilentContainer;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onEnable() {
 | 
			
		||||
        // Get plugin manager
 | 
			
		||||
        PluginManager pm = getServer().getPluginManager();
 | 
			
		||||
 | 
			
		||||
        accessor = new InternalAccessor(this);
 | 
			
		||||
        // Version check
 | 
			
		||||
        if (!accessor.isSupported()) {
 | 
			
		||||
            getLogger().info("Your version of CraftBukkit (" + accessor.getVersion() + ") is not supported.");
 | 
			
		||||
            getLogger().info("Please look for an updated version of OpenInv.");
 | 
			
		||||
            pm.disablePlugin(this);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        playerLoader = accessor.newPlayerDataManager();
 | 
			
		||||
        inventoryAccess = accessor.newInventoryAccess();
 | 
			
		||||
        anySilentContainer = accessor.newAnySilentContainer();
 | 
			
		||||
 | 
			
		||||
        FileConfiguration config = getConfig();
 | 
			
		||||
        boolean dirtyConfig = false;
 | 
			
		||||
        if (!config.isBoolean("NotifySilentChest")) {
 | 
			
		||||
            config.set("NotifySilentChest", true);
 | 
			
		||||
            dirtyConfig = true;
 | 
			
		||||
        }
 | 
			
		||||
        if (!config.isBoolean("NotifyAnyChest")) {
 | 
			
		||||
            config.set("NotifyAnyChest", true);
 | 
			
		||||
            dirtyConfig = true;
 | 
			
		||||
        }
 | 
			
		||||
        if (!config.isBoolean("DisableSaving")) {
 | 
			
		||||
            config.set("DisableSaving", false);
 | 
			
		||||
            dirtyConfig = true;
 | 
			
		||||
        }
 | 
			
		||||
        config.addDefault("NotifySilentChest", true);
 | 
			
		||||
        config.addDefault("NotifyAnyChest", true);
 | 
			
		||||
        config.addDefault("DisableSaving", false);
 | 
			
		||||
        config.options().copyDefaults(true);
 | 
			
		||||
        if (dirtyConfig) {
 | 
			
		||||
            saveConfig();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        pm.registerEvents(new OpenInvPlayerListener(this), this);
 | 
			
		||||
        pm.registerEvents(new OpenInvInventoryListener(this), this);
 | 
			
		||||
 | 
			
		||||
        getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
 | 
			
		||||
        SearchInvPluginCommand searchInv = new SearchInvPluginCommand();
 | 
			
		||||
        getCommand("searchinv").setExecutor(searchInv);
 | 
			
		||||
        getCommand("searchender").setExecutor(searchInv);
 | 
			
		||||
        getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
 | 
			
		||||
        getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
 | 
			
		||||
        getCommand("openender").setExecutor(new OpenEnderPluginCommand(this));
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onDisable() {
 | 
			
		||||
 | 
			
		||||
        if (this.disableSaving()) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.playerCache.invalidateAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if the server version is supported by OpenInv.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true if the server version is supported
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isSupportedVersion() {
 | 
			
		||||
        return accessor.isSupported();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the active IInventoryAccess implementation. May return null if the server version is
 | 
			
		||||
     * unsupported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the IInventoryAccess
 | 
			
		||||
     */
 | 
			
		||||
    public IInventoryAccess getInventoryAccess() {
 | 
			
		||||
        return this.inventoryAccess;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the active ISilentContainer implementation. May return null if the server version is
 | 
			
		||||
     * unsupported.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return the ISilentContainer
 | 
			
		||||
     */
 | 
			
		||||
    public IAnySilentContainer getAnySilentContainer() {
 | 
			
		||||
        return this.anySilentContainer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets an ISpecialPlayerInventory for the given Player.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player
 | 
			
		||||
     * @param online true if the Player is currently online
 | 
			
		||||
     * @return the ISpecialPlayerInventory
 | 
			
		||||
     */
 | 
			
		||||
    public ISpecialPlayerInventory getInventory(Player player, boolean online) {
 | 
			
		||||
        String id = playerLoader.getPlayerDataID(player);
 | 
			
		||||
        if (inventories.containsKey(id)) {
 | 
			
		||||
            return inventories.get(id);
 | 
			
		||||
        }
 | 
			
		||||
        ISpecialPlayerInventory inv = accessor.newSpecialPlayerInventory(player, online);
 | 
			
		||||
        inventories.put(id, inv);
 | 
			
		||||
        playerCache.put(id, player);
 | 
			
		||||
        return inv;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets an ISpecialEnderChest for the given Player.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player
 | 
			
		||||
     * @param online true if the Player is currently online
 | 
			
		||||
     * @return the ISpecialEnderChest
 | 
			
		||||
     */
 | 
			
		||||
    public ISpecialEnderChest getEnderChest(Player player, boolean online) {
 | 
			
		||||
        String id = playerLoader.getPlayerDataID(player);
 | 
			
		||||
        if (enderChests.containsKey(id)) {
 | 
			
		||||
            return enderChests.get(id);
 | 
			
		||||
        }
 | 
			
		||||
        ISpecialEnderChest inv = accessor.newSpecialEnderChest(player, online);
 | 
			
		||||
        enderChests.put(id, inv);
 | 
			
		||||
        playerCache.put(id, player);
 | 
			
		||||
        return inv;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Forcibly unload a cached Player's data.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the OfflinePlayer to unload
 | 
			
		||||
     */
 | 
			
		||||
    public void unload(OfflinePlayer player) {
 | 
			
		||||
        this.playerCache.invalidate(this.playerLoader.getPlayerDataID(player));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check the configuration value for whether or not OpenInv saves player data when unloading
 | 
			
		||||
     * players. This is exclusively for users who do not allow editing of inventories, only viewing,
 | 
			
		||||
     * and wish to prevent any possibility of bugs such as lishid#40. If true, OpenInv will not ever
 | 
			
		||||
     * save any edits made to players.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return false unless configured otherwise
 | 
			
		||||
     */
 | 
			
		||||
    public boolean disableSaving() {
 | 
			
		||||
        return getConfig().getBoolean("DisableSaving", false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check the configuration value for whether or not OpenInv displays a notification to the user
 | 
			
		||||
     * when a container is activated with SilentChest.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true unless configured otherwise
 | 
			
		||||
     */
 | 
			
		||||
    public boolean notifySilentChest() {
 | 
			
		||||
        return getConfig().getBoolean("NotifySilentChest", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check the configuration value for whether or not OpenInv displays a notification to the user
 | 
			
		||||
     * when a container is activated with AnyChest.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true unless configured otherwise
 | 
			
		||||
     */
 | 
			
		||||
    public boolean notifyAnyChest() {
 | 
			
		||||
        return getConfig().getBoolean("NotifyAnyChest", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets a player's SilentChest setting.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the OfflinePlayer
 | 
			
		||||
     * @return true if SilentChest is enabled
 | 
			
		||||
     */
 | 
			
		||||
    public boolean getPlayerSilentChestStatus(OfflinePlayer player) {
 | 
			
		||||
        return getConfig().getBoolean("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets a player's SilentChest setting.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the OfflinePlayer
 | 
			
		||||
     * @param status the status
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerSilentChestStatus(OfflinePlayer player, boolean status) {
 | 
			
		||||
        getConfig().set("SilentChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
 | 
			
		||||
        saveConfig();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the provided player's AnyChest setting.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the OfflinePlayer
 | 
			
		||||
     * @return true if AnyChest is enabled
 | 
			
		||||
     */
 | 
			
		||||
    public boolean getPlayerAnyChestStatus(OfflinePlayer player) {
 | 
			
		||||
        return getConfig().getBoolean("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets a player's AnyChest setting.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the OfflinePlayer
 | 
			
		||||
     * @param status the status
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerAnyChestStatus(OfflinePlayer player, boolean status) {
 | 
			
		||||
        getConfig().set("AnyChest." + playerLoader.getPlayerDataID(player) + ".toggle", status);
 | 
			
		||||
        saveConfig();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an OfflinePlayer by name.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Note: This method is potentially very heavily blocking. It should not ever be called on the
 | 
			
		||||
     * main thread, and if it is, a stack trace will be displayed alerting server owners to the
 | 
			
		||||
     * call.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param name the name of the Player
 | 
			
		||||
     * @return the OfflinePlayer with the closest matching name or null if no players have ever logged in
 | 
			
		||||
     */
 | 
			
		||||
    public OfflinePlayer matchPlayer(String name) {
 | 
			
		||||
 | 
			
		||||
        // Warn if called on the main thread - if we resort to searching offline players, this may take several seconds.
 | 
			
		||||
        if (getServer().isPrimaryThread()) {
 | 
			
		||||
            getLogger().warning("Call to OpenInv#matchPlayer made on the main thread!");
 | 
			
		||||
            getLogger().warning("This can cause the server to hang, potentially severely.");
 | 
			
		||||
            getLogger().warning("Trace:");
 | 
			
		||||
            for (StackTraceElement element : new Throwable().fillInStackTrace().getStackTrace()) {
 | 
			
		||||
                getLogger().warning(element.toString());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Ensure name is valid if server is in online mode to avoid unnecessary searching
 | 
			
		||||
        if (getServer().getOnlineMode() && !name.matches("[a-zA-Z0-9_]{3,16}")) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        OfflinePlayer player = getServer().getPlayerExact(name);
 | 
			
		||||
 | 
			
		||||
        if (player != null) {
 | 
			
		||||
            return player;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        player = getServer().getOfflinePlayer(name);
 | 
			
		||||
 | 
			
		||||
        /*
 | 
			
		||||
         * Compatibility: Pre-UUID, getOfflinePlayer always returns an OfflinePlayer. Post-UUID,
 | 
			
		||||
         * getOfflinePlayer will return null if no matching player is found. To preserve
 | 
			
		||||
         * compatibility, only return the player if they have played before. Ignoring current online
 | 
			
		||||
         * status is fine, they'd have been found by getPlayerExact otherwise.
 | 
			
		||||
         */
 | 
			
		||||
        if (player != null && player.hasPlayedBefore()) {
 | 
			
		||||
            return player;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        player = getServer().getPlayer(name);
 | 
			
		||||
 | 
			
		||||
        if (player != null) {
 | 
			
		||||
            return player;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int bestMatch = Integer.MAX_VALUE;
 | 
			
		||||
        for (OfflinePlayer offline : getServer().getOfflinePlayers()) {
 | 
			
		||||
            if (offline.getName() == null) {
 | 
			
		||||
                // Loaded by UUID only, name has never been looked up.
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Compatibility: Lang3 is only bundled with 1.8+
 | 
			
		||||
            int currentMatch = org.apache.commons.lang.StringUtils.getLevenshteinDistance(name, offline.getName());
 | 
			
		||||
 | 
			
		||||
            if (currentMatch == 0) {
 | 
			
		||||
                return offline;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (currentMatch < bestMatch) {
 | 
			
		||||
                bestMatch = currentMatch;
 | 
			
		||||
                player = offline;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Only null if no players have played ever, otherwise even the worst match will do.
 | 
			
		||||
        return player;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Load a Player from an OfflinePlayer. May return null under some circumstances.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param offline the OfflinePlayer to load a Player for
 | 
			
		||||
     * @return the Player
 | 
			
		||||
     */
 | 
			
		||||
    public Player loadPlayer(final OfflinePlayer offline) {
 | 
			
		||||
 | 
			
		||||
        if (offline == null) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        String key = this.playerLoader.getPlayerDataID(offline);
 | 
			
		||||
        if (this.playerCache.containsKey(key)) {
 | 
			
		||||
            return this.playerCache.get(key);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Player loaded;
 | 
			
		||||
 | 
			
		||||
        if (offline.isOnline()) {
 | 
			
		||||
            loaded = offline.getPlayer();
 | 
			
		||||
            this.playerCache.put(key, loaded);
 | 
			
		||||
            return loaded;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (Bukkit.isPrimaryThread()) {
 | 
			
		||||
            return this.playerLoader.loadPlayer(offline);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Future<Player> future = Bukkit.getScheduler().callSyncMethod(this,
 | 
			
		||||
                new Callable<Player>() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public Player call() throws Exception {
 | 
			
		||||
                        return playerLoader.loadPlayer(offline);
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
        int ticks = 0;
 | 
			
		||||
        while (!future.isDone() && !future.isCancelled() && ticks < 10) {
 | 
			
		||||
            ++ticks;
 | 
			
		||||
            try {
 | 
			
		||||
                Thread.sleep(50L);
 | 
			
		||||
            } catch (InterruptedException e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!future.isDone() || future.isCancelled()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            loaded = future.get();
 | 
			
		||||
        } catch (InterruptedException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return null;
 | 
			
		||||
        } catch (ExecutionException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (loaded != null) {
 | 
			
		||||
            this.playerCache.put(key, loaded);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return loaded;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method for handling a Player coming online.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerOnline(final Player player) {
 | 
			
		||||
 | 
			
		||||
        String key = this.playerLoader.getPlayerDataID(player);
 | 
			
		||||
 | 
			
		||||
        // Check if the player is cached. If not, neither of their inventories is open.
 | 
			
		||||
        if (!this.playerCache.containsKey(key)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.playerCache.put(key, player);
 | 
			
		||||
 | 
			
		||||
        if (this.inventories.containsKey(key)) {
 | 
			
		||||
            this.inventories.get(key).setPlayerOnline(player);
 | 
			
		||||
            new BukkitRunnable() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run() {
 | 
			
		||||
                    if (player.isOnline()) {
 | 
			
		||||
                        player.updateInventory();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }.runTask(this);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (this.enderChests.containsKey(key)) {
 | 
			
		||||
            this.enderChests.get(key).setPlayerOnline(player);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Method for handling a Player going offline.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player
 | 
			
		||||
     */
 | 
			
		||||
    public void setPlayerOffline(final Player player) {
 | 
			
		||||
 | 
			
		||||
        String key = this.playerLoader.getPlayerDataID(player);
 | 
			
		||||
 | 
			
		||||
        // Check if the player is cached. If not, neither of their inventories is open.
 | 
			
		||||
        if (!this.playerCache.containsKey(key)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (this.inventories.containsKey(key)) {
 | 
			
		||||
            this.inventories.get(key).setPlayerOffline();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (this.enderChests.containsKey(key)) {
 | 
			
		||||
            this.enderChests.get(key).setPlayerOffline();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Evicts all viewers lacking cross-world permissions from a Player's inventory.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player
 | 
			
		||||
     */
 | 
			
		||||
    public void changeWorld(final Player player) {
 | 
			
		||||
 | 
			
		||||
        String key = this.playerLoader.getPlayerDataID(player);
 | 
			
		||||
 | 
			
		||||
        // Check if the player is cached. If not, neither of their inventories is open.
 | 
			
		||||
        if (!this.playerCache.containsKey(key)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (this.inventories.containsKey(key)) {
 | 
			
		||||
            Iterator<HumanEntity> iterator = this.inventories.get(key).getBukkitInventory().getViewers().iterator();
 | 
			
		||||
            while (iterator.hasNext()) {
 | 
			
		||||
                HumanEntity human = iterator.next();
 | 
			
		||||
                // If player has permission or is in the same world, allow continued access
 | 
			
		||||
                // Just in case, also allow null worlds.
 | 
			
		||||
                if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
 | 
			
		||||
                        || human.getWorld().equals(player.getWorld())) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                human.closeInventory();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (this.enderChests.containsKey(key)) {
 | 
			
		||||
            Iterator<HumanEntity> iterator = this.enderChests.get(key).getBukkitInventory().getViewers().iterator();
 | 
			
		||||
            while (iterator.hasNext()) {
 | 
			
		||||
                HumanEntity human = iterator.next();
 | 
			
		||||
                if (Permissions.CROSSWORLD.hasPermission(human) || human.getWorld() == null
 | 
			
		||||
                        || human.getWorld().equals(player.getWorld())) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                human.closeInventory();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Displays all applicable help for OpenInv commands.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player to help
 | 
			
		||||
     */
 | 
			
		||||
    public void showHelp(Player player) {
 | 
			
		||||
        // Get registered commands
 | 
			
		||||
        for (String commandName : this.getDescription().getCommands().keySet()) {
 | 
			
		||||
            PluginCommand command = this.getCommand(commandName);
 | 
			
		||||
 | 
			
		||||
            // Ensure command is successfully registered and player can use it
 | 
			
		||||
            if (command == null  || !command.testPermissionSilent(player)) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Send usage
 | 
			
		||||
            player.sendMessage(command.getUsage().replace("<command>", commandName));
 | 
			
		||||
 | 
			
		||||
            List<String> aliases = command.getAliases();
 | 
			
		||||
            if (aliases.isEmpty()) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Assemble alias list
 | 
			
		||||
            StringBuilder aliasBuilder = new StringBuilder("   (aliases: ");
 | 
			
		||||
            for (String alias : aliases) {
 | 
			
		||||
                aliasBuilder.append(alias).append(", ");
 | 
			
		||||
            }
 | 
			
		||||
            aliasBuilder.delete(aliasBuilder.length() - 2, aliasBuilder.length()).append(')');
 | 
			
		||||
 | 
			
		||||
            // Send all aliases
 | 
			
		||||
            player.sendMessage(aliasBuilder.toString());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,62 +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;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.inventory.InventoryClickEvent;
 | 
			
		||||
import org.bukkit.event.inventory.InventoryDragEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
public class OpenInvInventoryListener implements Listener {
 | 
			
		||||
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
 | 
			
		||||
    public OpenInvInventoryListener(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
 | 
			
		||||
    public void onInventoryClick(InventoryClickEvent event) {
 | 
			
		||||
        if (cancelInteract(event.getWhoClicked(), event.getInventory())) {
 | 
			
		||||
            event.setCancelled(true);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
 | 
			
		||||
    public void onInventoryDrag(InventoryDragEvent event) {
 | 
			
		||||
        if (cancelInteract(event.getWhoClicked(), event.getInventory())) {
 | 
			
		||||
            event.setCancelled(true);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean cancelInteract(HumanEntity entity, Inventory inventory) {
 | 
			
		||||
        return plugin.getInventoryAccess().isSpecialPlayerInventory(inventory)
 | 
			
		||||
                && !Permissions.EDITINV.hasPermission(entity)
 | 
			
		||||
                || plugin.getInventoryAccess().isSpecialEnderChest(inventory)
 | 
			
		||||
                        && !Permissions.EDITENDER.hasPermission(entity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onWorldChange(PlayerChangedWorldEvent event) {
 | 
			
		||||
        plugin.changeWorld(event.getPlayer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,78 +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;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.Event.Result;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.block.Action;
 | 
			
		||||
import org.bukkit.event.player.PlayerInteractEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerJoinEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerQuitEvent;
 | 
			
		||||
 | 
			
		||||
public class OpenInvPlayerListener implements Listener {
 | 
			
		||||
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
 | 
			
		||||
    public OpenInvPlayerListener(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR)
 | 
			
		||||
    public void onPlayerJoin(final PlayerJoinEvent event) {
 | 
			
		||||
        plugin.setPlayerOnline(event.getPlayer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR)
 | 
			
		||||
    public void onPlayerQuit(PlayerQuitEvent event) {
 | 
			
		||||
        plugin.setPlayerOffline(event.getPlayer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
			
		||||
    public void onPlayerInteract(PlayerInteractEvent event) {
 | 
			
		||||
        if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking()
 | 
			
		||||
                || event.useInteractedBlock() == Result.DENY
 | 
			
		||||
                || !plugin.getAnySilentContainer().isAnySilentContainer(event.getClickedBlock())) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Player player = event.getPlayer();
 | 
			
		||||
        boolean anychest = Permissions.ANYCHEST.hasPermission(player) && plugin.getPlayerAnyChestStatus(player);
 | 
			
		||||
        boolean needsAnyChest = plugin.getAnySilentContainer().isAnyContainerNeeded(player, event.getClickedBlock());
 | 
			
		||||
 | 
			
		||||
        if (!anychest && needsAnyChest) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean silentchest = Permissions.SILENT.hasPermission(player) && plugin.getPlayerSilentChestStatus(player);
 | 
			
		||||
 | 
			
		||||
        // If anychest or silentchest is active
 | 
			
		||||
        if ((anychest || silentchest) && plugin.getAnySilentContainer().activateContainer(player, silentchest, event.getClickedBlock())) {
 | 
			
		||||
            if (silentchest && plugin.notifySilentChest() && needsAnyChest && plugin.notifyAnyChest()) {
 | 
			
		||||
                player.sendMessage("You are opening a blocked container silently.");
 | 
			
		||||
            } else if (silentchest && plugin.notifySilentChest()) {
 | 
			
		||||
                player.sendMessage("You are opening a container silently.");
 | 
			
		||||
            } else if (needsAnyChest && plugin.notifyAnyChest()) {
 | 
			
		||||
                player.sendMessage("You are opening a blocked container.");
 | 
			
		||||
            }
 | 
			
		||||
            event.setCancelled(true);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,38 +0,0 @@
 | 
			
		||||
package com.lishid.openinv;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.permissions.Permissible;
 | 
			
		||||
 | 
			
		||||
public enum Permissions {
 | 
			
		||||
 | 
			
		||||
    OPENINV("OpenInv.openinv"),
 | 
			
		||||
    OVERRIDE("OpenInv.override"),
 | 
			
		||||
    EXEMPT("OpenInv.exempt"),
 | 
			
		||||
    CROSSWORLD("OpenInv.crossworld"),
 | 
			
		||||
    SILENT("OpenInv.silent"),
 | 
			
		||||
    ANYCHEST("OpenInv.anychest"),
 | 
			
		||||
    ENDERCHEST("OpenInv.openender"),
 | 
			
		||||
    ENDERCHEST_ALL("OpenInv.openenderall"),
 | 
			
		||||
    SEARCH("OpenInv.search"),
 | 
			
		||||
    EDITINV("OpenInv.editinv"),
 | 
			
		||||
    EDITENDER("OpenInv.editender"),
 | 
			
		||||
    OPENSELF("OpenInv.openself");
 | 
			
		||||
 | 
			
		||||
    private final String permission;
 | 
			
		||||
 | 
			
		||||
    private Permissions(String permission) {
 | 
			
		||||
        this.permission = permission;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasPermission(Permissible permissible) {
 | 
			
		||||
        String[] parts = permission.split("\\.");
 | 
			
		||||
        String perm = "";
 | 
			
		||||
        for (int i = 0; i < parts.length; i++) {
 | 
			
		||||
            if (permissible.hasPermission(perm + "*")) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            perm += parts[i] + ".";
 | 
			
		||||
        }
 | 
			
		||||
        return permissible.hasPermission(permission);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,54 +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.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
 | 
			
		||||
public class AnyChestPluginCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
 | 
			
		||||
    public AnyChestPluginCommand(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (!(sender instanceof Player)) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
        if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
 | 
			
		||||
            sender.sendMessage("AnyChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        plugin.setPlayerAnyChestStatus(player, !plugin.getPlayerAnyChestStatus(player));
 | 
			
		||||
        sender.sendMessage("AnyChest is now " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,141 +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.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
 | 
			
		||||
public class OpenEnderPluginCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
    private final HashMap<Player, String> openEnderHistory = new HashMap<Player, String>();
 | 
			
		||||
 | 
			
		||||
    public OpenEnderPluginCommand(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (!(sender instanceof Player)) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
 | 
			
		||||
            plugin.showHelp((Player) sender);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
        // History management
 | 
			
		||||
        String history = openEnderHistory.get(player);
 | 
			
		||||
 | 
			
		||||
        if (history == null || history == "") {
 | 
			
		||||
            history = player.getName();
 | 
			
		||||
            openEnderHistory.put(player, history);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final String name;
 | 
			
		||||
 | 
			
		||||
        // Read from history if target is not named
 | 
			
		||||
        if (args.length < 1) {
 | 
			
		||||
            name = history;
 | 
			
		||||
        } else {
 | 
			
		||||
            name = args[0];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        new BukkitRunnable() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void run() {
 | 
			
		||||
                final OfflinePlayer offlinePlayer = plugin.matchPlayer(name);
 | 
			
		||||
 | 
			
		||||
                if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
 | 
			
		||||
                    player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                new BukkitRunnable() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void run() {
 | 
			
		||||
                        if (!player.isOnline()) {
 | 
			
		||||
                            return;
 | 
			
		||||
                        }
 | 
			
		||||
                        openInventory(player, offlinePlayer);
 | 
			
		||||
                    }
 | 
			
		||||
                }.runTask(plugin);
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }.runTaskAsynchronously(plugin);
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void openInventory(Player player, OfflinePlayer target) {
 | 
			
		||||
 | 
			
		||||
        Player onlineTarget;
 | 
			
		||||
        boolean online = target.isOnline();
 | 
			
		||||
 | 
			
		||||
        if (!online) {
 | 
			
		||||
            // Try loading the player's data
 | 
			
		||||
            onlineTarget = plugin.loadPlayer(target);
 | 
			
		||||
 | 
			
		||||
            if (onlineTarget == null) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            onlineTarget = target.getPlayer();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!onlineTarget.equals(player)) {
 | 
			
		||||
            if (!Permissions.ENDERCHEST_ALL.hasPermission(player)) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + "You do not have permission to access other players' enderchests.");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if (!Permissions.CROSSWORLD.hasPermission(player) && !player.getWorld().equals(onlineTarget.getWorld())) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if (!Permissions.OVERRIDE.hasPermission(player) && Permissions.EXEMPT.hasPermission(onlineTarget)) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Record the target
 | 
			
		||||
        openEnderHistory.put(player, onlineTarget.getName());
 | 
			
		||||
 | 
			
		||||
        // Create the inventory
 | 
			
		||||
        ISpecialEnderChest chest = plugin.getEnderChest(onlineTarget, online);
 | 
			
		||||
 | 
			
		||||
        // Open the inventory
 | 
			
		||||
        player.openInventory(chest.getBukkitInventory());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,148 +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.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
 | 
			
		||||
public class OpenInvPluginCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
    private final HashMap<Player, String> openInvHistory = new HashMap<Player, String>();
 | 
			
		||||
 | 
			
		||||
    public OpenInvPluginCommand(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (!(sender instanceof Player)) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
 | 
			
		||||
            plugin.showHelp((Player) sender);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
        // History management
 | 
			
		||||
        String history = openInvHistory.get(player);
 | 
			
		||||
 | 
			
		||||
        if (history == null || history == "") {
 | 
			
		||||
            history = player.getName();
 | 
			
		||||
            openInvHistory.put(player, history);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final String name;
 | 
			
		||||
 | 
			
		||||
        // Read from history if target is not named
 | 
			
		||||
        if (args.length < 1) {
 | 
			
		||||
            name = history;
 | 
			
		||||
        } else {
 | 
			
		||||
            name = args[0];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        new BukkitRunnable() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void run() {
 | 
			
		||||
                final OfflinePlayer offlinePlayer = plugin.matchPlayer(name);
 | 
			
		||||
 | 
			
		||||
                if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
 | 
			
		||||
                    player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                new BukkitRunnable() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void run() {
 | 
			
		||||
                        if (!player.isOnline()) {
 | 
			
		||||
                            return;
 | 
			
		||||
                        }
 | 
			
		||||
                        openInventory(player, offlinePlayer);
 | 
			
		||||
                    }
 | 
			
		||||
                }.runTask(plugin);
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }.runTaskAsynchronously(plugin);
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void openInventory(Player player, OfflinePlayer target) {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        Player onlineTarget;
 | 
			
		||||
        boolean online = target.isOnline();
 | 
			
		||||
 | 
			
		||||
        if (!online) {
 | 
			
		||||
            // Try loading the player's data
 | 
			
		||||
            onlineTarget = plugin.loadPlayer(target);
 | 
			
		||||
 | 
			
		||||
            if (onlineTarget == null) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            onlineTarget = target.getPlayer();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Permissions checks
 | 
			
		||||
        if (onlineTarget.equals(player)) {
 | 
			
		||||
            // Self-open check
 | 
			
		||||
            if (!Permissions.OPENSELF.hasPermission(player)) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            // Protected check
 | 
			
		||||
            if (!Permissions.OVERRIDE.hasPermission(player) && Permissions.EXEMPT.hasPermission(onlineTarget)) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + "'s inventory is protected!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Crossworld check
 | 
			
		||||
            if ((!Permissions.CROSSWORLD.hasPermission(player) && !Permissions.OVERRIDE.hasPermission(player)) && onlineTarget.getWorld() != player.getWorld()) {
 | 
			
		||||
                player.sendMessage(ChatColor.RED + onlineTarget.getDisplayName() + " is not in your world!");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Record the target
 | 
			
		||||
        openInvHistory.put(player, onlineTarget.getName());
 | 
			
		||||
 | 
			
		||||
        // Create the inventory
 | 
			
		||||
        ISpecialPlayerInventory inv = plugin.getInventory(onlineTarget, online);
 | 
			
		||||
 | 
			
		||||
        // Open the inventory
 | 
			
		||||
        player.openInventory(inv.getBukkitInventory());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,75 +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.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
public class SearchInvPluginCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
 | 
			
		||||
        Material material = null;
 | 
			
		||||
        int count = 1;
 | 
			
		||||
 | 
			
		||||
        if (args.length >= 1) {
 | 
			
		||||
            String[] gData = null;
 | 
			
		||||
            gData = args[0].split(":");
 | 
			
		||||
            material = Material.matchMaterial(gData[0]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (args.length >= 2) {
 | 
			
		||||
            try {
 | 
			
		||||
                count = Integer.parseInt(args[1]);
 | 
			
		||||
            } catch (NumberFormatException ex) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (material == null) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Unknown item");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        StringBuilder players = new StringBuilder();
 | 
			
		||||
        for (Player player : Bukkit.getServer().getOnlinePlayers()) {
 | 
			
		||||
            Inventory inventory = command.getName().equals("searchinv") ? player.getInventory() : player.getEnderChest();
 | 
			
		||||
            if (inventory.contains(material, count)) {
 | 
			
		||||
                players.append(player.getName()).append(", ");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Matches found, delete trailing comma and space
 | 
			
		||||
        if (players.length() > 0) {
 | 
			
		||||
            players.delete(players.length() - 2, players.length());
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage("No players found with " + material.toString());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        sender.sendMessage("Players with the item " + material.toString() + ":  " + players.toString());
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,53 +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.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
 | 
			
		||||
public class SilentChestPluginCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
 | 
			
		||||
    public SilentChestPluginCommand(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (!(sender instanceof Player)) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You can't use this from the console.");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
        if (args.length > 0 && args[0].equalsIgnoreCase("check")) {
 | 
			
		||||
            sender.sendMessage("SilentChest is " + (plugin.getPlayerAnyChestStatus(player) ? "ON" : "OFF") + ".");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        plugin.setPlayerSilentChestStatus(player, !plugin.getPlayerSilentChestStatus(player));
 | 
			
		||||
        sender.sendMessage("SilentChest is now " + (plugin.getPlayerSilentChestStatus(player) ? "ON" : "OFF") + ".");
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,160 +0,0 @@
 | 
			
		||||
package com.lishid.openinv.util;
 | 
			
		||||
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.Multimap;
 | 
			
		||||
import com.google.common.collect.TreeMultimap;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A minimal time-based cache implementation backed by a HashMap and TreeMultimap.
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Jikoo
 | 
			
		||||
 */
 | 
			
		||||
public class Cache<K, V> {
 | 
			
		||||
 | 
			
		||||
    private final Map<K, V> internal;
 | 
			
		||||
    private final Multimap<Long, K> expiry;
 | 
			
		||||
    private final long retention;
 | 
			
		||||
    private final Function<V> inUseCheck, postRemoval;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a Cache with the specified retention duration, in use function, and post-removal function.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param retention duration after which keys are automatically invalidated if not in use
 | 
			
		||||
     * @param inUseCheck Function used to check if a key is considered in use
 | 
			
		||||
     * @param postRemoval Function used to perform any operations required when a key is invalidated
 | 
			
		||||
     */
 | 
			
		||||
    public Cache(long retention, Function<V> inUseCheck, Function<V> postRemoval) {
 | 
			
		||||
        this.internal = new HashMap<K, V>();
 | 
			
		||||
 | 
			
		||||
        this.expiry = TreeMultimap.create(new Comparator<Long>() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public int compare(Long long1, Long long2) {
 | 
			
		||||
                        return long1.compareTo(long2);
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
                new Comparator<K>() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public int compare(K k1, K k2) {
 | 
			
		||||
                        return 0;
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
        this.retention = retention;
 | 
			
		||||
        this.inUseCheck = inUseCheck;
 | 
			
		||||
        this.postRemoval = postRemoval;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set a key and value pair. Keys are unique. Using an existing key will cause the old value to
 | 
			
		||||
     * be overwritten and the expiration timer to be reset.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param key key with which the specified value is to be associated
 | 
			
		||||
     * @param value value to be associated with the specified key
 | 
			
		||||
     */
 | 
			
		||||
    public void put(K key, V value) {
 | 
			
		||||
        // Invalidate key - runs lazy check and ensures value won't be cleaned up early
 | 
			
		||||
        invalidate(key);
 | 
			
		||||
 | 
			
		||||
        internal.put(key, value);
 | 
			
		||||
        expiry.put(System.currentTimeMillis() + retention, key);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the value to which the specified key is mapped, or null if no value is mapped for the key.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param key the key whose associated value is to be returned
 | 
			
		||||
     * @return the value to which the specified key is mapped, or null if no value is mapped for the key
 | 
			
		||||
     */
 | 
			
		||||
    public V get(K key) {
 | 
			
		||||
        // Run lazy check to clean cache
 | 
			
		||||
        lazyCheck();
 | 
			
		||||
 | 
			
		||||
        return internal.get(key);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns true if the specified key is mapped to a value.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param key key to check if a mapping exists for
 | 
			
		||||
     * @return true if a mapping exists for the specified key
 | 
			
		||||
     */
 | 
			
		||||
    public boolean containsKey(K key) {
 | 
			
		||||
        // Run lazy check to clean cache
 | 
			
		||||
        lazyCheck();
 | 
			
		||||
 | 
			
		||||
        return internal.containsKey(key);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Forcibly invalidates a key, even if it is considered to be in use.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param key key to invalidate
 | 
			
		||||
     */
 | 
			
		||||
    public void invalidate(K key) {
 | 
			
		||||
        // Run lazy check to clean cache
 | 
			
		||||
        lazyCheck();
 | 
			
		||||
 | 
			
		||||
        if (!internal.containsKey(key)) {
 | 
			
		||||
            // Value either not present or cleaned by lazy check. Either way, we're good
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Remove stored object
 | 
			
		||||
        internal.remove(key);
 | 
			
		||||
 | 
			
		||||
        // Remove expiration entry - prevents more work later, plus prevents issues with values invalidating early
 | 
			
		||||
        for (Iterator<Map.Entry<Long, K>> iterator = expiry.entries().iterator(); iterator.hasNext();) {
 | 
			
		||||
            if (key.equals(iterator.next().getValue())) {
 | 
			
		||||
                iterator.remove();
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Forcibly invalidates all keys, even if they are considered to be in use.
 | 
			
		||||
     */
 | 
			
		||||
    public void invalidateAll() {
 | 
			
		||||
        for (V value : internal.values()) {
 | 
			
		||||
            postRemoval.run(value);
 | 
			
		||||
        }
 | 
			
		||||
        expiry.clear();
 | 
			
		||||
        internal.clear();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Invalidate all expired keys that are not considered in use. If a key is expired but is
 | 
			
		||||
     * considered in use by the provided Function, its expiration time is reset.
 | 
			
		||||
     */
 | 
			
		||||
    private void lazyCheck() {
 | 
			
		||||
        long now = System.currentTimeMillis();
 | 
			
		||||
        long nextExpiry = now + retention;
 | 
			
		||||
        for (Iterator<Map.Entry<Long, K>> iterator = expiry.entries().iterator(); iterator.hasNext();) {
 | 
			
		||||
            Map.Entry<Long, K> entry = iterator.next();
 | 
			
		||||
 | 
			
		||||
            if (entry.getKey() > now) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            iterator.remove();
 | 
			
		||||
 | 
			
		||||
            if (inUseCheck.run(internal.get(entry.getValue()))) {
 | 
			
		||||
                expiry.put(nextExpiry, entry.getValue());
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            V value = internal.remove(entry.getValue());
 | 
			
		||||
 | 
			
		||||
            if (value == null) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            postRemoval.run(value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
package com.lishid.openinv.util;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Abstraction for some simple cache calls.
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Jikoo
 | 
			
		||||
 */
 | 
			
		||||
public abstract class Function<V> {
 | 
			
		||||
 | 
			
		||||
    public abstract boolean run(V value);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,45 +0,0 @@
 | 
			
		||||
name: OpenInv
 | 
			
		||||
main: com.lishid.openinv.OpenInv
 | 
			
		||||
version: ${openinv.version}
 | 
			
		||||
author: lishid
 | 
			
		||||
authors: [Jikoo, ShadowRanger]
 | 
			
		||||
description: >
 | 
			
		||||
             This plugin allows you to open a player's inventory as a chest and interact with it in real time.
 | 
			
		||||
commands:
 | 
			
		||||
  openinv:
 | 
			
		||||
    aliases: [oi, inv, open]
 | 
			
		||||
    description: Open a player's inventory
 | 
			
		||||
    permission: OpenInv.*;OpenInv.openinv
 | 
			
		||||
    usage: |-
 | 
			
		||||
           /<command> [Player] - Open a player's inventory
 | 
			
		||||
  openender:
 | 
			
		||||
    aliases: [oe]
 | 
			
		||||
    description: Opens the enderchest of a player
 | 
			
		||||
    permission: OpenInv.*;OpenInv.openender
 | 
			
		||||
    usage: |-
 | 
			
		||||
           /<command> [Player] - Open a player's enderchest
 | 
			
		||||
  searchinv:
 | 
			
		||||
    aliases: [si]
 | 
			
		||||
    description: Search and list players having a specific item
 | 
			
		||||
    permission: OpenInv.*;OpenInv.search
 | 
			
		||||
    usage: |-
 | 
			
		||||
           /<command> <Item> [MinAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required
 | 
			
		||||
  searchender:
 | 
			
		||||
    aliases: [se]
 | 
			
		||||
    permission: OpenInv.*;OpenInv.search
 | 
			
		||||
    description: Searches and lists players having a specific item in their ender chest
 | 
			
		||||
    usage: |-
 | 
			
		||||
           /<command> <item> [minAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required
 | 
			
		||||
  silentchest:
 | 
			
		||||
    aliases: [sc, silent]
 | 
			
		||||
    description: Toggle silent chest function, which stops sounds and animations when using containers.
 | 
			
		||||
    permission: OpenInv.*;OpenInv.silent
 | 
			
		||||
    usage: |-
 | 
			
		||||
           /<command> [Check] - Check or toggle silent chest
 | 
			
		||||
  anychest:
 | 
			
		||||
    aliases: [ac]
 | 
			
		||||
    description: Toggle anychest function, which allows opening of blocked chests.
 | 
			
		||||
    permission: OpenInv.*;OpenInv.anychest
 | 
			
		||||
    usage: |-
 | 
			
		||||
           /<command> [Check] - Checks or toggle anychest
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										216
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										216
									
								
								pom.xml
									
									
									
									
									
								
							@@ -1,168 +1,62 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<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>pom</packaging>
 | 
			
		||||
  <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  <name>OpenInv</name>
 | 
			
		||||
  <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
			
		||||
<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.3.1</version>
 | 
			
		||||
    <name>OpenInv</name>
 | 
			
		||||
    <url>http://dev.bukkit.org/bukkit-plugins/openinv/</url>
 | 
			
		||||
 | 
			
		||||
  <properties>
 | 
			
		||||
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
			
		||||
    <openinv.version>3.0.0-SNAPSHOT</openinv.version>
 | 
			
		||||
  </properties>
 | 
			
		||||
    <properties>
 | 
			
		||||
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
			
		||||
    </properties>
 | 
			
		||||
 | 
			
		||||
  <profiles>
 | 
			
		||||
    <repositories>
 | 
			
		||||
        <repository>
 | 
			
		||||
            <id>bukkit-repo</id>
 | 
			
		||||
            <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
 | 
			
		||||
        </repository>
 | 
			
		||||
    </repositories>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
      ~ N.B.: All dependencies for profiles are set in ./assembly/pom.xml
 | 
			
		||||
      ~ 
 | 
			
		||||
      ~ This is to prevent recursive dependencies. It's not ideal, but it works.
 | 
			
		||||
      ~ The parent project always builds first. Then, due to profile ordering here,
 | 
			
		||||
      ~ whatever modules are enabled are built. Finally, the assembly module is built,
 | 
			
		||||
      ~ which contains no actual code, but shades all its "dependencies" into one jar.
 | 
			
		||||
     -->
 | 
			
		||||
    <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.bukkit</groupId>
 | 
			
		||||
            <artifactId>bukkit</artifactId>
 | 
			
		||||
            <version>1.8.7-R0.1-SNAPSHOT</version>
 | 
			
		||||
            <scope>provided</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
      ~ This profile exists to simplify profile usage.
 | 
			
		||||
      ~ The interface and plugin modules should be built first to ensure that they are up to date.
 | 
			
		||||
     -->
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>reactorbuildfirst</id>
 | 
			
		||||
      <activation>
 | 
			
		||||
        <property>
 | 
			
		||||
          <name>!breakBuildProcess</name>
 | 
			
		||||
        </property>
 | 
			
		||||
      </activation>
 | 
			
		||||
      <modules>
 | 
			
		||||
        <module>internal</module>
 | 
			
		||||
        <module>plugin</module>
 | 
			
		||||
      </modules>
 | 
			
		||||
    </profile>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.bukkit</groupId>
 | 
			
		||||
            <artifactId>craftbukkit</artifactId>
 | 
			
		||||
            <version>1.8.7-R0.1-SNAPSHOT</version>
 | 
			
		||||
            <scope>provided</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>latest</id>
 | 
			
		||||
      <activation>
 | 
			
		||||
        <property>
 | 
			
		||||
          <name>latest</name>
 | 
			
		||||
          <value>true</value>
 | 
			
		||||
        </property>
 | 
			
		||||
      </activation>
 | 
			
		||||
      <modules>
 | 
			
		||||
        <module>v1_11_R1</module>
 | 
			
		||||
      </modules>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>modern</id>
 | 
			
		||||
      <activation>
 | 
			
		||||
        <property>
 | 
			
		||||
          <name>modern</name>
 | 
			
		||||
          <value>true</value>
 | 
			
		||||
        </property>
 | 
			
		||||
      </activation>
 | 
			
		||||
      <modules>
 | 
			
		||||
        <module>v1_8_R1</module>
 | 
			
		||||
        <module>v1_8_R2</module>
 | 
			
		||||
        <module>v1_8_R3</module>
 | 
			
		||||
        <module>v1_9_R1</module>
 | 
			
		||||
        <module>v1_9_R2</module>
 | 
			
		||||
        <module>v1_10_R1</module>
 | 
			
		||||
        <module>v1_11_R1</module>
 | 
			
		||||
      </modules>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>all</id>
 | 
			
		||||
      <activation>
 | 
			
		||||
        <activeByDefault>true</activeByDefault>
 | 
			
		||||
      </activation>
 | 
			
		||||
      <modules>
 | 
			
		||||
        <module>1_4_5</module>
 | 
			
		||||
        <module>1_4_6</module>
 | 
			
		||||
        <module>v1_4_R1</module>
 | 
			
		||||
        <!-- 1_5_R1 was never released -->
 | 
			
		||||
        <module>v1_5_R2</module>
 | 
			
		||||
        <module>v1_5_R3</module>
 | 
			
		||||
        <!-- 1_6_R1 also had no tagged releases, remove? -->
 | 
			
		||||
        <module>v1_6_R1</module>
 | 
			
		||||
        <module>v1_6_R2</module>
 | 
			
		||||
        <module>v1_6_R3</module>
 | 
			
		||||
        <!-- TODO: Recompile CB for 1_7_R1 through 1_7_R4, currently using whatever jars worked -->
 | 
			
		||||
        <module>v1_7_R1</module>
 | 
			
		||||
        <module>v1_7_R2</module>
 | 
			
		||||
        <module>v1_7_R3</module>
 | 
			
		||||
        <module>v1_7_R4</module>
 | 
			
		||||
        <module>v1_8_R1</module>
 | 
			
		||||
        <module>v1_8_R2</module>
 | 
			
		||||
        <module>v1_8_R3</module>
 | 
			
		||||
        <module>v1_9_R1</module>
 | 
			
		||||
        <module>v1_9_R2</module>
 | 
			
		||||
        <module>v1_10_R1</module>
 | 
			
		||||
        <module>v1_11_R1</module>
 | 
			
		||||
      </modules>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
    <!--
 | 
			
		||||
      ~ This profile exists to fix reactor build order.
 | 
			
		||||
      ~ The assembly module must be built last to aggregate all active modules into the final jar.
 | 
			
		||||
     -->
 | 
			
		||||
    <profile>
 | 
			
		||||
      <id>reactorbuildlast</id>
 | 
			
		||||
      <activation>
 | 
			
		||||
        <property>
 | 
			
		||||
          <name>!breakBuildProcess</name>
 | 
			
		||||
        </property>
 | 
			
		||||
      </activation>
 | 
			
		||||
      <modules>
 | 
			
		||||
        <module>assembly</module>
 | 
			
		||||
      </modules>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
  </profiles>
 | 
			
		||||
 | 
			
		||||
  <repositories>
 | 
			
		||||
    <repository>
 | 
			
		||||
      <id>spigot-repo</id>
 | 
			
		||||
      <url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
 | 
			
		||||
    </repository>
 | 
			
		||||
  </repositories>
 | 
			
		||||
 | 
			
		||||
  <build>
 | 
			
		||||
    <plugins>
 | 
			
		||||
      <plugin>
 | 
			
		||||
        <groupId>org.apache.maven.plugins</groupId>
 | 
			
		||||
        <artifactId>maven-shade-plugin</artifactId>
 | 
			
		||||
        <version>2.4.3</version>
 | 
			
		||||
        <configuration>
 | 
			
		||||
          <filters>
 | 
			
		||||
            <filter>
 | 
			
		||||
              <artifact>*:*</artifact>
 | 
			
		||||
              <!-- Keep the file clean, don't include every single pom from all modules -->
 | 
			
		||||
              <excludes>META-INF/maven/**</excludes>
 | 
			
		||||
            </filter>
 | 
			
		||||
          </filters>
 | 
			
		||||
        </configuration>
 | 
			
		||||
        <executions>
 | 
			
		||||
          <execution>
 | 
			
		||||
            <phase>package</phase>
 | 
			
		||||
            <goals>
 | 
			
		||||
              <goal>shade</goal>
 | 
			
		||||
            </goals>
 | 
			
		||||
          </execution>
 | 
			
		||||
        </executions>
 | 
			
		||||
      </plugin>
 | 
			
		||||
 | 
			
		||||
      <plugin>
 | 
			
		||||
        <artifactId>maven-compiler-plugin</artifactId>
 | 
			
		||||
        <version>3.5.1</version>
 | 
			
		||||
        <configuration>
 | 
			
		||||
          <source>1.6</source>
 | 
			
		||||
          <target>1.6</target>
 | 
			
		||||
        </configuration>
 | 
			
		||||
      </plugin>
 | 
			
		||||
    </plugins>
 | 
			
		||||
  </build>
 | 
			
		||||
    <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>
 | 
			
		||||
							
								
								
									
										160
									
								
								src/main/java/com/lishid/openinv/ConfigUpdater.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										160
									
								
								src/main/java/com/lishid/openinv/ConfigUpdater.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,160 @@
 | 
			
		||||
package com.lishid.openinv;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.configuration.ConfigurationSection;
 | 
			
		||||
import org.bukkit.configuration.file.FileConfiguration;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.utils.UUIDUtil;
 | 
			
		||||
 | 
			
		||||
public class ConfigUpdater {
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
 | 
			
		||||
    private static final int CONFIG_VERSION = 2;
 | 
			
		||||
 | 
			
		||||
    public ConfigUpdater(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getConfigVersion() {
 | 
			
		||||
        return plugin.getConfig().getInt("config-version", 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isConfigOutdated() {
 | 
			
		||||
        return getConfigVersion() < CONFIG_VERSION;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void checkForUpdates() {
 | 
			
		||||
        if (isConfigOutdated()) {
 | 
			
		||||
            plugin.getLogger().info("[Config] Update found! Performing update...");
 | 
			
		||||
            performUpdate();
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            plugin.getLogger().info("[Config] Update not required.");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void performUpdate() {
 | 
			
		||||
        // Update according to the right version
 | 
			
		||||
        switch (getConfigVersion()) {
 | 
			
		||||
            case 1:
 | 
			
		||||
                updateConfig1To2();
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void updateConfig1To2() {
 | 
			
		||||
        FileConfiguration config = plugin.getConfig();
 | 
			
		||||
 | 
			
		||||
        // Backup the old config file
 | 
			
		||||
        File configFile = new File(plugin.getDataFolder(), "config.yml");
 | 
			
		||||
        File oldConfigFile = new File(plugin.getDataFolder(), "config_old.yml");
 | 
			
		||||
 | 
			
		||||
        configFile.renameTo(oldConfigFile);
 | 
			
		||||
 | 
			
		||||
        if (configFile.exists()) {
 | 
			
		||||
            configFile.delete();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        plugin.getLogger().info("[Config] Backup of old config.yml file created.");
 | 
			
		||||
 | 
			
		||||
        // Get the old config settings
 | 
			
		||||
        int itemOpenInvItemId = config.getInt("ItemOpenInvItemID", 280);
 | 
			
		||||
        boolean notifySilentChest = config.getBoolean("NotifySilentChest", true);
 | 
			
		||||
        boolean notifyAnyChest = config.getBoolean("NotifyAnyChest", true);
 | 
			
		||||
 | 
			
		||||
        Map<UUID, Boolean> anyChestToggles = null;
 | 
			
		||||
        Map<UUID, Boolean> itemOpenInvToggles = null;
 | 
			
		||||
        Map<UUID, Boolean> silentChestToggles = null;
 | 
			
		||||
 | 
			
		||||
        if (config.isSet("AnyChest")) {
 | 
			
		||||
            anyChestToggles = updateToggles("AnyChest");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (config.isSet("ItemOpenInv")) {
 | 
			
		||||
            itemOpenInvToggles = updateToggles("ItemOpenInv");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (config.isSet("SilentChest")) {
 | 
			
		||||
            silentChestToggles = updateToggles("SilentChest");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Clear the old config
 | 
			
		||||
        for (String key : config.getKeys(false)) {
 | 
			
		||||
            config.set(key, null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Set the new config options
 | 
			
		||||
        plugin.saveDefaultConfig();
 | 
			
		||||
        plugin.reloadConfig();
 | 
			
		||||
 | 
			
		||||
        config = plugin.getConfig(); // Refresh the referenced plugin config
 | 
			
		||||
 | 
			
		||||
        config.set("config-version", 2);
 | 
			
		||||
        config.set("items.open-inv", getMaterialById(itemOpenInvItemId).toString());
 | 
			
		||||
        config.set("notify.any-chest", notifyAnyChest);
 | 
			
		||||
        config.set("notify.silent-chest", notifySilentChest);
 | 
			
		||||
 | 
			
		||||
        if (anyChestToggles != null && !anyChestToggles.isEmpty()) {
 | 
			
		||||
            for (Map.Entry<UUID, Boolean> entry : anyChestToggles.entrySet()) {
 | 
			
		||||
                config.set("toggles.any-chest." + entry.getKey(), entry.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (itemOpenInvToggles != null && !itemOpenInvToggles.isEmpty()) {
 | 
			
		||||
            for (Map.Entry<UUID, Boolean> entry : itemOpenInvToggles.entrySet()) {
 | 
			
		||||
                config.set("toggles.items.open-inv." + entry.getKey(), entry.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (silentChestToggles != null && !silentChestToggles.isEmpty()) {
 | 
			
		||||
            for (Map.Entry<UUID, Boolean> entry : silentChestToggles.entrySet()) {
 | 
			
		||||
                config.set("toggles.silent-chest." + entry.getKey(), entry.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Save the new config
 | 
			
		||||
        plugin.saveConfig();
 | 
			
		||||
        plugin.getLogger().info("[Config] Update complete.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Map<UUID, Boolean> updateToggles(String sectionName) {
 | 
			
		||||
        Map<UUID, Boolean> toggles = new HashMap<UUID, Boolean>();
 | 
			
		||||
 | 
			
		||||
        ConfigurationSection section = plugin.getConfig().getConfigurationSection(sectionName);
 | 
			
		||||
        Set<String> keys = section.getKeys(false);
 | 
			
		||||
        if (keys == null || keys.isEmpty()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int total = keys.size();
 | 
			
		||||
        int converted = 0;
 | 
			
		||||
 | 
			
		||||
        for (String playerName : keys) {
 | 
			
		||||
            UUID uuid = UUIDUtil.getUUIDOf(playerName);
 | 
			
		||||
            if (uuid != null) {
 | 
			
		||||
                boolean toggled = section.getBoolean(playerName + ".toggle", false);
 | 
			
		||||
                toggles.put(uuid, toggled);
 | 
			
		||||
                converted++;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        plugin.getLogger().info("[Config] Converted (" + converted + "/" + total + ") " + sectionName + " toggle player usernames to UUIDs.");
 | 
			
		||||
 | 
			
		||||
        return toggles;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings("deprecation")
 | 
			
		||||
    private Material getMaterialById(int id) {
 | 
			
		||||
        Material material = Material.getMaterial(id);
 | 
			
		||||
        if (material == null) {
 | 
			
		||||
            material = Material.STICK;
 | 
			
		||||
        }
 | 
			
		||||
        return material;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										226
									
								
								src/main/java/com/lishid/openinv/OpenInv.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										226
									
								
								src/main/java/com/lishid/openinv/OpenInv.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,226 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.permissions.Permissible;
 | 
			
		||||
import org.bukkit.plugin.PluginManager;
 | 
			
		||||
import org.bukkit.plugin.java.JavaPlugin;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.commands.AnyChestCommand;
 | 
			
		||||
import com.lishid.openinv.commands.OpenEnderCommand;
 | 
			
		||||
import com.lishid.openinv.commands.OpenInvCommand;
 | 
			
		||||
import com.lishid.openinv.commands.SearchEnderCommand;
 | 
			
		||||
import com.lishid.openinv.commands.SearchInvCommand;
 | 
			
		||||
import com.lishid.openinv.commands.SilentChestCommand;
 | 
			
		||||
import com.lishid.openinv.commands.ToggleOpenInvCommand;
 | 
			
		||||
import com.lishid.openinv.internal.AnySilentChest;
 | 
			
		||||
import com.lishid.openinv.internal.InventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.PlayerDataManager;
 | 
			
		||||
import com.lishid.openinv.internal.SpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.listeners.OpenInvEntityListener;
 | 
			
		||||
import com.lishid.openinv.listeners.OpenInvInventoryListener;
 | 
			
		||||
import com.lishid.openinv.listeners.OpenInvPlayerListener;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Open other player's inventory
 | 
			
		||||
 *
 | 
			
		||||
 * @author lishid
 | 
			
		||||
 */
 | 
			
		||||
public class OpenInv extends JavaPlugin {
 | 
			
		||||
    public static final Map<UUID, SpecialPlayerInventory> inventories = new HashMap<UUID, SpecialPlayerInventory>();
 | 
			
		||||
    public static final Map<UUID, SpecialEnderChest> enderChests = new HashMap<UUID, SpecialEnderChest>();
 | 
			
		||||
 | 
			
		||||
    public static OpenInv mainPlugin;
 | 
			
		||||
 | 
			
		||||
    private static PlayerDataManager playerLoader;
 | 
			
		||||
    private static InventoryAccess inventoryAccess;
 | 
			
		||||
    private static AnySilentChest anySilentChest;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onEnable() {
 | 
			
		||||
        // Plugin
 | 
			
		||||
        mainPlugin = this;
 | 
			
		||||
 | 
			
		||||
        // Config Updater
 | 
			
		||||
        ConfigUpdater configUpdater = new ConfigUpdater(this);
 | 
			
		||||
        configUpdater.checkForUpdates();
 | 
			
		||||
 | 
			
		||||
        // Initialize
 | 
			
		||||
        playerLoader = new PlayerDataManager();
 | 
			
		||||
        inventoryAccess = new InventoryAccess();
 | 
			
		||||
        anySilentChest = new AnySilentChest();
 | 
			
		||||
 | 
			
		||||
        // Save the default config.yml if it doesn't already exist
 | 
			
		||||
        saveDefaultConfig();
 | 
			
		||||
 | 
			
		||||
        // Register the plugin's events & commands
 | 
			
		||||
        registerEvents();
 | 
			
		||||
        registerCommands();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void registerEvents() {
 | 
			
		||||
        PluginManager pm = getServer().getPluginManager();
 | 
			
		||||
 | 
			
		||||
        pm.registerEvents(new OpenInvPlayerListener(), this);
 | 
			
		||||
        pm.registerEvents(new OpenInvEntityListener(), this);
 | 
			
		||||
        pm.registerEvents(new OpenInvInventoryListener(), this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void registerCommands() {
 | 
			
		||||
        getCommand("openinv").setExecutor(new OpenInvCommand(this));
 | 
			
		||||
        getCommand("openender").setExecutor(new OpenEnderCommand(this));
 | 
			
		||||
        getCommand("searchinv").setExecutor(new SearchInvCommand());
 | 
			
		||||
        getCommand("searchender").setExecutor(new SearchEnderCommand());
 | 
			
		||||
        getCommand("toggleopeninv").setExecutor(new ToggleOpenInvCommand());
 | 
			
		||||
        getCommand("anychest").setExecutor(new AnyChestCommand());
 | 
			
		||||
        getCommand("silentchest").setExecutor(new SilentChestCommand());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static PlayerDataManager getPlayerLoader() {
 | 
			
		||||
        return playerLoader;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static InventoryAccess getInventoryAccess() {
 | 
			
		||||
        return inventoryAccess;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static AnySilentChest getAnySilentChest() {
 | 
			
		||||
        return anySilentChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getFromConfig(String path, Object defaultValue) {
 | 
			
		||||
        Object val = mainPlugin.getConfig().get(path);
 | 
			
		||||
        if (val == null) {
 | 
			
		||||
            mainPlugin.getConfig().set(path, defaultValue);
 | 
			
		||||
            return defaultValue;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            return val;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void saveToConfig(String path, Object value) {
 | 
			
		||||
        mainPlugin.getConfig().set(path, value);
 | 
			
		||||
        mainPlugin.saveConfig();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Material getOpenInvItem() {
 | 
			
		||||
        if (!mainPlugin.getConfig().isSet("items.open-inv")) {
 | 
			
		||||
            saveToConfig("items.open-inv", "STICK");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        String itemName = mainPlugin.getConfig().getString("items.open-inv", "STICK");
 | 
			
		||||
        Material material = Material.getMaterial(itemName);
 | 
			
		||||
        if (material == null) {
 | 
			
		||||
            mainPlugin.getLogger().warning("OpenInv item '" + itemName + "' does not match to a valid item. Defaulting to stick.");
 | 
			
		||||
            material = Material.STICK;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return material;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean notifySilentChest() {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("notify.silent-chest", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean notifyAnyChest() {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("notify.any-chest", true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean getPlayerAnyChestStatus(Player player) {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("toggles.any-chest." + player.getUniqueId(), false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setPlayerAnyChestStatus(Player player, boolean status) {
 | 
			
		||||
        saveToConfig("toggles.any-chest." + player.getUniqueId(), status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean getPlayerItemOpenInvStatus(Player player) {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("toggles.items.open-inv" + player.getUniqueId(), false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setPlayerItemOpenInvStatus(Player player, boolean status) {
 | 
			
		||||
        saveToConfig("toggles.items.open-inv." + player.getUniqueId(), status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean getPlayerSilentChestStatus(Player player) {
 | 
			
		||||
        return mainPlugin.getConfig().getBoolean("toggles.silent-chest." + player.getUniqueId(), false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setPlayerSilentChestStatus(Player player, boolean status) {
 | 
			
		||||
        saveToConfig("toggles.silent-chest." + player.getUniqueId(), status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void log(String text) {
 | 
			
		||||
        mainPlugin.getLogger().info("[OpenInv] " + text);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void log(Throwable e) {
 | 
			
		||||
        mainPlugin.getLogger().severe("[OpenInv] " + e.toString());
 | 
			
		||||
        e.printStackTrace();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void sendMessage(CommandSender sender, String message) {
 | 
			
		||||
        sender.sendMessage(ChatColor.AQUA + "[OpenInv] " + ChatColor.WHITE + message);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void showHelp(Player player) {
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/openinv <player> - Open a player's inventory.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: oi, inv, open)");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/openender <player> - Open a player's ender chest.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: oe)");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/searchinv <item> [minAmount] -");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   Search and list players having a specific item.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: si)");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/searchender <item> [minAmount] -");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   Search and list players having a specific item.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: se)");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle the item openinv function.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: toi, toggleoi, toggleinv)");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/anychest - Toggle the any chest function.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: ac)");
 | 
			
		||||
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle the silent chest function.");
 | 
			
		||||
        player.sendMessage(ChatColor.GREEN + "   (aliases: sc, silent)");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean hasPermission(Permissible player, String permission) {
 | 
			
		||||
        String[] parts = permission.split("\\.");
 | 
			
		||||
        String perm = "";
 | 
			
		||||
        for (int i = 0; i < parts.length; i++) {
 | 
			
		||||
            if (player.hasPermission(perm + "*")) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            perm += parts[i] + ".";
 | 
			
		||||
        }
 | 
			
		||||
        return player.hasPermission(permission);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										16
									
								
								src/main/java/com/lishid/openinv/Permissions.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/main/java/com/lishid/openinv/Permissions.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
package com.lishid.openinv;
 | 
			
		||||
 | 
			
		||||
public class Permissions {
 | 
			
		||||
    public static final String PERM_OPENINV = "OpenInv.openinv";
 | 
			
		||||
    public static final String PERM_OVERRIDE = "OpenInv.override";
 | 
			
		||||
    public static final String PERM_EXEMPT = "OpenInv.exempt";
 | 
			
		||||
    public static final String PERM_CROSSWORLD = "OpenInv.crossworld";
 | 
			
		||||
    public static final String PERM_SILENT = "OpenInv.silent";
 | 
			
		||||
    public static final String PERM_ANYCHEST = "OpenInv.anychest";
 | 
			
		||||
    public static final String PERM_ENDERCHEST = "OpenInv.openender";
 | 
			
		||||
    public static final String PERM_ENDERCHEST_ALL = "OpenInv.openenderall";
 | 
			
		||||
    public static final String PERM_SEARCH = "OpenInv.search";
 | 
			
		||||
    public static final String PERM_EDITINV = "OpenInv.editinv";
 | 
			
		||||
    public static final String PERM_EDITENDER = "OpenInv.editender";
 | 
			
		||||
    public static final String PERM_OPENSELF = "OpenInv.openself";
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,62 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
 | 
			
		||||
public class AnyChestCommand implements CommandExecutor {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (command.getName().equalsIgnoreCase("anychest")) {
 | 
			
		||||
            if (!(sender instanceof Player)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_ANYCHEST)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You do not have permission to use any chest.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
            if (args.length > 0) {
 | 
			
		||||
                if (args[0].equalsIgnoreCase("check")) {
 | 
			
		||||
                    String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
			
		||||
                    OpenInv.sendMessage(player, "Any Chest is " + status + ChatColor.RESET + ".");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            OpenInv.setPlayerAnyChestStatus(player, !OpenInv.getPlayerAnyChestStatus(player));
 | 
			
		||||
 | 
			
		||||
            String status = OpenInv.getPlayerAnyChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
			
		||||
            OpenInv.sendMessage(player, "Any Chest is now " + status + ChatColor.RESET + ".");
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										164
									
								
								src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,164 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.concurrent.ConcurrentHashMap;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.SpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.utils.UUIDUtil;
 | 
			
		||||
 | 
			
		||||
public class OpenEnderCommand implements CommandExecutor {
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
    private final Map<UUID, UUID> openEnderHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
			
		||||
 | 
			
		||||
    public OpenEnderCommand(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (command.getName().equalsIgnoreCase("openender")) {
 | 
			
		||||
            if (!(sender instanceof Player)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You do not have permission to access player ender chests.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
 | 
			
		||||
                OpenInv.showHelp((Player) sender);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            final Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
            // History management
 | 
			
		||||
            UUID history = openEnderHistory.get(player.getUniqueId());
 | 
			
		||||
            if (history == null) {
 | 
			
		||||
                history = player.getUniqueId();
 | 
			
		||||
                openEnderHistory.put(player.getUniqueId(), history);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            final UUID uuid;
 | 
			
		||||
 | 
			
		||||
            // Read from history if target is not named
 | 
			
		||||
            if (args.length < 1) {
 | 
			
		||||
                if (history != null) {
 | 
			
		||||
                    uuid = history;
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
			
		||||
                if (uuid == null) {
 | 
			
		||||
                    player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            final UUID playerUUID = player.getUniqueId();
 | 
			
		||||
 | 
			
		||||
            Player target = Bukkit.getPlayer(uuid);
 | 
			
		||||
            if (target == null) {
 | 
			
		||||
                // Targeted player was not found online, start asynchronous lookup in files
 | 
			
		||||
                Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void run() {
 | 
			
		||||
                        // Try loading the player's data asynchronously
 | 
			
		||||
                        final Player target = OpenInv.getPlayerLoader().loadPlayer(uuid);
 | 
			
		||||
                        if (target == null) {
 | 
			
		||||
                            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                            return;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        // Open target's inventory synchronously
 | 
			
		||||
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
			
		||||
                            @Override
 | 
			
		||||
                            public void run() {
 | 
			
		||||
                                Player player = Bukkit.getPlayer(playerUUID);
 | 
			
		||||
                                // If sender is no longer online after loading the target, abort!
 | 
			
		||||
                                if (player == null) {
 | 
			
		||||
                                    return;
 | 
			
		||||
                                }
 | 
			
		||||
                                openInventory(player, target);
 | 
			
		||||
                            }
 | 
			
		||||
                        });
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            } else {
 | 
			
		||||
                openInventory(player, target);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void openInventory(Player player, Player target) {
 | 
			
		||||
        if (target == null) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + "You do not have permission to access other player's ender chests.");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Permissions checks
 | 
			
		||||
        if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s ender chest is protected!");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Crossworld check
 | 
			
		||||
        if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Record the target
 | 
			
		||||
        openEnderHistory.put(player.getUniqueId(), target.getUniqueId());
 | 
			
		||||
 | 
			
		||||
        // Create the inventory
 | 
			
		||||
        SpecialEnderChest chest = OpenInv.enderChests.get(target.getUniqueId());
 | 
			
		||||
        if (chest == null) {
 | 
			
		||||
            chest = new SpecialEnderChest(target, target.isOnline());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Open the inventory
 | 
			
		||||
        player.openInventory(chest.getBukkitInventory());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										158
									
								
								src/main/java/com/lishid/openinv/commands/OpenInvCommand.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								src/main/java/com/lishid/openinv/commands/OpenInvCommand.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,158 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.concurrent.ConcurrentHashMap;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.utils.UUIDUtil;
 | 
			
		||||
 | 
			
		||||
public class OpenInvCommand implements CommandExecutor {
 | 
			
		||||
    private final OpenInv plugin;
 | 
			
		||||
    private final Map<UUID, UUID> openInvHistory = new ConcurrentHashMap<UUID, UUID>();
 | 
			
		||||
 | 
			
		||||
    public OpenInvCommand(OpenInv plugin) {
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (command.getName().equalsIgnoreCase("openinv")) {
 | 
			
		||||
            if (!(sender instanceof Player)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (args.length > 0 && args[0].equalsIgnoreCase("?")) {
 | 
			
		||||
                OpenInv.showHelp((Player) sender);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            final Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
            // History management
 | 
			
		||||
            UUID history = openInvHistory.get(player.getUniqueId());
 | 
			
		||||
            if (history == null) {
 | 
			
		||||
                history = player.getUniqueId();
 | 
			
		||||
                openInvHistory.put(player.getUniqueId(), history);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            final UUID uuid;
 | 
			
		||||
 | 
			
		||||
            // Read from history if target is not named
 | 
			
		||||
            if (args.length < 1) {
 | 
			
		||||
                uuid = history;
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                uuid = UUIDUtil.getUUIDOf(args[0]);
 | 
			
		||||
                if (uuid == null) {
 | 
			
		||||
                    player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            final UUID playerUUID = player.getUniqueId();
 | 
			
		||||
 | 
			
		||||
            Player target = Bukkit.getPlayer(uuid);
 | 
			
		||||
            if (target == null) {
 | 
			
		||||
                // Targeted player was not found online, start asynchronous lookup in files
 | 
			
		||||
                Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void run() {
 | 
			
		||||
                        // Try loading the player's data asynchronously
 | 
			
		||||
                        final Player target = OpenInv.getPlayerLoader().loadPlayer(uuid);
 | 
			
		||||
                        if (target == null) {
 | 
			
		||||
                            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
                            return;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        // Open target's inventory synchronously
 | 
			
		||||
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
			
		||||
                            @Override
 | 
			
		||||
                            public void run() {
 | 
			
		||||
                                Player player = Bukkit.getPlayer(playerUUID);
 | 
			
		||||
                                // If sender is no longer online after loading the target, abort!
 | 
			
		||||
                                if (player == null) {
 | 
			
		||||
                                    return;
 | 
			
		||||
                                }
 | 
			
		||||
                                openInventory(player, target);
 | 
			
		||||
                            }
 | 
			
		||||
                        });
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            } else {
 | 
			
		||||
                openInventory(player, target);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void openInventory(Player player, Player target) {
 | 
			
		||||
        if (target == null) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + "Player not found!");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Permissions checks
 | 
			
		||||
        if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Crossworld check
 | 
			
		||||
        if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Self-open check
 | 
			
		||||
        if (!OpenInv.hasPermission(player, Permissions.PERM_OPENSELF) && target.equals(player)) {
 | 
			
		||||
            player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself.");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Record the target
 | 
			
		||||
        openInvHistory.put(player.getUniqueId(), target.getUniqueId());
 | 
			
		||||
 | 
			
		||||
        // Create the inventory
 | 
			
		||||
        SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId());
 | 
			
		||||
        if (inv == null) {
 | 
			
		||||
            inv = new SpecialPlayerInventory(target, target.isOnline());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Open the inventory
 | 
			
		||||
        player.openInventory(inv.getBukkitInventory());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,65 @@
 | 
			
		||||
package com.lishid.openinv.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
 | 
			
		||||
public class SearchEnderCommand implements CommandExecutor {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (command.getName().equalsIgnoreCase("searchender")) {
 | 
			
		||||
            if (sender instanceof Player) {
 | 
			
		||||
                if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "You do not have permission to search player ender chests.");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Material material = null;
 | 
			
		||||
            int count = 1;
 | 
			
		||||
 | 
			
		||||
            if (args.length >= 1) {
 | 
			
		||||
                String[] gData;
 | 
			
		||||
                gData = args[0].split(":");
 | 
			
		||||
                material = Material.matchMaterial(gData[0]);
 | 
			
		||||
            }
 | 
			
		||||
            if (args.length >= 2) {
 | 
			
		||||
                try {
 | 
			
		||||
                    count = Integer.parseInt(args[1]);
 | 
			
		||||
                }
 | 
			
		||||
                catch (NumberFormatException ex) {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (material == null) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "Unknown item");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            StringBuilder sb = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
            for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
 | 
			
		||||
                if (onlinePlayer.getEnderChest().contains(material, count)) {
 | 
			
		||||
                    sb.append(onlinePlayer.getName());
 | 
			
		||||
                    sb.append("  ");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            String playerList = sb.toString();
 | 
			
		||||
            sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their ender chest:  " + playerList);
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,81 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
 | 
			
		||||
public class SearchInvCommand implements CommandExecutor {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (command.getName().equalsIgnoreCase("searchinv")) {
 | 
			
		||||
            if (sender instanceof Player) {
 | 
			
		||||
                if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "You do not have permission to search player inventories.");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Material material = null;
 | 
			
		||||
            int count = 1;
 | 
			
		||||
 | 
			
		||||
            if (args.length >= 1) {
 | 
			
		||||
                String[] gData;
 | 
			
		||||
                gData = args[0].split(":");
 | 
			
		||||
                material = Material.matchMaterial(gData[0]);
 | 
			
		||||
            }
 | 
			
		||||
            if (args.length >= 2) {
 | 
			
		||||
                try {
 | 
			
		||||
                    count = Integer.parseInt(args[1]);
 | 
			
		||||
                }
 | 
			
		||||
                catch (NumberFormatException ex) {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (material == null) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "Unknown item");
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            StringBuilder sb = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
            for (Player onlinePlayer : Bukkit.getServer().getOnlinePlayers()) {
 | 
			
		||||
                if (onlinePlayer.getInventory().contains(material, count)) {
 | 
			
		||||
                    sb.append(onlinePlayer.getName());
 | 
			
		||||
                    sb.append("  ");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            String playerList = sb.toString();
 | 
			
		||||
            sender.sendMessage("Players with the item " + ChatColor.GRAY + material.toString() + ChatColor.RESET + " in their inventory:  " + playerList);
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,62 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
 | 
			
		||||
public class SilentChestCommand implements CommandExecutor {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (command.getName().equalsIgnoreCase("silentchest")) {
 | 
			
		||||
            if (!(sender instanceof Player)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_SILENT)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You do not have permission to use silent chest.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
            if (args.length > 0) {
 | 
			
		||||
                if (args[0].equalsIgnoreCase("check")) {
 | 
			
		||||
                    String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
			
		||||
                    OpenInv.sendMessage(player, "Silent Chest is " + status + ChatColor.RESET + ".");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            OpenInv.setPlayerSilentChestStatus(player, !OpenInv.getPlayerSilentChestStatus(player));
 | 
			
		||||
 | 
			
		||||
            String status = OpenInv.getPlayerSilentChestStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
			
		||||
            OpenInv.sendMessage(player, "Silent Chest is now " + status + ChatColor.RESET + ".");
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,62 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
 | 
			
		||||
public class ToggleOpenInvCommand implements CommandExecutor {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (command.getName().equalsIgnoreCase("toggleopeninv")) {
 | 
			
		||||
            if (!(sender instanceof Player)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You can't use this command from the console.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories.");
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Player player = (Player) sender;
 | 
			
		||||
 | 
			
		||||
            if (args.length > 0) {
 | 
			
		||||
                if (args[0].equalsIgnoreCase("check")) {
 | 
			
		||||
                    String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
			
		||||
                    OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + status + ChatColor.RESET + ".");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            OpenInv.setPlayerItemOpenInvStatus(player, !OpenInv.getPlayerItemOpenInvStatus(player));
 | 
			
		||||
 | 
			
		||||
            String status = OpenInv.getPlayerItemOpenInvStatus(player) ? ChatColor.GREEN + "ON" : ChatColor.RED + "OFF";
 | 
			
		||||
            OpenInv.sendMessage(player, "OpenInv with " + ChatColor.GRAY + OpenInv.getOpenInvItem() + ChatColor.RESET + " is now " + status + ChatColor.RESET + ".");
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										141
									
								
								src/main/java/com/lishid/openinv/internal/AnySilentChest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								src/main/java/com/lishid/openinv/internal/AnySilentChest.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,141 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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 java.util.Iterator;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
			
		||||
 | 
			
		||||
public class AnySilentChest {
 | 
			
		||||
    public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        BlockPosition position = new BlockPosition(x, y, z);
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).b == 1 ?
 | 
			
		||||
                Block.getByName("trapped_chest") : Block.getByName("chest"));
 | 
			
		||||
 | 
			
		||||
        // If block on top
 | 
			
		||||
        if (topBlocking(world, position)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block on top
 | 
			
		||||
        for (EnumDirection direction : EnumDirectionList.HORIZONTAL) {
 | 
			
		||||
            BlockPosition sidePosition = position.shift(direction);
 | 
			
		||||
            Block var8 = world.getType(sidePosition).getBlock();
 | 
			
		||||
            if (var8 == chest) {
 | 
			
		||||
                if (this.topBlocking(world, sidePosition)) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    private boolean topBlocking(World world, BlockPosition position) {
 | 
			
		||||
        return this.blockOnTop(world, position) || this.ocelotOnTop(world, position);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean blockOnTop(World world, BlockPosition position) {
 | 
			
		||||
        return world.getType(position.up()).getBlock().isOccluding();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean ocelotOnTop(World world, BlockPosition position) {
 | 
			
		||||
        Iterator var3 = world.a(EntityOcelot.class,
 | 
			
		||||
                new AxisAlignedBB((double) position.getX(), (double) (position.getY() + 1),
 | 
			
		||||
                        (double) position.getZ(), (double) (position.getX() + 1),
 | 
			
		||||
                        (double) (position.getY() + 2), (double) (position.getZ() + 1))).iterator();
 | 
			
		||||
 | 
			
		||||
        EntityOcelot var5;
 | 
			
		||||
        do {
 | 
			
		||||
            if (!var3.hasNext()) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Entity var4 = (Entity) var3.next();
 | 
			
		||||
            var5 = (EntityOcelot) var4;
 | 
			
		||||
        } while (!var5.isSitting());
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean activateChest(Player p, boolean anyChest, boolean silentChest, int x, int y, int z) {
 | 
			
		||||
        BlockPosition position = new BlockPosition(x, y, z);
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        if (world.isClientSide) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).b == 1 ?
 | 
			
		||||
                Block.getByName("trapped_chest") : Block.getByName("chest"));
 | 
			
		||||
 | 
			
		||||
        TileEntity tileEntity = world.getTileEntity(position);
 | 
			
		||||
        if (!(tileEntity instanceof TileEntityChest)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ITileInventory tileInventory = (ITileInventory) tileEntity;
 | 
			
		||||
        if (!anyChest && this.topBlocking(world, position)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (EnumDirection direction : EnumDirectionList.HORIZONTAL) {
 | 
			
		||||
            BlockPosition side = position.shift(direction);
 | 
			
		||||
            Block block = world.getType(side).getBlock();
 | 
			
		||||
            if (block == chest) {
 | 
			
		||||
                if (!anyChest && this.topBlocking(world, side)) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                TileEntity sideTileEntity = world.getTileEntity(side);
 | 
			
		||||
                if (sideTileEntity instanceof TileEntityChest) {
 | 
			
		||||
                    if (direction != EnumDirection.WEST && direction != EnumDirection.NORTH) {
 | 
			
		||||
                        tileInventory = new InventoryLargeChest("container.chestDouble", tileInventory, (TileEntityChest) sideTileEntity);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        tileInventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) sideTileEntity, tileInventory);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = true;
 | 
			
		||||
        if (silentChest) {
 | 
			
		||||
            tileInventory = new SilentInventory(tileInventory);
 | 
			
		||||
            if (OpenInv.notifySilentChest()) {
 | 
			
		||||
                OpenInv.sendMessage(p, "You are opening a chest silently.");
 | 
			
		||||
            }
 | 
			
		||||
            returnValue = false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        player.openContainer(tileInventory);
 | 
			
		||||
 | 
			
		||||
        if (anyChest && OpenInv.notifyAnyChest()) {
 | 
			
		||||
            OpenInv.sendMessage(p, "You are opening a blocked chest.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
package com.lishid.openinv.internal;
 | 
			
		||||
 | 
			
		||||
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> {
 | 
			
		||||
    HORIZONTAL(EnumDirectionLimit.HORIZONTAL),
 | 
			
		||||
    VERTICAL(EnumDirectionLimit.VERTICAL);
 | 
			
		||||
 | 
			
		||||
    private final EnumDirectionLimit list;
 | 
			
		||||
 | 
			
		||||
    private EnumDirectionList(EnumDirectionLimit list) {
 | 
			
		||||
        this.list = list;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Iterator<EnumDirection> iterator() {
 | 
			
		||||
        return Iterators.forArray(list.a());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,72 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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 java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess {
 | 
			
		||||
    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 inventory
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,60 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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 java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.mojang.authlib.GameProfile;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager {
 | 
			
		||||
    public Player loadPlayer(UUID uuid) {
 | 
			
		||||
        try {
 | 
			
		||||
            OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
 | 
			
		||||
            if (player == null || !player.hasPlayedBefore()) {
 | 
			
		||||
                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.getBukkitEntity();
 | 
			
		||||
            if (target != null) {
 | 
			
		||||
                // Load data
 | 
			
		||||
                target.loadData();
 | 
			
		||||
                // Return the entity
 | 
			
		||||
                return target;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception e) {
 | 
			
		||||
            OpenInv.log(e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -16,27 +16,21 @@
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
public interface IPlayerDataManager {
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Loads a Player for an OfflinePlayer.
 | 
			
		||||
     * </p>
 | 
			
		||||
     * This method is potentially blocking, and should not be called on the main thread.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param offline
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets a unique identifying string for an OfflinePlayer.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player);
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman human) {
 | 
			
		||||
        super(i1, i2, human);
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // Close signal
 | 
			
		||||
        inv.closeContainer(human);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman paramEntityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										164
									
								
								src/main/java/com/lishid/openinv/internal/SilentInventory.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								src/main/java/com/lishid/openinv/internal/SilentInventory.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,164 @@
 | 
			
		||||
package com.lishid.openinv.internal;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity;
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.InventoryHolder;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
public class SilentInventory implements ITileInventory {
 | 
			
		||||
    public ITileInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentInventory(ITileInventory inv) {
 | 
			
		||||
        this.inv = inv;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean r_() {
 | 
			
		||||
        return inv.r_();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void a(ChestLock chestLock) {
 | 
			
		||||
        inv.a(chestLock);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ChestLock i() {
 | 
			
		||||
        return inv.i();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getSize() {
 | 
			
		||||
        return inv.getSize();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack getItem(int i) {
 | 
			
		||||
        return inv.getItem(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitStack(int i, int i1) {
 | 
			
		||||
        return inv.splitStack(i, i1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
        return inv.splitWithoutUpdate(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemStack) {
 | 
			
		||||
        inv.setItem(i, itemStack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return inv.getMaxStackSize();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        inv.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean a(EntityHuman entityHuman) {
 | 
			
		||||
        return inv.a(entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void startOpen(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't do anything
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void closeContainer(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't do anything
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean b(int i, ItemStack itemStack) {
 | 
			
		||||
        return inv.b(i, itemStack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getProperty(int i) {
 | 
			
		||||
        return inv.getProperty(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(int i, int i1) {
 | 
			
		||||
        inv.b(i, i1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int g() {
 | 
			
		||||
        return inv.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void l() {
 | 
			
		||||
        inv.l();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return inv.getContents();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onOpen(CraftHumanEntity craftHumanEntity) {
 | 
			
		||||
        inv.onOpen(craftHumanEntity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity craftHumanEntity) {
 | 
			
		||||
        inv.onClose(craftHumanEntity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return inv.getViewers();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return inv.getOwner();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setMaxStackSize(int i) {
 | 
			
		||||
        inv.setMaxStackSize(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        return inv.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean hasCustomName() {
 | 
			
		||||
        return inv.hasCustomName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IChatBaseComponent getScoreboardDisplayName() {
 | 
			
		||||
        return inv.getScoreboardDisplayName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Container createContainer(PlayerInventory playerInventory, EntityHuman entityHuman) {
 | 
			
		||||
        // Don't let the chest itself create the container.
 | 
			
		||||
        return new ContainerChest(playerInventory, this, entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getContainerName() {
 | 
			
		||||
        return inv.getContainerName();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,96 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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;
 | 
			
		||||
import org.bukkit.inventory.InventoryHolder;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer {
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftPlayer owner;
 | 
			
		||||
    private boolean playerOnline;
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player p, boolean online) {
 | 
			
		||||
        this(p, ((CraftPlayer) p).getHandle().getEnderChest(), online);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player p, InventoryEnderChest enderChest, boolean online) {
 | 
			
		||||
        super(enderChest.getName(), enderChest.hasCustomName(), enderChest.getSize());
 | 
			
		||||
        this.owner = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = enderChest;
 | 
			
		||||
        this.items = this.enderChest.getContents();
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        OpenInv.enderChests.put(owner.getUniqueId(), this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void saveOnExit() {
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
            owner.saveData();
 | 
			
		||||
            OpenInv.enderChests.remove(owner.getUniqueId());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void linkInventory(InventoryEnderChest inventory) {
 | 
			
		||||
        inventory.items = this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void playerOnline(Player p) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            linkInventory(((CraftPlayer) p).getHandle().getEnderChest());
 | 
			
		||||
            p.saveData();
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        owner.loadData();
 | 
			
		||||
        linkInventory(owner.getHandle().getEnderChest());
 | 
			
		||||
        saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        super.onClose(who);
 | 
			
		||||
        saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return this.owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -14,64 +14,78 @@
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
package com.lishid.openinv.internal;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_6_R3.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.PlayerInventory;
 | 
			
		||||
import net.minecraft.server.v1_8_R3.*;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.entity.*;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_8_R3.inventory.*;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory {
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private final CraftPlayer owner;
 | 
			
		||||
    private boolean playerOnline;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
    public SpecialPlayerInventory(Player p, boolean online) {
 | 
			
		||||
        super(((CraftPlayer) p).getHandle());
 | 
			
		||||
        this.owner = (CraftPlayer) p;
 | 
			
		||||
        this.items = player.inventory.items;
 | 
			
		||||
        this.armor = player.inventory.armor;
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        OpenInv.inventories.put(owner.getUniqueId(), this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
    private void saveOnExit() {
 | 
			
		||||
        if (transaction.isEmpty() && !playerOnline) {
 | 
			
		||||
            owner.saveData();
 | 
			
		||||
            OpenInv.inventories.remove(owner.getUniqueId());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void linkInventory(PlayerInventory inventory) {
 | 
			
		||||
        inventory.items = this.items;
 | 
			
		||||
        inventory.armor = this.armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void playerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            this.player.inventory.items = this.items;
 | 
			
		||||
            this.player.inventory.armor = this.armor;
 | 
			
		||||
            CraftPlayer p = (CraftPlayer) player;
 | 
			
		||||
            linkInventory(p.getHandle().inventory);
 | 
			
		||||
            p.saveData();
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
    public void playerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
        owner.loadData();
 | 
			
		||||
        linkInventory(owner.getHandle().inventory);
 | 
			
		||||
        saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        super.onClose(who);
 | 
			
		||||
        this.saveOnExit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        ItemStack[] contents = new ItemStack[getSize()];
 | 
			
		||||
        System.arraycopy(items, 0, contents, 0, items.length);
 | 
			
		||||
        System.arraycopy(armor, 0, contents, items.length, armor.length);
 | 
			
		||||
        return contents;
 | 
			
		||||
        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
 | 
			
		||||
@@ -133,9 +147,9 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -161,13 +175,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        } else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
    public void setItem(int i, ItemStack itemStack) {
 | 
			
		||||
        ItemStack[] is = this.items;
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
@@ -186,13 +200,13 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
 | 
			
		||||
        // Effects
 | 
			
		||||
        if (is == this.extra) {
 | 
			
		||||
            player.drop(itemstack);
 | 
			
		||||
            itemstack = null;
 | 
			
		||||
            owner.getHandle().drop(itemStack, true);
 | 
			
		||||
            itemStack = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        is[i] = itemstack;
 | 
			
		||||
        is[i] = itemStack;
 | 
			
		||||
 | 
			
		||||
        player.defaultContainer.b();
 | 
			
		||||
        owner.getHandle().defaultContainer.b();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
@@ -215,12 +229,24 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean hasCustomName() {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        player.inventory.update();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,54 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.listeners;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
 | 
			
		||||
public class OpenInvEntityListener implements Listener {
 | 
			
		||||
    @EventHandler(priority = EventPriority.LOWEST)
 | 
			
		||||
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
 | 
			
		||||
        Entity attacker = event.getDamager();
 | 
			
		||||
        Entity defender = event.getEntity();
 | 
			
		||||
 | 
			
		||||
        if (!(attacker instanceof Player) || !(defender instanceof Player)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Player player = (Player) attacker;
 | 
			
		||||
 | 
			
		||||
        if (player.getItemInHand().getType() == OpenInv.getOpenInvItem()) {
 | 
			
		||||
            if (!OpenInv.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Player target = (Player) defender;
 | 
			
		||||
 | 
			
		||||
            event.setDamage(0);
 | 
			
		||||
            event.setCancelled(true);
 | 
			
		||||
 | 
			
		||||
            player.performCommand("openinv " + target.getName());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,37 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.listeners;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.inventory.InventoryClickEvent;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
 | 
			
		||||
public class OpenInvInventoryListener implements Listener {
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onInventoryClick(InventoryClickEvent event) {
 | 
			
		||||
        Inventory inventory = event.getInventory();
 | 
			
		||||
        HumanEntity player = event.getWhoClicked();
 | 
			
		||||
 | 
			
		||||
        if (!OpenInv.getInventoryAccess().check(inventory, player)) {
 | 
			
		||||
            event.setCancelled(true);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,151 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.listeners;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.block.Chest;
 | 
			
		||||
import org.bukkit.block.Sign;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.Event.Result;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.block.Action;
 | 
			
		||||
import org.bukkit.event.player.PlayerInteractEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerJoinEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerQuitEvent;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.SpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.SpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class OpenInvPlayerListener implements Listener {
 | 
			
		||||
    @EventHandler(priority = EventPriority.LOWEST)
 | 
			
		||||
    public void onPlayerJoin(PlayerJoinEvent event) {
 | 
			
		||||
        Player player = event.getPlayer();
 | 
			
		||||
 | 
			
		||||
        SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
 | 
			
		||||
        if (inventory != null) {
 | 
			
		||||
            inventory.playerOnline(event.getPlayer());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        SpecialEnderChest chest = OpenInv.enderChests.get(player.getUniqueId());
 | 
			
		||||
        if (chest != null) {
 | 
			
		||||
            chest.playerOnline(event.getPlayer());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR)
 | 
			
		||||
    public void onPlayerQuit(PlayerQuitEvent event) {
 | 
			
		||||
        Player player = event.getPlayer();
 | 
			
		||||
 | 
			
		||||
        SpecialPlayerInventory inventory = OpenInv.inventories.get(player.getUniqueId());
 | 
			
		||||
        if (inventory != null) {
 | 
			
		||||
            inventory.playerOffline();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        SpecialEnderChest chest = OpenInv.enderChests.get(player.getUniqueId());
 | 
			
		||||
        if (chest != null) {
 | 
			
		||||
            chest.playerOffline();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onPlayerInteract(PlayerInteractEvent event) {
 | 
			
		||||
        Player player = event.getPlayer();
 | 
			
		||||
 | 
			
		||||
        if (player.isSneaking()) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Action action = event.getAction();
 | 
			
		||||
        Block block = event.getClickedBlock();
 | 
			
		||||
 | 
			
		||||
        switch (action) {
 | 
			
		||||
            case RIGHT_CLICK_BLOCK:
 | 
			
		||||
                if (event.useInteractedBlock() == Result.DENY) {
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Ender Chests
 | 
			
		||||
                if (block.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
                    if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
 | 
			
		||||
                        event.setCancelled(true);
 | 
			
		||||
                        player.openInventory(player.getEnderChest());
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Chests
 | 
			
		||||
                if (block.getState() instanceof Chest) {
 | 
			
		||||
                    boolean silentChest = false;
 | 
			
		||||
                    boolean anyChest = false;
 | 
			
		||||
                    int x = block.getX();
 | 
			
		||||
                    int y = block.getY();
 | 
			
		||||
                    int z = block.getZ();
 | 
			
		||||
 | 
			
		||||
                    if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && OpenInv.getPlayerSilentChestStatus(player)) {
 | 
			
		||||
                        silentChest = true;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && OpenInv.getPlayerAnyChestStatus(player)) {
 | 
			
		||||
                        try {
 | 
			
		||||
                            anyChest = OpenInv.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
 | 
			
		||||
                        }
 | 
			
		||||
                        catch (Exception e) {
 | 
			
		||||
                            player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
 | 
			
		||||
                            e.printStackTrace();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // If the anyChest or silentChest is active
 | 
			
		||||
                    if (anyChest || silentChest) {
 | 
			
		||||
                        if (!OpenInv.getAnySilentChest().activateChest(player, anyChest, silentChest, x, y, z)) {
 | 
			
		||||
                            event.setCancelled(true);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Signs
 | 
			
		||||
                if (block.getState() instanceof Sign) {
 | 
			
		||||
                    try {
 | 
			
		||||
                        Sign sign = ((Sign) block.getState());
 | 
			
		||||
                        if (OpenInv.hasPermission(player, Permissions.PERM_OPENINV) && sign.getLine(0).equalsIgnoreCase("[openinv]")) {
 | 
			
		||||
                            String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim();
 | 
			
		||||
                            player.performCommand("openinv " + text);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception e) {
 | 
			
		||||
                        player.sendMessage("Internal Error.");
 | 
			
		||||
                        e.printStackTrace();
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
            case RIGHT_CLICK_AIR:
 | 
			
		||||
                // OpenInv item
 | 
			
		||||
                if (player.getItemInHand().getType() == OpenInv.getOpenInvItem() && OpenInv.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) {
 | 
			
		||||
                    player.performCommand("openinv");
 | 
			
		||||
                }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										98
									
								
								src/main/java/com/lishid/openinv/utils/UUIDFetcher.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										98
									
								
								src/main/java/com/lishid/openinv/utils/UUIDFetcher.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,98 @@
 | 
			
		||||
package com.lishid.openinv.utils;
 | 
			
		||||
 | 
			
		||||
import java.io.InputStreamReader;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.net.HttpURLConnection;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.nio.ByteBuffer;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.concurrent.Callable;
 | 
			
		||||
 | 
			
		||||
import org.json.simple.JSONArray;
 | 
			
		||||
import org.json.simple.JSONObject;
 | 
			
		||||
import org.json.simple.parser.JSONParser;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.ImmutableList;
 | 
			
		||||
 | 
			
		||||
public class UUIDFetcher implements Callable<Map<String, UUID>> {
 | 
			
		||||
    private static final double PROFILES_PER_REQUEST = 100;
 | 
			
		||||
    private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
 | 
			
		||||
    private final JSONParser jsonParser = new JSONParser();
 | 
			
		||||
    private final List<String> names;
 | 
			
		||||
    private final boolean rateLimiting;
 | 
			
		||||
 | 
			
		||||
    public UUIDFetcher(List<String> names, boolean rateLimiting) {
 | 
			
		||||
        this.names = ImmutableList.copyOf(names);
 | 
			
		||||
        this.rateLimiting = rateLimiting;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UUIDFetcher(List<String> names) {
 | 
			
		||||
        this(names, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Map<String, UUID> call() throws Exception {
 | 
			
		||||
        Map<String, UUID> uuidMap = new HashMap<String, UUID>();
 | 
			
		||||
        int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
 | 
			
		||||
        for (int i = 0; i < requests; i++) {
 | 
			
		||||
            HttpURLConnection connection = createConnection();
 | 
			
		||||
            String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
 | 
			
		||||
            writeBody(connection, body);
 | 
			
		||||
            JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
 | 
			
		||||
            for (Object profile : array) {
 | 
			
		||||
                JSONObject jsonProfile = (JSONObject) profile;
 | 
			
		||||
                String id = (String) jsonProfile.get("id");
 | 
			
		||||
                String name = (String) jsonProfile.get("name");
 | 
			
		||||
                UUID uuid = UUIDFetcher.getUUID(id);
 | 
			
		||||
                uuidMap.put(name.toLowerCase(), uuid);
 | 
			
		||||
            }
 | 
			
		||||
            if (rateLimiting && i != requests - 1) {
 | 
			
		||||
                Thread.sleep(100L);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return uuidMap;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void writeBody(HttpURLConnection connection, String body) throws Exception {
 | 
			
		||||
        OutputStream stream = connection.getOutputStream();
 | 
			
		||||
        stream.write(body.getBytes());
 | 
			
		||||
        stream.flush();
 | 
			
		||||
        stream.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static HttpURLConnection createConnection() throws Exception {
 | 
			
		||||
        URL url = new URL(PROFILE_URL);
 | 
			
		||||
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 | 
			
		||||
        connection.setRequestMethod("POST");
 | 
			
		||||
        connection.setRequestProperty("Content-Type", "application/json");
 | 
			
		||||
        connection.setUseCaches(false);
 | 
			
		||||
        connection.setDoInput(true);
 | 
			
		||||
        connection.setDoOutput(true);
 | 
			
		||||
        return connection;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static UUID getUUID(String id) {
 | 
			
		||||
        return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" +id.substring(20, 32));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static byte[] toBytes(UUID uuid) {
 | 
			
		||||
        ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
 | 
			
		||||
        byteBuffer.putLong(uuid.getMostSignificantBits());
 | 
			
		||||
        byteBuffer.putLong(uuid.getLeastSignificantBits());
 | 
			
		||||
        return byteBuffer.array();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static UUID fromBytes(byte[] array) {
 | 
			
		||||
        if (array.length != 16) {
 | 
			
		||||
            throw new IllegalArgumentException("Illegal byte array length: " + array.length);
 | 
			
		||||
        }
 | 
			
		||||
        ByteBuffer byteBuffer = ByteBuffer.wrap(array);
 | 
			
		||||
        long mostSignificant = byteBuffer.getLong();
 | 
			
		||||
        long leastSignificant = byteBuffer.getLong();
 | 
			
		||||
        return new UUID(mostSignificant, leastSignificant);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static UUID getUUIDOf(String name) throws Exception {
 | 
			
		||||
        return new UUIDFetcher(Arrays.asList(name)).call().get(name);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										62
									
								
								src/main/java/com/lishid/openinv/utils/UUIDUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								src/main/java/com/lishid/openinv/utils/UUIDUtil.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
package com.lishid.openinv.utils;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.Validate;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
public class UUIDUtil {
 | 
			
		||||
    private static Player getPlayer(String name) {
 | 
			
		||||
        Validate.notNull(name, "Name cannot be null");
 | 
			
		||||
 | 
			
		||||
        Player found = null;
 | 
			
		||||
        String lowerName = name.toLowerCase();
 | 
			
		||||
        int delta = Integer.MAX_VALUE;
 | 
			
		||||
 | 
			
		||||
        Collection<? extends Player> players = Bukkit.getOnlinePlayers();
 | 
			
		||||
        for (Player player : players) {
 | 
			
		||||
            if (player.getName().toLowerCase().startsWith(lowerName)) {
 | 
			
		||||
                int curDelta = player.getName().length() - lowerName.length();
 | 
			
		||||
                if (curDelta < delta) {
 | 
			
		||||
                    found = player;
 | 
			
		||||
                    delta = curDelta;
 | 
			
		||||
                }
 | 
			
		||||
                if (curDelta == 0) break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return found;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings("deprecation")
 | 
			
		||||
    private static UUID getUUIDLocally(String name) {
 | 
			
		||||
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
 | 
			
		||||
        return offlinePlayer.hasPlayedBefore() ? offlinePlayer.getUniqueId() : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static UUID getUUIDOf(String name) {
 | 
			
		||||
        Player player = getPlayer(name);
 | 
			
		||||
 | 
			
		||||
        if (player != null) {
 | 
			
		||||
            return player.getUniqueId();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (Bukkit.getServer().getOnlineMode() && !Bukkit.getServer().isPrimaryThread()) {
 | 
			
		||||
            UUIDFetcher fetcher = new UUIDFetcher(Arrays.asList(name));
 | 
			
		||||
            try {
 | 
			
		||||
                Map<String, UUID> response = fetcher.call();
 | 
			
		||||
                return response.get(name.toLowerCase());
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ignored) {
 | 
			
		||||
                //Fallthrough to end of method
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return getUUIDLocally(name);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/main/resources/config.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
config-version: 2
 | 
			
		||||
notify:
 | 
			
		||||
  any-chest: true
 | 
			
		||||
  silent-chest: true
 | 
			
		||||
items:
 | 
			
		||||
  open-inv: STICK
 | 
			
		||||
							
								
								
									
										44
									
								
								src/main/resources/plugin.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/main/resources/plugin.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
name: OpenInv
 | 
			
		||||
main: com.lishid.openinv.OpenInv
 | 
			
		||||
version: 2.3.1
 | 
			
		||||
author: lishid
 | 
			
		||||
description: >
 | 
			
		||||
             This plugin allows you to open a player's inventory as a chest and interact with it in real time.
 | 
			
		||||
commands:
 | 
			
		||||
  openinv:
 | 
			
		||||
    aliases: [oi, inv, open]
 | 
			
		||||
    description: Opens a player's inventory.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> - Opens last person's inventory.
 | 
			
		||||
           /<command> <player> - Opens a player's inventory.
 | 
			
		||||
  openender:
 | 
			
		||||
    aliases: [oe]
 | 
			
		||||
    description: Opens a player's ender chest.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> - Opens last person's ender chest.
 | 
			
		||||
           /<command> <player> - Opens a player's ender chest.
 | 
			
		||||
  searchinv:
 | 
			
		||||
    aliases: [si]
 | 
			
		||||
    description: Searches and lists players that have a specific item in their inventory.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> <item> [minAmount] - Item can be the Item ID or the CraftBukkit Item Name, minAmount is the minimum amount to be considered.
 | 
			
		||||
  searchender:
 | 
			
		||||
    aliases: [se]
 | 
			
		||||
    description: Searches and lists players that have a specific item in their ender chest.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> <item> [minAmount] - Item can be the Item ID or the CraftBukkit Item Name, minAmount is the minimum amount to be considered.
 | 
			
		||||
  toggleopeninv:
 | 
			
		||||
    aliases: [toi, toggleoi, toggleinv]
 | 
			
		||||
    description: Toggles the item openinv function.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> [check] - Checks whether item openinv is enabled.
 | 
			
		||||
  anychest:
 | 
			
		||||
    aliases: [ac]
 | 
			
		||||
    description: Toggles the any chest function, which allows opening of blocked chests.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> [check] - Checks whether any chest is enabled.
 | 
			
		||||
  silentchest:
 | 
			
		||||
    aliases: [sc, silent]
 | 
			
		||||
    description: Toggles the silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound.
 | 
			
		||||
    usage: |
 | 
			
		||||
           /<command> [check] - Checks whether silent chest is enabled.
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_10_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_10_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.spigotmc</groupId>
 | 
			
		||||
      <artifactId>spigot</artifactId>
 | 
			
		||||
      <version>1.10-R0.1-SNAPSHOT</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,206 +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_10_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.Block;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.BlockChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.BlockChest.Type;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.BlockEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.BlockPosition;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.Entity;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.EnumDirection;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.ITileInventory;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.StatisticList;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.TileEntity;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.TileEntityEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
			
		||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
			
		||||
        Block block = world.getType(blockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.getType(blockPosition.up()).m();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check if chest is blocked or has an ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, blockPosition)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check for matching adjacent chests that are blocked or have an ocelot on top
 | 
			
		||||
        for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
			
		||||
            BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
			
		||||
            Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
            if (localBlock != block) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
			
		||||
            if (!(localTileEntity instanceof TileEntityChest)) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (isBlockedChest(world, localBlockPosition)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, BlockPosition blockPosition) {
 | 
			
		||||
        // For reference, loot at net.minecraft.server.BlockChest
 | 
			
		||||
        return world.getType(blockPosition.up()).l() || hasOcelotOnTop(world, blockPosition);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
 | 
			
		||||
        for (Entity localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
 | 
			
		||||
                        blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
 | 
			
		||||
                        blockPosition.getZ() + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
 | 
			
		||||
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
 | 
			
		||||
        // Silent ender chest is pretty much API-only
 | 
			
		||||
        if (silentchest && b.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            p.openInventory(p.getEnderChest());
 | 
			
		||||
            player.b(StatisticList.X);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
			
		||||
        Object tile = world.getTileEntity(blockPosition);
 | 
			
		||||
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tile instanceof TileEntityEnderChest) {
 | 
			
		||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
			
		||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
			
		||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
			
		||||
            player.openContainer(enderChest);
 | 
			
		||||
            player.b(StatisticList.X);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof IInventory)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Block block = world.getType(blockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockChest) {
 | 
			
		||||
            for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
			
		||||
                BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
			
		||||
                Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
                if (localBlock != block) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
			
		||||
                if (!(localTileEntity instanceof TileEntityChest)) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) {
 | 
			
		||||
                    tile = new InventoryLargeChest("container.chestDouble",
 | 
			
		||||
                            (TileEntityChest) localTileEntity, (ITileInventory) tile);
 | 
			
		||||
                } else {
 | 
			
		||||
                    tile = new InventoryLargeChest("container.chestDouble",
 | 
			
		||||
                            (ITileInventory) tile, (TileEntityChest) localTileEntity);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (silentchest) {
 | 
			
		||||
                tile = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (((BlockChest) block).g == Type.BASIC)
 | 
			
		||||
                player.b(StatisticList.ac);
 | 
			
		||||
            else if (((BlockChest) block).g == Type.TRAP) {
 | 
			
		||||
                player.b(StatisticList.W);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) tile);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            try {
 | 
			
		||||
                SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
 | 
			
		||||
                int windowId = player.nextContainerCounter();
 | 
			
		||||
                player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) tile).getScoreboardDisplayName(), ((IInventory) tile).getSize()));
 | 
			
		||||
                player.activeContainer = silentContainerChest;
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +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_10_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_10_R1.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            return (SpecialPlayerInventory) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            return (SpecialEnderChest) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,64 +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_10_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
 | 
			
		||||
import com.mojang.authlib.GameProfile;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_10_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.MinecraftServer;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Create a profile and entity to load the player data
 | 
			
		||||
        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
        return player.getUniqueId().toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,46 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_10_R1;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_10_R1.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) {
 | 
			
		||||
        super(i1, i2, e1);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.closeContainer(e1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried, false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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_10_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.lang.reflect.Modifier;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_10_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.InventorySubcontainer;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.ItemStack;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
 | 
			
		||||
                ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
 | 
			
		||||
                ((CraftPlayer) player).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer craftPlayer = (CraftPlayer) player;
 | 
			
		||||
        this.enderChest = craftPlayer.getHandle().getEnderChest();
 | 
			
		||||
        this.bukkitOwner = craftPlayer;
 | 
			
		||||
        setItemArrays(this, enderChest.getContents());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setItemArrays(InventorySubcontainer subcontainer, ItemStack[] items) {
 | 
			
		||||
        try {
 | 
			
		||||
            // Prepare to remove final modifier
 | 
			
		||||
            Field modifiers = Field.class.getDeclaredField("modifiers");
 | 
			
		||||
            modifiers.setAccessible(true);
 | 
			
		||||
            // Access and replace main inventory array
 | 
			
		||||
            Field field = InventorySubcontainer.class.getField("items");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(subcontainer, items);
 | 
			
		||||
        } catch (NoSuchFieldException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (SecurityException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalAccessException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                this.bukkitOwner = player;
 | 
			
		||||
                CraftPlayer craftPlayer = (CraftPlayer) player;
 | 
			
		||||
                setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,296 +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_10_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.lang.reflect.Modifier;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_10_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[4];
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setItemArrays(PlayerInventory inventory, ItemStack[] items, ItemStack[] armor,
 | 
			
		||||
            ItemStack[] extraSlots) {
 | 
			
		||||
        try {
 | 
			
		||||
            // Prepare to remove final modifier
 | 
			
		||||
            Field modifiers = Field.class.getDeclaredField("modifiers");
 | 
			
		||||
            modifiers.setAccessible(true);
 | 
			
		||||
 | 
			
		||||
            // Access and replace main inventory array
 | 
			
		||||
            Field field = PlayerInventory.class.getField("items");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, items);
 | 
			
		||||
 | 
			
		||||
            // Access and replace armor inventory array
 | 
			
		||||
            field = PlayerInventory.class.getField("armor");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, armor);
 | 
			
		||||
 | 
			
		||||
            // Access and replace offhand inventory array
 | 
			
		||||
            field = PlayerInventory.class.getField("extraSlots");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, extraSlots);
 | 
			
		||||
 | 
			
		||||
            // Access and replace array containing all inventory arrays
 | 
			
		||||
            field = PlayerInventory.class.getDeclaredField("g");
 | 
			
		||||
            field.setAccessible(true);
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, new ItemStack[][] { items, armor, extraSlots });
 | 
			
		||||
        } catch (NoSuchFieldException e) {
 | 
			
		||||
            // Unable to set final fields to item arrays, we're screwed. Noisily fail.
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalAccessException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            setItemArrays(this.player.inventory, items, armor, extraSlots);
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        ItemStack[] contents = new ItemStack[getSize()];
 | 
			
		||||
        System.arraycopy(items, 0, contents, 0, items.length);
 | 
			
		||||
        System.arraycopy(armor, 0, contents, items.length, armor.length);
 | 
			
		||||
        System.arraycopy(extraSlots, 0, contents, items.length + armor.length, extraSlots.length);
 | 
			
		||||
        return contents;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getSize() {
 | 
			
		||||
        return super.getSize() + 4;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // extraSlots is, for now, just an array with length 1. No need for special handling.
 | 
			
		||||
 | 
			
		||||
        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.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (is[i] != null) {
 | 
			
		||||
            ItemStack itemstack;
 | 
			
		||||
 | 
			
		||||
            if (is[i].count <= j) {
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
                itemstack = is[i].cloneAndSubtract(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (is[i] != null) {
 | 
			
		||||
            ItemStack itemstack = is[i];
 | 
			
		||||
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Effects
 | 
			
		||||
        if (is == this.extra) {
 | 
			
		||||
            player.drop(itemstack, true);
 | 
			
		||||
            itemstack = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        is[i] = itemstack;
 | 
			
		||||
 | 
			
		||||
        player.defaultContainer.b();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        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,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_11_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.spigotmc</groupId>
 | 
			
		||||
      <artifactId>spigot</artifactId>
 | 
			
		||||
      <version>1.11-R0.1-SNAPSHOT</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,276 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.Block;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.BlockChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.BlockChest.Type;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.BlockEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.BlockPosition;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.Container;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.Entity;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.EnumDirection;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.IBlockData;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ITileInventory;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.StatisticList;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.TileEntity;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.TileEntityEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
			
		||||
        if (block.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        BlockState state = block.getState();
 | 
			
		||||
        return state instanceof org.bukkit.block.Chest || state instanceof org.bukkit.block.ShulkerBox;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
			
		||||
        Block block = world.getType(blockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockShulkerBox) {
 | 
			
		||||
            return isBlockedShulkerBox(world, blockPosition, block);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.getType(blockPosition.up()).m();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check if chest is blocked or has an ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, blockPosition)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check for matching adjacent chests that are blocked or have an ocelot on top
 | 
			
		||||
        for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
			
		||||
            BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
			
		||||
            Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
            if (localBlock != block) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
			
		||||
            if (!(localTileEntity instanceof TileEntityChest)) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (isBlockedChest(world, localBlockPosition)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedShulkerBox(World world, BlockPosition blockPosition, Block block) {
 | 
			
		||||
        // For reference, look at net.minecraft.server.BlockShulkerBox
 | 
			
		||||
        TileEntity tile = world.getTileEntity(blockPosition);
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof TileEntityShulkerBox)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        IBlockData iBlockData = block.getBlockData();
 | 
			
		||||
 | 
			
		||||
        EnumDirection enumDirection = iBlockData.get(BlockShulkerBox.a);
 | 
			
		||||
        if (((TileEntityShulkerBox) tile).p() == TileEntityShulkerBox.AnimationPhase.CLOSED) {
 | 
			
		||||
            AxisAlignedBB axisAlignedBB = BlockShulkerBox.j.b(0.5F * enumDirection.getAdjacentX(),
 | 
			
		||||
                    0.5F * enumDirection.getAdjacentY(), 0.5F * enumDirection.getAdjacentZ())
 | 
			
		||||
                    .a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
 | 
			
		||||
                            enumDirection.getAdjacentZ());
 | 
			
		||||
 | 
			
		||||
            return world.b(axisAlignedBB.a(blockPosition.shift(enumDirection)));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, BlockPosition blockPosition) {
 | 
			
		||||
        // For reference, loot at net.minecraft.server.BlockChest
 | 
			
		||||
        return world.getType(blockPosition.up()).m() || hasOcelotOnTop(world, blockPosition);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
 | 
			
		||||
        for (Entity localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
 | 
			
		||||
                        blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
 | 
			
		||||
                        blockPosition.getZ() + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block b) {
 | 
			
		||||
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
 | 
			
		||||
        // Silent ender chest is pretty much API-only
 | 
			
		||||
        if (silentchest && b.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            p.openInventory(p.getEnderChest());
 | 
			
		||||
            player.b(StatisticList.X);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        final World world = player.world;
 | 
			
		||||
        final BlockPosition blockPosition = new BlockPosition(b.getX(), b.getY(), b.getZ());
 | 
			
		||||
        Object tile = world.getTileEntity(blockPosition);
 | 
			
		||||
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tile instanceof TileEntityEnderChest) {
 | 
			
		||||
            // Anychest ender chest.  See net.minecraft.server.BlockEnderChest
 | 
			
		||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
			
		||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
			
		||||
            player.openContainer(enderChest);
 | 
			
		||||
            player.b(StatisticList.X);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof IInventory)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Block block = world.getType(blockPosition).getBlock();
 | 
			
		||||
        Container container = null;
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockChest) {
 | 
			
		||||
            BlockChest blockChest = (BlockChest) block;
 | 
			
		||||
 | 
			
		||||
            for (EnumDirection localEnumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
			
		||||
                BlockPosition localBlockPosition = blockPosition.shift(localEnumDirection);
 | 
			
		||||
                Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
                if (localBlock != block) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
			
		||||
                if (!(localTileEntity instanceof TileEntityChest)) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if ((localEnumDirection == EnumDirection.WEST) || (localEnumDirection == EnumDirection.NORTH)) {
 | 
			
		||||
                    tile = new InventoryLargeChest("container.chestDouble",
 | 
			
		||||
                            (TileEntityChest) localTileEntity, (ITileInventory) tile);
 | 
			
		||||
                } else {
 | 
			
		||||
                    tile = new InventoryLargeChest("container.chestDouble",
 | 
			
		||||
                            (ITileInventory) tile, (TileEntityChest) localTileEntity);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (blockChest.g == Type.BASIC)
 | 
			
		||||
                player.b(StatisticList.ac);
 | 
			
		||||
            else if (blockChest.g == Type.TRAP) {
 | 
			
		||||
                player.b(StatisticList.W);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (silentchest) {
 | 
			
		||||
                container = new SilentContainerChest(player.inventory, ((IInventory) tile), player);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockShulkerBox) {
 | 
			
		||||
            player.b(StatisticList.ae);
 | 
			
		||||
 | 
			
		||||
            if (silentchest && tile instanceof TileEntityShulkerBox) {
 | 
			
		||||
                // Set value to current + 1. Ensures consistency later when resetting.
 | 
			
		||||
                SilentContainerShulkerBox.setOpenValue((TileEntityShulkerBox) tile,
 | 
			
		||||
                        SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) + 1);
 | 
			
		||||
 | 
			
		||||
                container = new SilentContainerShulkerBox(player.inventory, (IInventory) tile, player);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        final IInventory iInventory = (IInventory) tile;
 | 
			
		||||
 | 
			
		||||
        if (!silentchest || container == null) {
 | 
			
		||||
            player.openContainer(iInventory);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            try {
 | 
			
		||||
                int windowId = player.nextContainerCounter();
 | 
			
		||||
                player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, iInventory.getName(), iInventory.getScoreboardDisplayName(), iInventory.getSize()));
 | 
			
		||||
                player.activeContainer = container;
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
                if (tile instanceof TileEntityShulkerBox) {
 | 
			
		||||
                    new BukkitRunnable() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public void run() {
 | 
			
		||||
                            // TODO hacky
 | 
			
		||||
                            Object tile = world.getTileEntity(blockPosition);
 | 
			
		||||
                            if (!(tile instanceof TileEntityShulkerBox)) {
 | 
			
		||||
                                return;
 | 
			
		||||
                            }
 | 
			
		||||
                            TileEntityShulkerBox box = (TileEntityShulkerBox) tile;
 | 
			
		||||
                            // Reset back - we added 1, and calling TileEntityShulkerBox#startOpen adds 1 more.
 | 
			
		||||
                            SilentContainerShulkerBox.setOpenValue(box,
 | 
			
		||||
                                    SilentContainerShulkerBox.getOpenValue((TileEntityShulkerBox) tile) - 2);
 | 
			
		||||
                        }
 | 
			
		||||
                    }.runTaskLater(Bukkit.getPluginManager().getPlugin("OpenInv"), 2);
 | 
			
		||||
                }
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_11_R1.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            return (SpecialPlayerInventory) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            return (SpecialEnderChest) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,64 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
 | 
			
		||||
import com.mojang.authlib.GameProfile;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.MinecraftServer;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.PlayerInteractManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_11_R1.CraftServer;
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Create a profile and entity to load the player data
 | 
			
		||||
        GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName());
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
        return player.getUniqueId().toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,47 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
 | 
			
		||||
            EntityHuman entityHuman) {
 | 
			
		||||
        super(playerInventory, iInventory, entityHuman);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        iInventory.closeContainer(entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != ItemStack.a) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            playerinventory.setCarried(ItemStack.a);
 | 
			
		||||
            entityHuman.drop(carried, false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,56 +0,0 @@
 | 
			
		||||
package com.lishid.openinv.internal.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ContainerShulkerBox;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerShulkerBox extends ContainerShulkerBox {
 | 
			
		||||
 | 
			
		||||
    private static Field fieldShulkerActionData;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
 | 
			
		||||
            EntityHuman entityHuman) {
 | 
			
		||||
        super(playerInventory, iInventory, entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (!playerinventory.getCarried().isEmpty()) {
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried(), false);
 | 
			
		||||
            playerinventory.setCarried(ItemStack.a);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
 | 
			
		||||
        if (fieldShulkerActionData == null) {
 | 
			
		||||
            fieldShulkerActionData = TileEntityShulkerBox.class.getDeclaredField("h");
 | 
			
		||||
            fieldShulkerActionData.setAccessible(true);
 | 
			
		||||
        }
 | 
			
		||||
        return fieldShulkerActionData;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setOpenValue(TileEntityShulkerBox tileShulkerBox, Object value) {
 | 
			
		||||
        try {
 | 
			
		||||
            exposeOpenStatus().set(tileShulkerBox, value);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Integer getOpenValue(TileEntityShulkerBox tileShulkerBox) {
 | 
			
		||||
        try {
 | 
			
		||||
            return (Integer) exposeOpenStatus().get(tileShulkerBox);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,106 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.lang.reflect.Modifier;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_11_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.InventorySubcontainer;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ItemStack;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player player, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) player).getHandle().getEnderChest().getName(),
 | 
			
		||||
                ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(),
 | 
			
		||||
                ((CraftPlayer) player).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer craftPlayer = (CraftPlayer) player;
 | 
			
		||||
        this.enderChest = craftPlayer.getHandle().getEnderChest();
 | 
			
		||||
        this.bukkitOwner = craftPlayer;
 | 
			
		||||
        setItemLists(this, enderChest.getContents());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setItemLists(InventorySubcontainer subcontainer, List<ItemStack> list) {
 | 
			
		||||
        try {
 | 
			
		||||
            // Prepare to remove final modifier
 | 
			
		||||
            Field modifiers = Field.class.getDeclaredField("modifiers");
 | 
			
		||||
            modifiers.setAccessible(true);
 | 
			
		||||
            // Access and replace main inventory array
 | 
			
		||||
            Field field = InventorySubcontainer.class.getField("items");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(subcontainer, list);
 | 
			
		||||
        } catch (NoSuchFieldException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (SecurityException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalAccessException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                this.bukkitOwner = player;
 | 
			
		||||
                CraftPlayer craftPlayer = (CraftPlayer) player;
 | 
			
		||||
                setItemLists(craftPlayer.getHandle().getEnderChest(), this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,261 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.lang.reflect.Modifier;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ContainerUtil;
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_11_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.NonNullList;
 | 
			
		||||
import net.minecraft.server.v1_11_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setItemArrays(PlayerInventory inventory, NonNullList<ItemStack> items,
 | 
			
		||||
            NonNullList<ItemStack> armor, NonNullList<ItemStack> extraSlots) {
 | 
			
		||||
        try {
 | 
			
		||||
            // Prepare to remove final modifier
 | 
			
		||||
            Field modifiers = Field.class.getDeclaredField("modifiers");
 | 
			
		||||
            modifiers.setAccessible(true);
 | 
			
		||||
 | 
			
		||||
            // Access and replace main inventory array
 | 
			
		||||
            Field field = PlayerInventory.class.getField("items");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, items);
 | 
			
		||||
 | 
			
		||||
            // Access and replace armor inventory array
 | 
			
		||||
            field = PlayerInventory.class.getField("armor");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, armor);
 | 
			
		||||
 | 
			
		||||
            // Access and replace offhand inventory array
 | 
			
		||||
            field = PlayerInventory.class.getField("extraSlots");
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, extraSlots);
 | 
			
		||||
 | 
			
		||||
            // Access and replace array containing all inventory arrays
 | 
			
		||||
            field = PlayerInventory.class.getDeclaredField("g");
 | 
			
		||||
            field.setAccessible(true);
 | 
			
		||||
            modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
 | 
			
		||||
            field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots }));
 | 
			
		||||
        } catch (NoSuchFieldException e) {
 | 
			
		||||
            // Unable to set final fields to item arrays, we're screwed. Noisily fail.
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalArgumentException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        } catch (IllegalAccessException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            setItemArrays(this.player.inventory, items, armor, extraSlots);
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getSize() {
 | 
			
		||||
        return super.getSize() + 4;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack getItem(int i) {
 | 
			
		||||
        NonNullList<ItemStack> list = this.items;
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.extraSlots;
 | 
			
		||||
        } else if (list == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            return ItemStack.a;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return list.get(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitStack(int i, int j) {
 | 
			
		||||
        NonNullList<ItemStack> list = this.items;
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.extraSlots;
 | 
			
		||||
        } else if (list == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            return ItemStack.a;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return list == null || list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
        NonNullList<ItemStack> list = this.items;
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.extraSlots;
 | 
			
		||||
        } else if (list == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            return ItemStack.a;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (list != null && !list.get(i).isEmpty()) {
 | 
			
		||||
            ItemStack itemstack = list.get(i);
 | 
			
		||||
 | 
			
		||||
            list.set(i, ItemStack.a);
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ItemStack.a;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
        NonNullList<ItemStack> list = this.items;
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            i -= list.size();
 | 
			
		||||
            list = this.extraSlots;
 | 
			
		||||
        } else if (list == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= list.size()) {
 | 
			
		||||
            player.drop(itemstack, true);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (list != null) {
 | 
			
		||||
            list.set(i, itemstack);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        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,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_4_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_4_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>craftbukkit</artifactId>
 | 
			
		||||
      <version>1.4.7-R1.0</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,168 +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 com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.BlockEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.TileEntityEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
			
		||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
			
		||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, int x, int y, int z) {
 | 
			
		||||
        for (Object localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
			
		||||
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
 | 
			
		||||
        // Silent ender chest is API-only
 | 
			
		||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            p.openInventory(p.getEnderChest());
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tile instanceof TileEntityEnderChest) {
 | 
			
		||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
			
		||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
			
		||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
			
		||||
            player.openContainer(enderChest);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof IInventory)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
			
		||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) tile);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } 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) tile).getName(), ((IInventory) tile).getSize()));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +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 com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_R1.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            return (SpecialPlayerInventory) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            return (SpecialEnderChest) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,63 +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 com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.server.v1_4_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.MinecraftServer;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.PlayerInteractManager;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.CraftServer;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure the player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,46 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_4_R1;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_R1.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.f();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,128 +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.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.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.InventorySubcontainer;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.ItemStack;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftHumanEntity;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
 | 
			
		||||
    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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                owner = (CraftPlayer) player;
 | 
			
		||||
                InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onOpen(CraftHumanEntity who) {
 | 
			
		||||
        transaction.add(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        transaction.remove(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return transaction;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return this.owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setMaxStackSize(int size) {
 | 
			
		||||
        maxStack = size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return maxStack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,237 +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 com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        this.items = player.inventory.items;
 | 
			
		||||
        this.armor = player.inventory.armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            this.player.inventory.items = this.items;
 | 
			
		||||
            this.player.inventory.armor = this.armor;
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        ItemStack[] contents = new ItemStack[getSize()];
 | 
			
		||||
        System.arraycopy(items, 0, contents, 0, items.length);
 | 
			
		||||
        System.arraycopy(armor, 0, contents, items.length, armor.length);
 | 
			
		||||
        return contents;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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) {
 | 
			
		||||
            player.drop(itemstack);
 | 
			
		||||
            itemstack = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        is[i] = itemstack;
 | 
			
		||||
 | 
			
		||||
        player.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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_5_R2</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_5_R2</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>craftbukkit</artifactId>
 | 
			
		||||
      <version>1.5.1-R0.2</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,168 +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 com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.BlockEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.TileEntityEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
			
		||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
			
		||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, int x, int y, int z) {
 | 
			
		||||
        for (Object localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
			
		||||
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
 | 
			
		||||
        // Silent ender chest is API-only
 | 
			
		||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            p.openInventory(p.getEnderChest());
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tile instanceof TileEntityEnderChest) {
 | 
			
		||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
			
		||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
			
		||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
			
		||||
            player.openContainer(enderChest);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof IInventory)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
			
		||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) tile);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } 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) tile).getName(), ((IInventory) tile).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +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 com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R2.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            return (SpecialPlayerInventory) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            return (SpecialEnderChest) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,62 +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 com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R2.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.MinecraftServer;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.PlayerInteractManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.CraftServer;
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure the player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,46 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_5_R2;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R2.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,129 +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.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.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.InventorySubcontainer;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.ItemStack;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftHumanEntity;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
 | 
			
		||||
    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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                owner = (CraftPlayer) player;
 | 
			
		||||
                InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onOpen(CraftHumanEntity who) {
 | 
			
		||||
        transaction.add(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        transaction.remove(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return transaction;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return this.owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setMaxStackSize(int size) {
 | 
			
		||||
        maxStack = size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return maxStack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,229 +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 com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R2.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R2.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        this.items = player.inventory.items;
 | 
			
		||||
        this.armor = player.inventory.armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            this.player.inventory.items = this.items;
 | 
			
		||||
            this.player.inventory.armor = this.armor;
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        ItemStack[] contents = new ItemStack[getSize()];
 | 
			
		||||
        System.arraycopy(items, 0, contents, 0, items.length);
 | 
			
		||||
        System.arraycopy(armor, 0, contents, items.length, armor.length);
 | 
			
		||||
        return contents;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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) {
 | 
			
		||||
            player.drop(itemstack);
 | 
			
		||||
            itemstack = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        is[i] = itemstack;
 | 
			
		||||
 | 
			
		||||
        player.defaultContainer.b();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        if (player.getName().length() > 16) {
 | 
			
		||||
            return player.getName().substring(0, 16);
 | 
			
		||||
        }
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_5_R3</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_5_R3</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>craftbukkit</artifactId>
 | 
			
		||||
      <version>1.5.2-R1.0</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -1,168 +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 com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
//Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R3.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.BlockEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.TileEntityEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.Block block) {
 | 
			
		||||
        return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block block) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.t(block.getX(), block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ())) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() + 1);
 | 
			
		||||
        } else if(world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX(), block.getY() + 1, block.getZ() - 1);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() + 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            return isBlockedChest(world, block.getX() - 1, block.getY() + 1, block.getZ());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        return world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, int x, int y, int z) {
 | 
			
		||||
        for (Object localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                AxisAlignedBB.a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean silentchest, org.bukkit.block.Block block) {
 | 
			
		||||
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
 | 
			
		||||
        // Silent ender chest is API-only
 | 
			
		||||
        if (silentchest && block.getType() == Material.ENDER_CHEST) {
 | 
			
		||||
            p.openInventory(p.getEnderChest());
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object tile = world.getTileEntity(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (tile instanceof TileEntityEnderChest) {
 | 
			
		||||
            // Anychest ender chest. See net.minecraft.server.BlockEnderChest
 | 
			
		||||
            InventoryEnderChest enderChest = player.getEnderChest();
 | 
			
		||||
            enderChest.a((TileEntityEnderChest) tile);
 | 
			
		||||
            player.openContainer(enderChest);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!(tile instanceof IInventory)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(block.getX(), block.getY(), block.getZ());
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(block.getX(), block.getY(), block.getZ() + 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() + 1));
 | 
			
		||||
        } else if (world.getTypeId(block.getX(), block.getY(), block.getZ() - 1) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX(), block.getY(), block.getZ() - 1), (IInventory) tile);
 | 
			
		||||
        } else if (world.getTypeId(block.getX() + 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (IInventory) tile, (TileEntityChest) world.getTileEntity(block.getX() + 1, block.getY(), block.getZ()));
 | 
			
		||||
        } else if (world.getTypeId(block.getX() - 1, block.getY(), block.getZ()) == id) {
 | 
			
		||||
            tile = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(block.getX() - 1, block.getY(), block.getZ()), (IInventory) tile);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) tile);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } 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) tile).getName(), ((IInventory) tile).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) tile));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,79 +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 com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialEnderChest;
 | 
			
		||||
import com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
import com.lishid.openinv.internal.InternalAccessor;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R3.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialPlayerInventory;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialPlayerInventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialPlayerInventory getSpecialPlayerInventory(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            return (SpecialPlayerInventory) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            return ((CraftInventory) inventory).getInventory() instanceof ISpecialEnderChest;
 | 
			
		||||
        }
 | 
			
		||||
        return InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory) instanceof ISpecialEnderChest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ISpecialEnderChest getSpecialEnderChest(Inventory inventory) {
 | 
			
		||||
        IInventory inv;
 | 
			
		||||
        if (inventory instanceof CraftInventory) {
 | 
			
		||||
            inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
        } else {
 | 
			
		||||
            inv = InternalAccessor.grabFieldOfTypeFromObject(IInventory.class, inventory);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            return (SpecialEnderChest) inv;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,62 +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 com.lishid.openinv.internal.IPlayerDataManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.OfflinePlayer;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R3.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.MinecraftServer;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.PlayerInteractManager;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.CraftServer;
 | 
			
		||||
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure the player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), offline.getName(),
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,46 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_5_R3;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R3.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void b(EntityHuman entityHuman) {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,129 +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.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.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.InventoryEnderChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.InventorySubcontainer;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.ItemStack;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftHumanEntity;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
 | 
			
		||||
    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();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            try {
 | 
			
		||||
                owner = (CraftPlayer) player;
 | 
			
		||||
                InventoryEnderChest playerEnderChest = owner.getHandle().getEnderChest();
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        return this.items;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onOpen(CraftHumanEntity who) {
 | 
			
		||||
        transaction.add(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onClose(CraftHumanEntity who) {
 | 
			
		||||
        transaction.remove(who);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<HumanEntity> getViewers() {
 | 
			
		||||
        return transaction;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public InventoryHolder getOwner() {
 | 
			
		||||
        return this.owner;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setMaxStackSize(int size) {
 | 
			
		||||
        maxStack = size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getMaxStackSize() {
 | 
			
		||||
        return maxStack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update() {
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,229 +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 com.lishid.openinv.internal.ISpecialPlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R3.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
 | 
			
		||||
import org.bukkit.craftbukkit.v1_5_R3.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
 | 
			
		||||
 | 
			
		||||
    private final ItemStack[] extra = new ItemStack[5];
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
 | 
			
		||||
    public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) bukkitPlayer).getHandle());
 | 
			
		||||
        this.playerOnline = online;
 | 
			
		||||
        this.items = player.inventory.items;
 | 
			
		||||
        this.armor = player.inventory.armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Inventory getBukkitInventory() {
 | 
			
		||||
        return inventory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOnline(Player player) {
 | 
			
		||||
        if (!playerOnline) {
 | 
			
		||||
            this.player = ((CraftPlayer) player).getHandle();
 | 
			
		||||
            this.player.inventory.items = this.items;
 | 
			
		||||
            this.player.inventory.armor = this.armor;
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setPlayerOffline() {
 | 
			
		||||
        playerOnline = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isInUse() {
 | 
			
		||||
        return !this.getViewers().isEmpty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack[] getContents() {
 | 
			
		||||
        ItemStack[] contents = new ItemStack[getSize()];
 | 
			
		||||
        System.arraycopy(items, 0, contents, 0, items.length);
 | 
			
		||||
        System.arraycopy(armor, 0, contents, items.length, armor.length);
 | 
			
		||||
        return contents;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    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;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        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) {
 | 
			
		||||
            player.drop(itemstack);
 | 
			
		||||
            itemstack = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        is[i] = itemstack;
 | 
			
		||||
 | 
			
		||||
        player.defaultContainer.b();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        if (player.getName().length() > 16) {
 | 
			
		||||
            return player.getName().substring(0, 16);
 | 
			
		||||
        }
 | 
			
		||||
        return player.getName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,28 +0,0 @@
 | 
			
		||||
<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>
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_6_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_6_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>org.bukkit</groupId>
 | 
			
		||||
      <artifactId>craftbukkit</artifactId>
 | 
			
		||||
      <version>1.6.1-R0.1-SNAPSHOT</version>
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user