Compare commits
	
		
			36 Commits
		
	
	
		
			3.0.0
			...
			2.5.3-alph
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					476171911a | ||
| 
						 | 
					9501d1c571 | ||
| 
						 | 
					ff683d65d1 | ||
| 
						 | 
					c3f517d7ab | ||
| 
						 | 
					2e41b4bd45 | ||
| 
						 | 
					e100dff6ab | ||
| 
						 | 
					835e3151eb | ||
| 
						 | 
					3312ed9ff6 | ||
| 
						 | 
					23bda96f38 | ||
| 
						 | 
					1bbdde683c | ||
| 
						 | 
					9edac80544 | ||
| 
						 | 
					53eadcb821 | ||
| 
						 | 
					326ffdb433 | ||
| 
						 | 
					fc5f9587d1 | ||
| 
						 | 
					a929eeeb69 | ||
| 
						 | 
					7256494df3 | ||
| 
						 | 
					1fbaa5b2a9 | ||
| 
						 | 
					eeb28b4210 | ||
| 
						 | 
					0ebe6fe132 | ||
| 
						 | 
					e39ab10797 | ||
| 
						 | 
					fb48f6a783 | ||
| 
						 | 
					d761b6bfe4 | ||
| 
						 | 
					5b3ba79b82 | ||
| 
						 | 
					3549431fbc | ||
| 
						 | 
					17b0cb6efe | ||
| 
						 | 
					2d7522554c | ||
| 
						 | 
					131f874329 | ||
| 
						 | 
					a623af5119 | ||
| 
						 | 
					8f17bd0237 | ||
| 
						 | 
					20fb61705d | ||
| 
						 | 
					c0f513177a | ||
| 
						 | 
					b3a3947b03 | ||
| 
						 | 
					c7bab7d451 | ||
| 
						 | 
					4058463f7f | ||
| 
						 | 
					21cd1926ae | ||
| 
						 | 
					2a66b2e81b | 
							
								
								
									
										10
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										10
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,10 +0,0 @@
 | 
			
		||||
**/.settings
 | 
			
		||||
**/.gitignore
 | 
			
		||||
**/.project
 | 
			
		||||
**/.classpath
 | 
			
		||||
**/.idea
 | 
			
		||||
**/target
 | 
			
		||||
**/bin
 | 
			
		||||
**/lib
 | 
			
		||||
**/out
 | 
			
		||||
**dependency-reduced-pom.xml
 | 
			
		||||
@@ -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,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,15 +1,15 @@
 | 
			
		||||
<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">
 | 
			
		||||
<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>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvassembly</artifactId>
 | 
			
		||||
  <name>OpenInvAssembly</name>
 | 
			
		||||
  <artifactId>openinv</artifactId>
 | 
			
		||||
  <name>OpenInv</name>
 | 
			
		||||
  <version>2.5.3-SNAPSHOT</version>
 | 
			
		||||
 | 
			
		||||
  <profiles>
 | 
			
		||||
 | 
			
		||||
@@ -18,7 +18,7 @@
 | 
			
		||||
      <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_11_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
      </dependencies>
 | 
			
		||||
@@ -29,37 +29,42 @@
 | 
			
		||||
      <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_7_R4</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R2</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_8_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R3</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_8_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_8_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R2</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_9_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_10_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_9_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_10_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_11_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
      </dependencies>
 | 
			
		||||
@@ -70,107 +75,113 @@
 | 
			
		||||
      <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_4_5</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_4_5</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_4_6</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_4_6</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_4_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_4_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_5_R2</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_5_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_5_R3</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_5_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_6_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_6_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_6_R2</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_6_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_6_R3</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_6_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_7_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R2</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_7_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R3</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_7_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_7_R4</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_7_R4</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_8_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R2</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_8_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_8_R3</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_8_R3</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_9_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_9_R2</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_9_R2</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_10_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_10_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
          <groupId>com.lishid</groupId>
 | 
			
		||||
          <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
          <artifactId>openinvcraftbukkit1_11_R1</artifactId>
 | 
			
		||||
          <version>1.0-SNAPSHOT</version>
 | 
			
		||||
        </dependency>
 | 
			
		||||
      </dependencies>
 | 
			
		||||
    </profile>
 | 
			
		||||
 | 
			
		||||
  </profiles>
 | 
			
		||||
 | 
			
		||||
  <build>
 | 
			
		||||
    <directory>../target</directory>
 | 
			
		||||
    <finalName>OpenInv</finalName>
 | 
			
		||||
    <finalName>${project.name}</finalName>
 | 
			
		||||
 | 
			
		||||
    <resources>
 | 
			
		||||
      <resource>
 | 
			
		||||
        <directory>../OpenInvPlugin/src/main/resources</directory>
 | 
			
		||||
        <filtering>true</filtering>
 | 
			
		||||
      </resource>
 | 
			
		||||
    </resources>
 | 
			
		||||
 | 
			
		||||
    <plugins>
 | 
			
		||||
      <plugin>
 | 
			
		||||
@@ -4,12 +4,12 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvinternal</artifactId>
 | 
			
		||||
  <name>OpenInvInternal</name>
 | 
			
		||||
  <artifactId>openinvcore</artifactId>
 | 
			
		||||
  <name>OpenInvCore</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
@@ -19,5 +19,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,39 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @deprecated Use {@link IAnySilentContainer}
 | 
			
		||||
 */
 | 
			
		||||
@Deprecated
 | 
			
		||||
public interface IAnySilentChest {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link IAnySilentContainer#activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link IAnySilentContainer#isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package com.lishid.openinv.internal;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
public interface IAnySilentContainer {
 | 
			
		||||
public interface IAnySilentContainer extends IAnySilentChest {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if the given block is a container which can be unblocked or silenced.
 | 
			
		||||
@@ -11,27 +11,30 @@ public interface IAnySilentContainer {
 | 
			
		||||
     * @param block the BlockState
 | 
			
		||||
     * @return true if the Block is a supported container
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isAnySilentContainer(Block block);
 | 
			
		||||
    public boolean isAnySilentContainer(BlockState block);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Opens the container at the given coordinates for the Player.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player
 | 
			
		||||
     * @param anychest whether compatibility for blocked containers is to be used
 | 
			
		||||
     * @param silentchest whether the container's noise is to be silenced
 | 
			
		||||
     * @param x the x coordinate
 | 
			
		||||
     * @param y the y coordinate
 | 
			
		||||
     * @param z the z coordinate
 | 
			
		||||
     * @return true if the container can be opened
 | 
			
		||||
     */
 | 
			
		||||
    public boolean activateContainer(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Checks if the container at the given coordinates is blocked.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param player the Player opening the container
 | 
			
		||||
     * @param block the Block
 | 
			
		||||
     * @param x the x coordinate
 | 
			
		||||
     * @param y the y coordinate
 | 
			
		||||
     * @param z the z coordinate
 | 
			
		||||
     * @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);
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player player, int x, int y, int z);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
public interface IInventoryAccess {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check if an entity has permission to modify the contents of an inventory.
 | 
			
		||||
     * 
 | 
			
		||||
     * @param inventory the Inventory
 | 
			
		||||
     * @param player the HumanEntity
 | 
			
		||||
     * @return true if the HumanEntity can modify the Inventory
 | 
			
		||||
     */
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_10_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_10_R1</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_10_R1</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_10_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,153 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.block.BlockState;
 | 
			
		||||
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.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.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.ITileInventory;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_10_R1.TileEntityChest;
 | 
			
		||||
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(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(new BlockPosition(x, y, z));
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
 | 
			
		||||
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest);
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z)));
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest);
 | 
			
		||||
        if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            try {
 | 
			
		||||
                SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
 | 
			
		||||
                int windowId = player.nextContainerCounter();
 | 
			
		||||
                player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        BlockPosition position = new BlockPosition(x, y, z);
 | 
			
		||||
        if (Block.getId(world.getType(position).getBlock()) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.getType(position).l()) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return hasOcelotOnTop(world, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, int x, int y, int z) {
 | 
			
		||||
        for (Entity localEntity : world.a(EntityOcelot.class,
 | 
			
		||||
                new AxisAlignedBB(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,74 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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 com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
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 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 iinventory
 | 
			
		||||
        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) {
 | 
			
		||||
                    e.printStackTrace();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -35,26 +35,24 @@ 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)));
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
			
		||||
 | 
			
		||||
        // Get the bukkit entity
 | 
			
		||||
        Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
			
		||||
        if (target != null) {
 | 
			
		||||
            // Load data
 | 
			
		||||
            target.loadData();
 | 
			
		||||
        }
 | 
			
		||||
            // Return the entity
 | 
			
		||||
            return target;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_10_R1;
 | 
			
		||||
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 IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) {
 | 
			
		||||
        super(i1, i2, e1);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.closeContainer(e1);
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.closeContainer(e1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried(), false);
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried, false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -37,12 +37,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public 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());
 | 
			
		||||
        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;
 | 
			
		||||
@@ -81,7 +79,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                this.bukkitOwner = player;
 | 
			
		||||
                CraftPlayer craftPlayer = (CraftPlayer) player;
 | 
			
		||||
                setItemArrays(craftPlayer.getHandle().getEnderChest(), this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -126,14 +126,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -154,14 +156,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -177,7 +181,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].cloneAndSubtract(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -186,9 +191,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -197,14 +203,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -219,9 +227,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -230,14 +239,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extraSlots;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -258,25 +269,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -292,5 +300,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    public boolean a(EntityHuman entityhuman) {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_11_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_11_R1</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_11_R1</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_11_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -18,19 +18,14 @@ 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;
 | 
			
		||||
@@ -41,13 +36,11 @@ 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;
 | 
			
		||||
 | 
			
		||||
@@ -56,50 +49,125 @@ 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;
 | 
			
		||||
    public boolean isAnySilentContainer(org.bukkit.block.BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest || block instanceof org.bukkit.block.ShulkerBox;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, org.bukkit.block.Block b) {
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
 | 
			
		||||
        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();
 | 
			
		||||
        BlockPosition blockPosition = new BlockPosition(x, y, z);
 | 
			
		||||
        Object tile = world.getTileEntity(blockPosition);
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockShulkerBox) {
 | 
			
		||||
            return isBlockedShulkerBox(world, blockPosition, block);
 | 
			
		||||
        if (tile == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockEnderChest) {
 | 
			
		||||
            // Ender chests are not blocked by ocelots.
 | 
			
		||||
            return world.getType(blockPosition.up()).m();
 | 
			
		||||
        }
 | 
			
		||||
        Block block = world.getType(new BlockPosition(x, y, z)).getBlock();
 | 
			
		||||
        Container container = null;
 | 
			
		||||
 | 
			
		||||
        // Check if chest is blocked or has an ocelot on top
 | 
			
		||||
        if (isBlockedChest(world, blockPosition)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (block instanceof BlockChest) {
 | 
			
		||||
            BlockChest blockChest = (BlockChest) block;
 | 
			
		||||
 | 
			
		||||
        // 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);
 | 
			
		||||
            for (EnumDirection enumDirection : EnumDirection.EnumDirectionLimit.HORIZONTAL) {
 | 
			
		||||
                BlockPosition localBlockPosition = blockPosition.shift(enumDirection);
 | 
			
		||||
                Block localBlock = world.getType(localBlockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
                if (localBlock != block) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (!anychest && isBlockedChest(world, localBlock, localBlockPosition)) {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                TileEntity localTileEntity = world.getTileEntity(localBlockPosition);
 | 
			
		||||
                if (!(localTileEntity instanceof TileEntityChest)) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            if (isBlockedChest(world, localBlockPosition)) {
 | 
			
		||||
                if ((enumDirection == EnumDirection.WEST) || (enumDirection == 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) {
 | 
			
		||||
            if (!anychest && isBlockedShulkerBox(world, blockPosition, block)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            player.b(StatisticList.ae);
 | 
			
		||||
 | 
			
		||||
            if (silentchest && tile instanceof TileEntityShulkerBox) {
 | 
			
		||||
                // TODO: This fixes sound, but the box is then silent for anyone until the tile entity is recreated
 | 
			
		||||
                SilentContainerShulkerBox.increaseOpenQuantity((TileEntityShulkerBox) tile);
 | 
			
		||||
                container = new SilentContainerShulkerBox(player.inventory, ((IInventory) tile), player);
 | 
			
		||||
                SilentContainerShulkerBox.decreaseOpenQuantity((TileEntityShulkerBox) tile);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
 | 
			
		||||
        if (!silentchest || container == null) {
 | 
			
		||||
            player.openContainer((IInventory) tile);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            try {
 | 
			
		||||
                int windowId = player.nextContainerCounter();
 | 
			
		||||
                player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) tile).getScoreboardDisplayName(), ((IInventory) tile).getSize()));
 | 
			
		||||
                player.activeContainer = container;
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        BlockPosition blockPosition = new BlockPosition(x, y, z);
 | 
			
		||||
        Block block = world.getType(blockPosition).getBlock();
 | 
			
		||||
 | 
			
		||||
        if (block instanceof BlockShulkerBox) {
 | 
			
		||||
            return isBlockedShulkerBox(world, blockPosition, block);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // For reference, loot at net.minecraft.server.BlockChest
 | 
			
		||||
        // Check if chest is blocked or has an ocelot on top
 | 
			
		||||
        if (world.getType(new BlockPosition(x, y + 1, z)).m() || hasOcelotOnTop(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);
 | 
			
		||||
            if (isBlockedChest(world, block, localBlockPosition)) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -124,15 +192,18 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
                    .a(enumDirection.getAdjacentX(), enumDirection.getAdjacentY(),
 | 
			
		||||
                            enumDirection.getAdjacentZ());
 | 
			
		||||
 | 
			
		||||
            return world.b(axisAlignedBB.a(blockPosition.shift(enumDirection)));
 | 
			
		||||
            return !(world.b(axisAlignedBB.a(blockPosition.shift(enumDirection))));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, Block block, BlockPosition blockPosition) {
 | 
			
		||||
        if (world.getType(blockPosition).getBlock() == block) {
 | 
			
		||||
            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);
 | 
			
		||||
        return world.getType(blockPosition).m() || hasOcelotOnTop(world, blockPosition);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
 | 
			
		||||
@@ -149,128 +220,22 @@ public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @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;
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        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() {
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @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;
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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.v1_11_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
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 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 iinventory
 | 
			
		||||
        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) {
 | 
			
		||||
                    e.printStackTrace();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -35,26 +35,24 @@ 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)));
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
			
		||||
 | 
			
		||||
        // Get the bukkit entity
 | 
			
		||||
        Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
			
		||||
        if (target != null) {
 | 
			
		||||
            // Load data
 | 
			
		||||
            target.loadData();
 | 
			
		||||
        }
 | 
			
		||||
            // Return the entity
 | 
			
		||||
            return target;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -28,7 +28,7 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public SilentContainerChest(PlayerInventory playerInventory, IInventory iInventory,
 | 
			
		||||
            EntityHuman entityHuman) {
 | 
			
		||||
        super(playerInventory, iInventory, entityHuman);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        // close signal
 | 
			
		||||
        iInventory.closeContainer(entityHuman);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -37,11 +37,9 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        // Don't send close signal twice, might screw up
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != ItemStack.a) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
        if (!playerinventory.getCarried().isEmpty()) {
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried(), false);
 | 
			
		||||
            playerinventory.setCarried(ItemStack.a);
 | 
			
		||||
            entityHuman.drop(carried, false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -11,7 +11,31 @@ import net.minecraft.server.v1_11_R1.TileEntityShulkerBox;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerShulkerBox extends ContainerShulkerBox {
 | 
			
		||||
 | 
			
		||||
    private static Field fieldShulkerActionData;
 | 
			
		||||
    private static Field h;
 | 
			
		||||
 | 
			
		||||
    private static Field exposeOpenStatus() throws NoSuchFieldException, SecurityException {
 | 
			
		||||
        if (h == null) {
 | 
			
		||||
            h = TileEntityShulkerBox.class.getDeclaredField("h");
 | 
			
		||||
            h.setAccessible(true);
 | 
			
		||||
        }
 | 
			
		||||
        return h;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void increaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
 | 
			
		||||
        try {
 | 
			
		||||
            exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) + 1);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void decreaseOpenQuantity(TileEntityShulkerBox containerShulkerBox) {
 | 
			
		||||
        try {
 | 
			
		||||
            exposeOpenStatus().set(containerShulkerBox, ((Integer) exposeOpenStatus().get(containerShulkerBox)) - 1);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SilentContainerShulkerBox(PlayerInventory playerInventory, IInventory iInventory,
 | 
			
		||||
            EntityHuman entityHuman) {
 | 
			
		||||
@@ -28,29 +52,4 @@ public class SilentContainerShulkerBox extends ContainerShulkerBox {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -38,12 +38,10 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public 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());
 | 
			
		||||
        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;
 | 
			
		||||
@@ -82,7 +80,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                this.bukkitOwner = player;
 | 
			
		||||
                CraftPlayer craftPlayer = (CraftPlayer) player;
 | 
			
		||||
                setItemLists(craftPlayer.getHandle().getEnderChest(), this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -223,25 +223,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -257,5 +254,4 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    public boolean a(EntityHuman entityhuman) {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_4_5</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_4_5</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_4_5</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_4_5</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,154 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_5.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_4_5.Block;
 | 
			
		||||
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.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_4_5.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_4_5.TileEntityChest;
 | 
			
		||||
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(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            try {
 | 
			
		||||
                int id = 0;
 | 
			
		||||
                try {
 | 
			
		||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
			
		||||
                    windowID.setAccessible(true);
 | 
			
		||||
                    id = windowID.getInt(player);
 | 
			
		||||
                    id = id % 100 + 1;
 | 
			
		||||
                    windowID.setInt(player, id);
 | 
			
		||||
                } catch (NoSuchFieldException e) {}
 | 
			
		||||
 | 
			
		||||
                player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                player.activeContainer.windowId = id;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != Block.CHEST.id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.s(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_4_5;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_5.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_5.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,26 +33,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_4_5;
 | 
			
		||||
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 IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.f();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.f();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,14 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer player = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
			
		||||
        this.owner = player;
 | 
			
		||||
@@ -69,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_4_6</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_4_6</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_4_6</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_4_6</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,154 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_6.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_4_6.Block;
 | 
			
		||||
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.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_4_6.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_4_6.TileEntityChest;
 | 
			
		||||
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(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            try {
 | 
			
		||||
                int id = 0;
 | 
			
		||||
                try {
 | 
			
		||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
			
		||||
                    windowID.setAccessible(true);
 | 
			
		||||
                    id = windowID.getInt(player);
 | 
			
		||||
                    id = id % 100 + 1;
 | 
			
		||||
                    windowID.setInt(player, id);
 | 
			
		||||
                } catch (NoSuchFieldException e) {}
 | 
			
		||||
 | 
			
		||||
                player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                player.activeContainer.windowId = id;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != Block.CHEST.id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.s(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_4_6;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_6.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_4_6.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,26 +33,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_4_6;
 | 
			
		||||
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 IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.f();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.f();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,14 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer player = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
			
		||||
        this.owner = player;
 | 
			
		||||
@@ -69,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -196,25 +207,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_4_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_4_R1</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_4_R1</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_4_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,154 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.Block;
 | 
			
		||||
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.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_4_R1.TileEntityChest;
 | 
			
		||||
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(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            returnValue = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            try {
 | 
			
		||||
                int id = 0;
 | 
			
		||||
                try {
 | 
			
		||||
                    Field windowID = player.getClass().getDeclaredField("containerCounter");
 | 
			
		||||
                    windowID.setAccessible(true);
 | 
			
		||||
                    id = windowID.getInt(player);
 | 
			
		||||
                    id = id % 100 + 1;
 | 
			
		||||
                    windowID.setInt(player, id);
 | 
			
		||||
                } catch (NoSuchFieldException e) {}
 | 
			
		||||
 | 
			
		||||
                player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                player.activeContainer.windowId = id;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.s(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, x - 1, y, z) || isBlockedChest(world, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, x, y, z - 1) || isBlockedChest(world, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != Block.CHEST.id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.s(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
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 check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -34,26 +34,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_4_R1;
 | 
			
		||||
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 IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.f();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.f();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,14 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer player = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
			
		||||
        this.owner = player;
 | 
			
		||||
@@ -69,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_5_R2</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_5_R2</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_5_R2</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_5_R2</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,157 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R2.AxisAlignedBB;
 | 
			
		||||
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.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_5_R2.TileEntityChest;
 | 
			
		||||
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(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
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 check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,26 +33,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_5_R2;
 | 
			
		||||
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 IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.g();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,15 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        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;
 | 
			
		||||
@@ -70,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -196,25 +207,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_5_R3</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_5_R3</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_5_R3</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_5_R3</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,157 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
//Volatile
 | 
			
		||||
import net.minecraft.server.v1_5_R3.AxisAlignedBB;
 | 
			
		||||
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.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_5_R3.TileEntityChest;
 | 
			
		||||
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(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
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 check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,26 +33,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_5_R3;
 | 
			
		||||
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 class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.g();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {    public IInventory
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,15 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        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;
 | 
			
		||||
@@ -70,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -196,25 +207,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_6_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_6_R1</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_6_R1</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_6_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,157 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_6_R1.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_6_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_6_R1.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,26 +33,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_6_R1;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_6_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.g();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,15 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        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;
 | 
			
		||||
@@ -70,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -196,25 +207,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_6_R2</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_6_R2</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_6_R2</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_6_R2</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,157 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_6_R2.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_6_R2;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_6_R2.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R2.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,26 +33,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_6_R2;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_6_R2.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.g();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,15 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        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;
 | 
			
		||||
@@ -70,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -196,25 +207,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_6_R3</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_6_R3</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_6_R3</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_6_R3</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,157 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_6_R3.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.Packet100OpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        if (world.getTypeId(x - 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x + 1, y, z) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (world.getTypeId(x, y, z - 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (world.getTypeId(x, y, z + 1) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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) chest).getName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = world.getTypeId(x, y, z);
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (world.getTypeId(x, y, z) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_6_R3;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_6_R3.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -33,26 +33,21 @@ 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)));
 | 
			
		||||
        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;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_6_R3;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_6_R3.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.g();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.g();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried());
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,15 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public 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());
 | 
			
		||||
        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;
 | 
			
		||||
@@ -70,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_7_R1</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_7_R1</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_7_R1</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_7_R1</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -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.internal.v1_7_R1;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
//Volatile
 | 
			
		||||
import net.minecraft.server.v1_7_R1.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.Block;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.PacketPlayOutOpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = Block.b(world.getType(x, y, z));
 | 
			
		||||
 | 
			
		||||
        if (Block.b(world.getType(x - 1, y, z)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (Block.b(world.getType(x + 1, y, z)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (Block.b(world.getType(x, y, z - 1)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (Block.b(world.getType(x, y, z + 1)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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 PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = Block.b(world.getType(x, y, z));
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (Block.b(world.getType(x, y, z)) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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().a(x, y + 1, z, x + 1, y + 2, z + 1))) {
 | 
			
		||||
            EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
 | 
			
		||||
            if (localEntityOcelot.isSitting()) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_7_R1;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_7_R1.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -34,26 +34,22 @@ public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure the player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Create a profile and entity to load the player data
 | 
			
		||||
        GameProfile profile = new GameProfile(null, offline.getName());
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
 | 
			
		||||
                new PlayerInteractManager(server.getWorldServer(0)));
 | 
			
		||||
 | 
			
		||||
        GameProfile profile = new GameProfile(null, offline.getName());
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
			
		||||
 | 
			
		||||
        // Get the bukkit entity
 | 
			
		||||
        Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
			
		||||
        if (target != null) {
 | 
			
		||||
            // Load data
 | 
			
		||||
            target.loadData();
 | 
			
		||||
        }
 | 
			
		||||
            // Return the entity
 | 
			
		||||
            return target;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_7_R1;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_7_R1.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.l_();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.l_();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried(), false);
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried, false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,15 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(),
 | 
			
		||||
                ((CraftPlayer) p).getHandle().getEnderChest().k_(),
 | 
			
		||||
                ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer player = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
			
		||||
        this.owner = player;
 | 
			
		||||
@@ -70,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -125,5 +124,4 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
        super.update();
 | 
			
		||||
        enderChest.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -196,25 +207,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_7_R2</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_7_R2</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_7_R2</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_7_R2</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -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.internal.v1_7_R2;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
//Volatile
 | 
			
		||||
import net.minecraft.server.v1_7_R2.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.Block;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.PacketPlayOutOpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = Block.b(world.getType(x, y, z));
 | 
			
		||||
 | 
			
		||||
        if (Block.b(world.getType(x - 1, y, z)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (Block.b(world.getType(x + 1, y, z)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (Block.b(world.getType(x, y, z - 1)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (Block.b(world.getType(x, y, z + 1)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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 PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = Block.b(world.getType(x, y, z));
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (Block.b(world.getType(x, y, z)) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (C) 2011-2014 lishid.  All rights reserved.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation,  version 3.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 * GNU General Public License for more details.
 | 
			
		||||
 * 
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package com.lishid.openinv.internal.v1_7_R2;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.OpenInv;
 | 
			
		||||
import com.lishid.openinv.Permissions;
 | 
			
		||||
import com.lishid.openinv.internal.IInventoryAccess;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.HumanEntity;
 | 
			
		||||
import org.bukkit.inventory.Inventory;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_7_R2.IInventory;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_7_R2.inventory.CraftInventory;
 | 
			
		||||
 | 
			
		||||
public class InventoryAccess implements IInventoryAccess {
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean check(Inventory inventory, HumanEntity player) {
 | 
			
		||||
        IInventory inv = ((CraftInventory) inventory).getInventory();
 | 
			
		||||
 | 
			
		||||
        if (inv instanceof SpecialPlayerInventory) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else if (inv instanceof SpecialEnderChest) {
 | 
			
		||||
            if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -30,31 +30,26 @@ import net.minecraft.util.com.mojang.authlib.GameProfile;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings("deprecation") // Deprecated methods are used properly and will not change.
 | 
			
		||||
public class PlayerDataManager implements IPlayerDataManager {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Player loadPlayer(OfflinePlayer offline) {
 | 
			
		||||
        // Ensure the player has data
 | 
			
		||||
        if (offline == null || !offline.hasPlayedBefore()) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Create a profile and entity to load the player data
 | 
			
		||||
        GameProfile profile = new GameProfile(null, offline.getName());
 | 
			
		||||
        MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile,
 | 
			
		||||
                new PlayerInteractManager(server.getWorldServer(0)));
 | 
			
		||||
 | 
			
		||||
        GameProfile profile = new GameProfile(null, offline.getName());
 | 
			
		||||
        // Create an entity to load the player data
 | 
			
		||||
        EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
 | 
			
		||||
 | 
			
		||||
        // Get the bukkit entity
 | 
			
		||||
        Player target = (entity == null) ? null : entity.getBukkitEntity();
 | 
			
		||||
        if (target != null) {
 | 
			
		||||
            // Load data
 | 
			
		||||
            target.loadData();
 | 
			
		||||
        }
 | 
			
		||||
            // Return the entity
 | 
			
		||||
            return target;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getPlayerDataID(OfflinePlayer player) {
 | 
			
		||||
@@ -20,15 +20,16 @@ package com.lishid.openinv.internal.v1_7_R2;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_7_R2.PlayerInventory;
 | 
			
		||||
 | 
			
		||||
public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
    public IInventory inv;
 | 
			
		||||
 | 
			
		||||
    public SilentContainerChest(IInventory i1, IInventory i2) {
 | 
			
		||||
        super(i1, i2);
 | 
			
		||||
        // Send close signal
 | 
			
		||||
        i2.l_();
 | 
			
		||||
        inv = i2;
 | 
			
		||||
        // close signal
 | 
			
		||||
        inv.l_();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -37,10 +38,8 @@ public class SilentContainerChest extends ContainerChest {
 | 
			
		||||
        PlayerInventory playerinventory = entityHuman.inventory;
 | 
			
		||||
 | 
			
		||||
        if (playerinventory.getCarried() != null) {
 | 
			
		||||
            ItemStack carried = playerinventory.getCarried();
 | 
			
		||||
            entityHuman.drop(playerinventory.getCarried(), false);
 | 
			
		||||
            playerinventory.setCarried(null);
 | 
			
		||||
            entityHuman.drop(carried, false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -41,15 +41,13 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
 | 
			
		||||
    private final InventoryEnderChest enderChest;
 | 
			
		||||
    private final CraftInventory inventory = new CraftInventory(this);
 | 
			
		||||
    private final List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    private boolean playerOnline = false;
 | 
			
		||||
    public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
 | 
			
		||||
    public boolean playerOnline = false;
 | 
			
		||||
    private CraftPlayer owner;
 | 
			
		||||
    private int maxStack = MAX_STACK;
 | 
			
		||||
 | 
			
		||||
    public SpecialEnderChest(Player p, Boolean online) {
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(),
 | 
			
		||||
                ((CraftPlayer) p).getHandle().getEnderChest().k_(),
 | 
			
		||||
                ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
 | 
			
		||||
        CraftPlayer player = (CraftPlayer) p;
 | 
			
		||||
        this.enderChest = player.getHandle().getEnderChest();
 | 
			
		||||
        this.owner = player;
 | 
			
		||||
@@ -70,7 +68,8 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
 | 
			
		||||
                Field field = playerEnderChest.getClass().getField("items");
 | 
			
		||||
                field.setAccessible(true);
 | 
			
		||||
                field.set(playerEnderChest, this.items);
 | 
			
		||||
            } catch (Exception e) {}
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e) {}
 | 
			
		||||
            playerOnline = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -86,14 +86,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -107,14 +109,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +129,8 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                itemstack = is[i];
 | 
			
		||||
                is[i] = null;
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            } else {
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                itemstack = is[i].a(j);
 | 
			
		||||
                if (is[i].count == 0) {
 | 
			
		||||
                    is[i] = null;
 | 
			
		||||
@@ -134,9 +139,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
                return itemstack;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack splitWithoutUpdate(int i) {
 | 
			
		||||
@@ -145,14 +151,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -162,9 +170,10 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
            is[i] = null;
 | 
			
		||||
            return itemstack;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItem(int i, ItemStack itemstack) {
 | 
			
		||||
@@ -173,14 +182,16 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.armor;
 | 
			
		||||
        } else {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            i = getReversedItemSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (i >= is.length) {
 | 
			
		||||
            i -= is.length;
 | 
			
		||||
            is = this.extra;
 | 
			
		||||
        } else if (is == this.armor) {
 | 
			
		||||
        }
 | 
			
		||||
        else if (is == this.armor) {
 | 
			
		||||
            i = getReversedArmorSlotNum(i);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -196,25 +207,22 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedItemSlotNum(int i) {
 | 
			
		||||
        if (i >= 27) {
 | 
			
		||||
        if (i >= 27)
 | 
			
		||||
            return i - 27;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i + 9;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getReversedArmorSlotNum(int i) {
 | 
			
		||||
        if (i == 0) {
 | 
			
		||||
        if (i == 0)
 | 
			
		||||
            return 3;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 1) {
 | 
			
		||||
        if (i == 1)
 | 
			
		||||
            return 2;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 2) {
 | 
			
		||||
        if (i == 2)
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        if (i == 3) {
 | 
			
		||||
        if (i == 3)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
            return i;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -4,14 +4,19 @@
 | 
			
		||||
 | 
			
		||||
  <parent>
 | 
			
		||||
    <groupId>com.lishid</groupId>
 | 
			
		||||
    <artifactId>openinv</artifactId>
 | 
			
		||||
    <artifactId>openinvparent</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
  </parent>
 | 
			
		||||
 | 
			
		||||
  <artifactId>openinvadapter1_7_R3</artifactId>
 | 
			
		||||
  <name>OpenInvAdapter1_7_R3</name>
 | 
			
		||||
  <artifactId>OpenInvCraftbukkit1_7_R3</artifactId>
 | 
			
		||||
  <name>OpenInvCraftbukkit1_7_R3</name>
 | 
			
		||||
 | 
			
		||||
  <dependencies>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvcore</artifactId>
 | 
			
		||||
      <version>1.0-SNAPSHOT</version>
 | 
			
		||||
    </dependency>
 | 
			
		||||
    <dependency>
 | 
			
		||||
      <groupId>com.lishid</groupId>
 | 
			
		||||
      <artifactId>openinvplugin</artifactId>
 | 
			
		||||
@@ -24,5 +29,4 @@
 | 
			
		||||
      <scope>provided</scope>
 | 
			
		||||
    </dependency>
 | 
			
		||||
  </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -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.internal.v1_7_R3;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import com.lishid.openinv.internal.IAnySilentContainer;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.block.BlockState;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
// Volatile
 | 
			
		||||
import net.minecraft.server.v1_7_R3.AxisAlignedBB;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.Block;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.EntityOcelot;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.EntityPlayer;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.InventoryLargeChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.PacketPlayOutOpenWindow;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.TileEntityChest;
 | 
			
		||||
import net.minecraft.server.v1_7_R3.World;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
 | 
			
		||||
 | 
			
		||||
public class AnySilentContainer implements IAnySilentContainer {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnySilentContainer(BlockState block) {
 | 
			
		||||
        return block instanceof org.bukkit.block.Chest;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
        Object chest = world.getTileEntity(x, y, z);
 | 
			
		||||
        if (chest == null)
 | 
			
		||||
            return false;
 | 
			
		||||
 | 
			
		||||
        if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int id = Block.b(world.getType(x, y, z));
 | 
			
		||||
 | 
			
		||||
        if (Block.b(world.getType(x - 1, y, z)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
 | 
			
		||||
        if (Block.b(world.getType(x + 1, y, z)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z));
 | 
			
		||||
        if (Block.b(world.getType(x, y, z - 1)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
 | 
			
		||||
        if (Block.b(world.getType(x, y, z + 1)) == id)
 | 
			
		||||
            chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
 | 
			
		||||
 | 
			
		||||
        boolean returnValue = false;
 | 
			
		||||
        if (!silentchest) {
 | 
			
		||||
            player.openContainer((IInventory) chest);
 | 
			
		||||
            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 PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
 | 
			
		||||
                player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
 | 
			
		||||
                player.activeContainer.windowId = windowId;
 | 
			
		||||
                player.activeContainer.addSlotListener(player);
 | 
			
		||||
                returnValue = true;
 | 
			
		||||
            } catch (Exception e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
                p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return returnValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyContainerNeeded(Player p, int x, int y, int z) {
 | 
			
		||||
        // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
 | 
			
		||||
        EntityPlayer player = ((CraftPlayer) p).getHandle();
 | 
			
		||||
        World world = player.world;
 | 
			
		||||
 | 
			
		||||
        // If block or ocelot on top
 | 
			
		||||
        if (world.t(x, y + 1, z) || hasOcelotOnTop(world, x, y, z))
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        int id = Block.b(world.getType(x, y, z));
 | 
			
		||||
 | 
			
		||||
        // If block next to chest is chest and has a block or ocelot on top
 | 
			
		||||
        return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
 | 
			
		||||
                || isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isBlockedChest(World world, int id, int x, int y, int z) {
 | 
			
		||||
        if (Block.b(world.getType(x, y, z)) != id) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (world.t(x, y + 1, z)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
 | 
			
		||||
        return !activateContainer(player, anychest, silentchest, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Use {@link #isAnyContainerNeeded(Player, int, int, int)}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isAnyChestNeeded(Player player, int x, int y, int z) {
 | 
			
		||||
        return isAnyContainerNeeded(player, x, y, z);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user