Prep for silent shulker boxes, backport ocelot fix to all versions
No clue why I didn't port it to all versions, seems like I stopped after 1.8 or something. Ocelots have been around since 1.2.
This commit is contained in:
@@ -18,8 +18,22 @@ package com.lishid.openinv.internal;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link IAnySilentContainer}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface IAnySilentChest {
|
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);
|
public boolean isAnyChestNeeded(Player player, int x, int y, int z);
|
||||||
|
|
||||||
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z);
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,40 @@
|
|||||||
|
package com.lishid.openinv.internal;
|
||||||
|
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public interface IAnySilentContainer extends IAnySilentChest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the given Block is a container which can be unblocked or silenced.
|
||||||
|
*
|
||||||
|
* @param block the Block
|
||||||
|
* @return true if the Block is a supported container
|
||||||
|
*/
|
||||||
|
public boolean isAnySilentContainer(Block 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 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, int x, int y, int z);
|
||||||
|
|
||||||
|
}
|
@@ -20,5 +20,14 @@ import org.bukkit.entity.HumanEntity;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
public interface IInventoryAccess {
|
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);
|
public boolean check(Inventory inventory, HumanEntity player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,11 @@ import org.bukkit.inventory.Inventory;
|
|||||||
|
|
||||||
public interface ISpecialEnderChest {
|
public interface ISpecialEnderChest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Inventory associated with this ISpecialEnderChest.
|
||||||
|
*
|
||||||
|
* @return the Inventory
|
||||||
|
*/
|
||||||
public Inventory getBukkitInventory();
|
public Inventory getBukkitInventory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -21,6 +21,11 @@ import org.bukkit.inventory.Inventory;
|
|||||||
|
|
||||||
public interface ISpecialPlayerInventory {
|
public interface ISpecialPlayerInventory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Inventory associated with this ISpecialPlayerInventory.
|
||||||
|
*
|
||||||
|
* @return the Inventory
|
||||||
|
*/
|
||||||
public Inventory getBukkitInventory();
|
public Inventory getBukkitInventory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_10_R1;
|
package com.lishid.openinv.internal.v1_10_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
import net.minecraft.server.v1_10_R1.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_10_R1.Block;
|
import net.minecraft.server.v1_10_R1.Block;
|
||||||
@@ -37,12 +37,64 @@ import net.minecraft.server.v1_10_R1.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block 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
|
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
|
|
||||||
// If block or ocelot on top
|
// If block or ocelot on top
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
||||||
return true;
|
return true;
|
||||||
@@ -50,16 +102,8 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
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
|
// If block next to chest is chest and has a block or ocelot on top
|
||||||
if (isBlockedChest(world, id, x - 1, y, z))
|
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
||||||
return true;
|
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
||||||
if (isBlockedChest(world, id, x + 1, y, z))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z - 1))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z + 1))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
||||||
@@ -87,58 +131,22 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
return !activateContainer(player, anychest, silentchest, x, y, z);
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = true;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
}
|
|
||||||
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 = false;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -1,144 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.lishid.openinv.internal.v1_11_R1;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import net.minecraft.server.v1_11_R1.AxisAlignedBB;
|
|
||||||
import net.minecraft.server.v1_11_R1.Block;
|
|
||||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
|
||||||
import net.minecraft.server.v1_11_R1.Entity;
|
|
||||||
import net.minecraft.server.v1_11_R1.EntityOcelot;
|
|
||||||
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_11_R1.IInventory;
|
|
||||||
import net.minecraft.server.v1_11_R1.ITileInventory;
|
|
||||||
import net.minecraft.server.v1_11_R1.InventoryLargeChest;
|
|
||||||
import net.minecraft.server.v1_11_R1.PacketPlayOutOpenWindow;
|
|
||||||
import net.minecraft.server.v1_11_R1.TileEntityChest;
|
|
||||||
import net.minecraft.server.v1_11_R1.World;
|
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
|
||||||
@Override
|
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block 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
|
|
||||||
if (isBlockedChest(world, id, x - 1, y, z))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x + 1, y, z))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z - 1))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z + 1))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = true;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
}
|
|
||||||
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 = false;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,211 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.lishid.openinv.internal.v1_11_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// 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.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_11_R1.BlockShulkerBox;
|
||||||
|
import net.minecraft.server.v1_11_R1.Container;
|
||||||
|
import net.minecraft.server.v1_11_R1.Entity;
|
||||||
|
import net.minecraft.server.v1_11_R1.EntityOcelot;
|
||||||
|
import net.minecraft.server.v1_11_R1.EntityPlayer;
|
||||||
|
import net.minecraft.server.v1_11_R1.EnumDirection;
|
||||||
|
import net.minecraft.server.v1_11_R1.IInventory;
|
||||||
|
import net.minecraft.server.v1_11_R1.ITileInventory;
|
||||||
|
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.World;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
|
return block instanceof org.bukkit.block.Chest || block instanceof org.bukkit.block.ShulkerBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
BlockPosition blockPosition = new BlockPosition(x, y, z);
|
||||||
|
Object tile = world.getTileEntity(blockPosition);
|
||||||
|
|
||||||
|
if (tile == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Block block = world.getType(new BlockPosition(x, y, z)).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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!anychest && isBlockedChest(world, localBlock, localBlockPosition)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
// TODO shulker
|
||||||
|
}
|
||||||
|
|
||||||
|
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, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FOR REFERENCE, LOOK 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockedShulkerBox(World world, int x, int y, int z) {
|
||||||
|
// For reference, look at net.minecraft.server.BlockShulkerBox
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlockedChest(World world, Block block, BlockPosition blockPosition) {
|
||||||
|
if (world.getType(blockPosition).getBlock() == block) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return world.getType(blockPosition).m() || hasOcelotOnTop(world, blockPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasOcelotOnTop(World world, BlockPosition blockPosition) {
|
||||||
|
for (Entity localEntity : world.a(EntityOcelot.class,
|
||||||
|
new AxisAlignedBB(blockPosition.getX(), blockPosition.getY() + 1,
|
||||||
|
blockPosition.getZ(), blockPosition.getX() + 1, blockPosition.getY() + 2,
|
||||||
|
blockPosition.getZ() + 1))) {
|
||||||
|
EntityOcelot localEntityOcelot = (EntityOcelot) localEntity;
|
||||||
|
if (localEntityOcelot.isSitting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -18,30 +18,29 @@ package com.lishid.openinv.internal.v1_11_R1;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
import com.lishid.openinv.OpenInv;
|
import com.lishid.openinv.OpenInv;
|
||||||
import com.lishid.openinv.Permissions;
|
import com.lishid.openinv.Permissions;
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
|
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
import net.minecraft.server.v1_11_R1.IInventory;
|
import net.minecraft.server.v1_11_R1.IInventory;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory;
|
||||||
|
|
||||||
public class InventoryAccess implements IInventoryAccess {
|
public class InventoryAccess implements IInventoryAccess {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean check(Inventory inventory, HumanEntity player) {
|
public boolean check(Inventory inventory, HumanEntity player) {
|
||||||
IInventory inv = grabInventory(inventory);
|
IInventory inv = grabInventory(inventory);
|
||||||
|
|
||||||
if (inv instanceof SpecialPlayerInventory) {
|
if (inv instanceof SpecialPlayerInventory) {
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else if (inv instanceof SpecialEnderChest) {
|
||||||
|
|
||||||
else if (inv instanceof SpecialEnderChest) {
|
|
||||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -49,22 +48,21 @@ public class InventoryAccess implements IInventoryAccess {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IInventory grabInventory(Inventory inventory) {
|
private IInventory grabInventory(Inventory inventory) {
|
||||||
if(inventory instanceof CraftInventory) {
|
if (inventory instanceof CraftInventory) {
|
||||||
return ((CraftInventory) inventory).getInventory();
|
return ((CraftInventory) inventory).getInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Use reflection to find the iinventory
|
// Use reflection to find the iinventory
|
||||||
Class<? extends Inventory> clazz = inventory.getClass();
|
Class<? extends Inventory> clazz = inventory.getClass();
|
||||||
IInventory result = null;
|
IInventory result = null;
|
||||||
for(Field f : clazz.getDeclaredFields()) {
|
for (Field f : clazz.getDeclaredFields()) {
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
||||||
try {
|
try {
|
||||||
result = (IInventory) f.get(inventory);
|
result = (IInventory) f.get(inventory);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,13 +18,15 @@ package com.lishid.openinv.internal.v1_4_5;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_5.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_4_5.Block;
|
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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_4_5.IInventory;
|
import net.minecraft.server.v1_4_5.IInventory;
|
||||||
import net.minecraft.server.v1_4_5.InventoryLargeChest;
|
import net.minecraft.server.v1_4_5.InventoryLargeChest;
|
||||||
@@ -34,48 +36,23 @@ import net.minecraft.server.v1_4_5.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_4_5.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.s(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
if (!anychest) {
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
if (world.s(x, y + 1, z))
|
return false;
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
||||||
@@ -87,11 +64,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
try {
|
try {
|
||||||
@@ -100,16 +77,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
id = windowID.getInt(player);
|
id = windowID.getInt(player);
|
||||||
id = id % 100 + 1;
|
id = id % 100 + 1;
|
||||||
windowID.setInt(player, id);
|
windowID.setInt(player, id);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = id;
|
player.activeContainer.windowId = id;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -117,4 +92,62 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,12 +18,15 @@ package com.lishid.openinv.internal.v1_4_6;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_6.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_4_6.Block;
|
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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_4_6.IInventory;
|
import net.minecraft.server.v1_4_6.IInventory;
|
||||||
import net.minecraft.server.v1_4_6.InventoryLargeChest;
|
import net.minecraft.server.v1_4_6.InventoryLargeChest;
|
||||||
@@ -31,51 +34,25 @@ import net.minecraft.server.v1_4_6.Packet100OpenWindow;
|
|||||||
import net.minecraft.server.v1_4_6.TileEntityChest;
|
import net.minecraft.server.v1_4_6.TileEntityChest;
|
||||||
import net.minecraft.server.v1_4_6.World;
|
import net.minecraft.server.v1_4_6.World;
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_4_6.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.s(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
if (!anychest) {
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
if (world.s(x, y + 1, z))
|
return false;
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
||||||
@@ -87,11 +64,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
try {
|
try {
|
||||||
@@ -100,16 +77,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
id = windowID.getInt(player);
|
id = windowID.getInt(player);
|
||||||
id = id % 100 + 1;
|
id = id % 100 + 1;
|
||||||
windowID.setInt(player, id);
|
windowID.setInt(player, id);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = id;
|
player.activeContainer.windowId = id;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -117,4 +92,62 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,12 +18,15 @@ package com.lishid.openinv.internal.v1_4_R1;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_4_R1.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_4_R1.Block;
|
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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_4_R1.IInventory;
|
import net.minecraft.server.v1_4_R1.IInventory;
|
||||||
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
|
import net.minecraft.server.v1_4_R1.InventoryLargeChest;
|
||||||
@@ -31,51 +34,25 @@ import net.minecraft.server.v1_4_R1.Packet100OpenWindow;
|
|||||||
import net.minecraft.server.v1_4_R1.TileEntityChest;
|
import net.minecraft.server.v1_4_R1.TileEntityChest;
|
||||||
import net.minecraft.server.v1_4_R1.World;
|
import net.minecraft.server.v1_4_R1.World;
|
||||||
|
|
||||||
// Volatile
|
|
||||||
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.s(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
if (!anychest) {
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
if (world.s(x, y + 1, z))
|
return false;
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
if (world.getTypeId(x - 1, y, z) == Block.CHEST.id)
|
||||||
@@ -87,11 +64,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
if (world.getTypeId(x, y, z + 1) == Block.CHEST.id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
try {
|
try {
|
||||||
@@ -100,16 +77,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
id = windowID.getInt(player);
|
id = windowID.getInt(player);
|
||||||
id = id % 100 + 1;
|
id = id % 100 + 1;
|
||||||
windowID.setInt(player, id);
|
windowID.setInt(player, id);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize()));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = id;
|
player.activeContainer.windowId = id;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -117,4 +92,62 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,12 +18,14 @@ package com.lishid.openinv.internal.v1_5_R2;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// 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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_5_R2.IInventory;
|
import net.minecraft.server.v1_5_R2.IInventory;
|
||||||
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
|
import net.minecraft.server.v1_5_R2.InventoryLargeChest;
|
||||||
@@ -33,54 +35,27 @@ import net.minecraft.server.v1_5_R2.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_5_R2.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
int id = world.getTypeId(x, y, z);
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
if (world.getTypeId(x - 1, y, z) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
if (world.getTypeId(x + 1, y, z) == id)
|
||||||
@@ -90,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == id)
|
if (world.getTypeId(x, y, z + 1) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -103,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -120,4 +93,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,12 +18,14 @@ package com.lishid.openinv.internal.v1_5_R3;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
//Volatile
|
//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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_5_R3.IInventory;
|
import net.minecraft.server.v1_5_R3.IInventory;
|
||||||
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
|
import net.minecraft.server.v1_5_R3.InventoryLargeChest;
|
||||||
@@ -33,54 +35,27 @@ import net.minecraft.server.v1_5_R3.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_5_R3.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
int id = world.getTypeId(x, y, z);
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
if (world.getTypeId(x - 1, y, z) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
if (world.getTypeId(x + 1, y, z) == id)
|
||||||
@@ -90,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == id)
|
if (world.getTypeId(x, y, z + 1) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -103,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -120,4 +93,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,12 +18,14 @@ package com.lishid.openinv.internal.v1_6_R1;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// 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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_6_R1.IInventory;
|
import net.minecraft.server.v1_6_R1.IInventory;
|
||||||
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
|
import net.minecraft.server.v1_6_R1.InventoryLargeChest;
|
||||||
@@ -33,54 +35,27 @@ import net.minecraft.server.v1_6_R1.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_6_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
int id = world.getTypeId(x, y, z);
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
if (world.getTypeId(x - 1, y, z) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
if (world.getTypeId(x + 1, y, z) == id)
|
||||||
@@ -90,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == id)
|
if (world.getTypeId(x, y, z + 1) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -103,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -120,4 +93,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,12 +18,14 @@ package com.lishid.openinv.internal.v1_6_R2;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// 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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_6_R2.IInventory;
|
import net.minecraft.server.v1_6_R2.IInventory;
|
||||||
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
|
import net.minecraft.server.v1_6_R2.InventoryLargeChest;
|
||||||
@@ -33,54 +35,27 @@ import net.minecraft.server.v1_6_R2.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
int id = world.getTypeId(x, y, z);
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
if (world.getTypeId(x - 1, y, z) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
if (world.getTypeId(x + 1, y, z) == id)
|
||||||
@@ -90,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == id)
|
if (world.getTypeId(x, y, z + 1) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -103,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -120,4 +93,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,12 +18,14 @@ package com.lishid.openinv.internal.v1_6_R3;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// 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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_6_R3.IInventory;
|
import net.minecraft.server.v1_6_R3.IInventory;
|
||||||
import net.minecraft.server.v1_6_R3.InventoryLargeChest;
|
import net.minecraft.server.v1_6_R3.InventoryLargeChest;
|
||||||
@@ -33,54 +35,27 @@ import net.minecraft.server.v1_6_R3.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = world.getTypeId(x, y, z);
|
int id = world.getTypeId(x, y, z);
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.t(x, y + 1, z))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1)))
|
|
||||||
return true;
|
|
||||||
if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1)))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getTypeId(x - 1, y, z) == id)
|
if (world.getTypeId(x - 1, y, z) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (world.getTypeId(x + 1, y, z) == id)
|
if (world.getTypeId(x + 1, y, z) == id)
|
||||||
@@ -90,11 +65,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (world.getTypeId(x, y, z + 1) == id)
|
if (world.getTypeId(x, y, z + 1) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -103,16 +78,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -120,4 +93,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,13 +18,15 @@ package com.lishid.openinv.internal.v1_7_R1;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
//Volatile
|
//Volatile
|
||||||
|
import net.minecraft.server.v1_7_R1.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_7_R1.Block;
|
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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_7_R1.IInventory;
|
import net.minecraft.server.v1_7_R1.IInventory;
|
||||||
import net.minecraft.server.v1_7_R1.InventoryLargeChest;
|
import net.minecraft.server.v1_7_R1.InventoryLargeChest;
|
||||||
@@ -34,54 +36,27 @@ import net.minecraft.server.v1_7_R1.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
int id = Block.b(world.getType(x, y, z));
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
if (Block.b(world.getType(x - 1, y, z)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||||
@@ -91,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -104,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -121,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,13 +18,15 @@ package com.lishid.openinv.internal.v1_7_R2;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_7_R2.Block;
|
|
||||||
//Volatile
|
//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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_7_R2.IInventory;
|
import net.minecraft.server.v1_7_R2.IInventory;
|
||||||
import net.minecraft.server.v1_7_R2.InventoryLargeChest;
|
import net.minecraft.server.v1_7_R2.InventoryLargeChest;
|
||||||
@@ -34,54 +36,27 @@ import net.minecraft.server.v1_7_R2.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
int id = Block.b(world.getType(x, y, z));
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
if (Block.b(world.getType(x - 1, y, z)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||||
@@ -91,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -104,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -121,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,13 +18,15 @@ package com.lishid.openinv.internal.v1_7_R3;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_7_R3.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_7_R3.Block;
|
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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_7_R3.IInventory;
|
import net.minecraft.server.v1_7_R3.IInventory;
|
||||||
import net.minecraft.server.v1_7_R3.InventoryLargeChest;
|
import net.minecraft.server.v1_7_R3.InventoryLargeChest;
|
||||||
@@ -34,54 +36,27 @@ import net.minecraft.server.v1_7_R3.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R3.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = Block.b(world.getType(x, y, z));
|
int id = Block.b(world.getType(x, y, z));
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Block.b(world.getType(x - 1, y, z)) == id)
|
if (Block.b(world.getType(x - 1, y, z)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||||
@@ -91,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -104,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -121,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,13 +18,15 @@ package com.lishid.openinv.internal.v1_7_R4;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
|
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_7_R4.Block;
|
import net.minecraft.server.v1_7_R4.Block;
|
||||||
|
import net.minecraft.server.v1_7_R4.EntityOcelot;
|
||||||
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
import net.minecraft.server.v1_7_R4.EntityPlayer;
|
||||||
import net.minecraft.server.v1_7_R4.IInventory;
|
import net.minecraft.server.v1_7_R4.IInventory;
|
||||||
import net.minecraft.server.v1_7_R4.InventoryLargeChest;
|
import net.minecraft.server.v1_7_R4.InventoryLargeChest;
|
||||||
@@ -34,54 +36,27 @@ import net.minecraft.server.v1_7_R4.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(x, y, z));
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(x, y, z);
|
Object chest = world.getTileEntity(x, y, z);
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = Block.getId(world.getType(x, y, z));
|
int id = Block.getId(world.getType(x, y, z));
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(x, y + 1, z).c())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(x - 1, y, z)) == id)
|
if (Block.getId(world.getType(x - 1, y, z)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||||
if (Block.getId(world.getType(x + 1, y, z)) == id)
|
if (Block.getId(world.getType(x + 1, y, z)) == id)
|
||||||
@@ -91,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (Block.getId(world.getType(x, y, z + 1)) == id)
|
if (Block.getId(world.getType(x, y, z + 1)) == id)
|
||||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
int windowId = 0;
|
int windowId = 0;
|
||||||
try {
|
try {
|
||||||
@@ -104,16 +79,14 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
windowId = windowID.getInt(player);
|
windowId = windowID.getInt(player);
|
||||||
windowId = windowId % 100 + 1;
|
windowId = windowId % 100 + 1;
|
||||||
windowID.setInt(player, windowId);
|
windowID.setInt(player, windowId);
|
||||||
}
|
} catch (NoSuchFieldException e) {}
|
||||||
catch (NoSuchFieldException e) {}
|
|
||||||
|
|
||||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -121,4 +94,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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.getId(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.getId(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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -16,13 +16,16 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R1;
|
package com.lishid.openinv.internal.v1_8_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
//Volatile
|
||||||
|
import net.minecraft.server.v1_8_R1.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_8_R1.Block;
|
import net.minecraft.server.v1_8_R1.Block;
|
||||||
import net.minecraft.server.v1_8_R1.BlockPosition;
|
import net.minecraft.server.v1_8_R1.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_8_R1.EntityOcelot;
|
||||||
import net.minecraft.server.v1_8_R1.EntityPlayer;
|
import net.minecraft.server.v1_8_R1.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R1.IInventory;
|
import net.minecraft.server.v1_8_R1.IInventory;
|
||||||
import net.minecraft.server.v1_8_R1.ITileInventory;
|
import net.minecraft.server.v1_8_R1.ITileInventory;
|
||||||
@@ -31,57 +34,29 @@ import net.minecraft.server.v1_8_R1.PacketPlayOutOpenWindow;
|
|||||||
import net.minecraft.server.v1_8_R1.TileEntityChest;
|
import net.minecraft.server.v1_8_R1.TileEntityChest;
|
||||||
import net.minecraft.server.v1_8_R1.World;
|
import net.minecraft.server.v1_8_R1.World;
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
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);
|
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)
|
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
||||||
@@ -91,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
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)));
|
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
||||||
int windowId = player.nextContainerCounter();
|
int windowId = player.nextContainerCounter();
|
||||||
@@ -103,9 +78,8 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
player.activeContainer = silentContainerChest;
|
player.activeContainer = silentContainerChest;
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -113,4 +87,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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)).getBlock().c() || 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) {
|
||||||
|
if (Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()) != id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -16,13 +16,16 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R2;
|
package com.lishid.openinv.internal.v1_8_R2;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
//Volatile
|
||||||
|
import net.minecraft.server.v1_8_R2.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_8_R2.Block;
|
import net.minecraft.server.v1_8_R2.Block;
|
||||||
import net.minecraft.server.v1_8_R2.BlockPosition;
|
import net.minecraft.server.v1_8_R2.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_8_R2.EntityOcelot;
|
||||||
import net.minecraft.server.v1_8_R2.EntityPlayer;
|
import net.minecraft.server.v1_8_R2.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R2.IInventory;
|
import net.minecraft.server.v1_8_R2.IInventory;
|
||||||
import net.minecraft.server.v1_8_R2.ITileInventory;
|
import net.minecraft.server.v1_8_R2.ITileInventory;
|
||||||
@@ -31,57 +34,29 @@ import net.minecraft.server.v1_8_R2.PacketPlayOutOpenWindow;
|
|||||||
import net.minecraft.server.v1_8_R2.TileEntityChest;
|
import net.minecraft.server.v1_8_R2.TileEntityChest;
|
||||||
import net.minecraft.server.v1_8_R2.World;
|
import net.minecraft.server.v1_8_R2.World;
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
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);
|
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)
|
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
||||||
@@ -91,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
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)));
|
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
||||||
int windowId = player.nextContainerCounter();
|
int windowId = player.nextContainerCounter();
|
||||||
@@ -103,9 +78,8 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
player.activeContainer = silentContainerChest;
|
player.activeContainer = silentContainerChest;
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -113,4 +87,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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)).getBlock().c() || 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) {
|
||||||
|
if (Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()) != id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -16,13 +16,16 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_8_R3;
|
package com.lishid.openinv.internal.v1_8_R3;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
//Volatile
|
||||||
|
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_8_R3.Block;
|
import net.minecraft.server.v1_8_R3.Block;
|
||||||
import net.minecraft.server.v1_8_R3.BlockPosition;
|
import net.minecraft.server.v1_8_R3.BlockPosition;
|
||||||
|
import net.minecraft.server.v1_8_R3.EntityOcelot;
|
||||||
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
import net.minecraft.server.v1_8_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R3.IInventory;
|
import net.minecraft.server.v1_8_R3.IInventory;
|
||||||
import net.minecraft.server.v1_8_R3.ITileInventory;
|
import net.minecraft.server.v1_8_R3.ITileInventory;
|
||||||
@@ -31,57 +34,29 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutOpenWindow;
|
|||||||
import net.minecraft.server.v1_8_R3.TileEntityChest;
|
import net.minecraft.server.v1_8_R3.TileEntityChest;
|
||||||
import net.minecraft.server.v1_8_R3.World;
|
import net.minecraft.server.v1_8_R3.World;
|
||||||
|
|
||||||
//Volatile
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||||
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
return block instanceof org.bukkit.block.Chest;
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
|
||||||
World world = player.world;
|
|
||||||
// If block on top
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
// If block next to chest is chest and has a block on top
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
||||||
if (chest == null)
|
if (chest == null)
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
|
if (!anychest && isAnyContainerNeeded(p, x, y, z)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id)
|
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);
|
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)
|
if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id)
|
||||||
@@ -91,11 +66,11 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id)
|
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)));
|
chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1)));
|
||||||
|
|
||||||
boolean returnValue = true;
|
boolean returnValue = false;
|
||||||
if (!silentchest) {
|
if (!silentchest) {
|
||||||
player.openContainer((IInventory) chest);
|
player.openContainer((IInventory) chest);
|
||||||
}
|
returnValue = true;
|
||||||
else {
|
} else {
|
||||||
try {
|
try {
|
||||||
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player);
|
||||||
int windowId = player.nextContainerCounter();
|
int windowId = player.nextContainerCounter();
|
||||||
@@ -103,9 +78,8 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
player.activeContainer = silentContainerChest;
|
player.activeContainer = silentContainerChest;
|
||||||
player.activeContainer.windowId = windowId;
|
player.activeContainer.windowId = windowId;
|
||||||
player.activeContainer.addSlotListener(player);
|
player.activeContainer.addSlotListener(player);
|
||||||
returnValue = false;
|
returnValue = true;
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||||
}
|
}
|
||||||
@@ -113,4 +87,64 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
|
|
||||||
return returnValue;
|
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)).getBlock().c() || 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) {
|
||||||
|
if (Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()) != id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R1;
|
package com.lishid.openinv.internal.v1_9_R1;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
import net.minecraft.server.v1_9_R1.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_9_R1.Block;
|
import net.minecraft.server.v1_9_R1.Block;
|
||||||
@@ -37,12 +37,64 @@ import net.minecraft.server.v1_9_R1.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block 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
|
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
|
|
||||||
// If block or ocelot on top
|
// If block or ocelot on top
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
||||||
return true;
|
return true;
|
||||||
@@ -50,16 +102,8 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
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
|
// If block next to chest is chest and has a block or ocelot on top
|
||||||
if (isBlockedChest(world, id, x - 1, y, z))
|
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
||||||
return true;
|
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
||||||
if (isBlockedChest(world, id, x + 1, y, z))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z - 1))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z + 1))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
||||||
@@ -87,58 +131,22 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
return !activateContainer(player, anychest, silentchest, x, y, z);
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = true;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
}
|
|
||||||
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 = false;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package com.lishid.openinv.internal.v1_9_R2;
|
package com.lishid.openinv.internal.v1_9_R2;
|
||||||
|
|
||||||
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
|
||||||
|
|
||||||
// Volatile
|
// Volatile
|
||||||
import net.minecraft.server.v1_9_R2.AxisAlignedBB;
|
import net.minecraft.server.v1_9_R2.AxisAlignedBB;
|
||||||
import net.minecraft.server.v1_9_R2.Block;
|
import net.minecraft.server.v1_9_R2.Block;
|
||||||
@@ -37,12 +37,64 @@ import net.minecraft.server.v1_9_R2.World;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
||||||
|
|
||||||
public class AnySilentChest implements IAnySilentChest {
|
public class AnySilentContainer implements IAnySilentContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnyChestNeeded(Player p, int x, int y, int z) {
|
public boolean isAnySilentContainer(org.bukkit.block.Block 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
|
// FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
||||||
World world = player.world;
|
World world = player.world;
|
||||||
|
|
||||||
// If block or ocelot on top
|
// If block or ocelot on top
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
if (world.getType(new BlockPosition(x, y + 1, z)).l() || hasOcelotOnTop(world, x, y, z))
|
||||||
return true;
|
return true;
|
||||||
@@ -50,16 +102,8 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
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
|
// If block next to chest is chest and has a block or ocelot on top
|
||||||
if (isBlockedChest(world, id, x - 1, y, z))
|
return isBlockedChest(world, id, x - 1, y, z) || isBlockedChest(world, id, x + 1, y, z)
|
||||||
return true;
|
|| isBlockedChest(world, id, x, y, z - 1) || isBlockedChest(world, id, x, y, z + 1);
|
||||||
if (isBlockedChest(world, id, x + 1, y, z))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z - 1))
|
|
||||||
return true;
|
|
||||||
if (isBlockedChest(world, id, x, y, z + 1))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
private boolean isBlockedChest(World world, int id, int x, int y, int z) {
|
||||||
@@ -87,58 +131,22 @@ public class AnySilentChest implements IAnySilentChest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public boolean activateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
public boolean activateChest(Player player, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||||
EntityPlayer player = ((CraftPlayer) p).getHandle();
|
return !activateContainer(player, anychest, silentchest, x, y, z);
|
||||||
World world = player.world;
|
|
||||||
Object chest = world.getTileEntity(new BlockPosition(x, y, z));
|
|
||||||
if (chest == null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock());
|
|
||||||
|
|
||||||
if (!anychest) {
|
|
||||||
if (world.getType(new BlockPosition(x, y + 1, z)).l())
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).l()))
|
|
||||||
return true;
|
|
||||||
if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).l()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = true;
|
|
||||||
if (!silentchest) {
|
|
||||||
player.openContainer((IInventory) chest);
|
|
||||||
}
|
|
||||||
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 = false;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -27,7 +27,7 @@ import com.lishid.openinv.commands.OpenEnderPluginCommand;
|
|||||||
import com.lishid.openinv.commands.OpenInvPluginCommand;
|
import com.lishid.openinv.commands.OpenInvPluginCommand;
|
||||||
import com.lishid.openinv.commands.SearchInvPluginCommand;
|
import com.lishid.openinv.commands.SearchInvPluginCommand;
|
||||||
import com.lishid.openinv.commands.SilentChestPluginCommand;
|
import com.lishid.openinv.commands.SilentChestPluginCommand;
|
||||||
import com.lishid.openinv.internal.IAnySilentChest;
|
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||||
import com.lishid.openinv.internal.IInventoryAccess;
|
import com.lishid.openinv.internal.IInventoryAccess;
|
||||||
import com.lishid.openinv.internal.IPlayerDataManager;
|
import com.lishid.openinv.internal.IPlayerDataManager;
|
||||||
import com.lishid.openinv.internal.ISpecialEnderChest;
|
import com.lishid.openinv.internal.ISpecialEnderChest;
|
||||||
@@ -97,7 +97,7 @@ public class OpenInv extends JavaPlugin {
|
|||||||
private InternalAccessor accessor;
|
private InternalAccessor accessor;
|
||||||
private IPlayerDataManager playerLoader;
|
private IPlayerDataManager playerLoader;
|
||||||
private IInventoryAccess inventoryAccess;
|
private IInventoryAccess inventoryAccess;
|
||||||
private IAnySilentChest anySilentChest;
|
private IAnySilentContainer anySilentContainer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -115,7 +115,7 @@ public class OpenInv extends JavaPlugin {
|
|||||||
|
|
||||||
playerLoader = accessor.newPlayerDataManager();
|
playerLoader = accessor.newPlayerDataManager();
|
||||||
inventoryAccess = accessor.newInventoryAccess();
|
inventoryAccess = accessor.newInventoryAccess();
|
||||||
anySilentChest = accessor.newAnySilentChest();
|
anySilentContainer = accessor.newAnySilentContainer();
|
||||||
|
|
||||||
FileConfiguration config = getConfig();
|
FileConfiguration config = getConfig();
|
||||||
boolean dirtyConfig = false;
|
boolean dirtyConfig = false;
|
||||||
@@ -164,8 +164,16 @@ public class OpenInv extends JavaPlugin {
|
|||||||
return this.inventoryAccess;
|
return this.inventoryAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAnySilentChest getAnySilentChest() {
|
public IAnySilentContainer getAnySilentContainer() {
|
||||||
return this.anySilentChest;
|
return this.anySilentContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #getAnySilentContainer()}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public com.lishid.openinv.internal.IAnySilentChest getAnySilentChest() {
|
||||||
|
return this.getAnySilentContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISpecialPlayerInventory getInventoryFor(Player player, boolean online) {
|
public ISpecialPlayerInventory getInventoryFor(Player player, boolean online) {
|
||||||
|
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.lishid.openinv;
|
package com.lishid.openinv;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.block.Chest;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event.Result;
|
import org.bukkit.event.Event.Result;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@@ -46,53 +44,41 @@ public class OpenInvPlayerListener implements Listener {
|
|||||||
plugin.setPlayerOffline(event.getPlayer());
|
plugin.setPlayerOffline(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getPlayer().isSneaking()
|
||||||
|
|| event.useInteractedBlock() == Result.DENY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (event.getPlayer().isSneaking()) {
|
if (event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) {
|
||||||
return;
|
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT)
|
||||||
}
|
&& plugin.getPlayerSilentChestStatus(player)) {
|
||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == org.bukkit.Material.ENDER_CHEST) {
|
|
||||||
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
player.openInventory(player.getEnderChest());
|
player.openInventory(player.getEnderChest());
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest) {
|
if (plugin.getAnySilentContainer().isAnySilentContainer(event.getClickedBlock())) {
|
||||||
boolean silentchest = false;
|
|
||||||
boolean anychest = false;
|
boolean silentchest = OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player);
|
||||||
|
boolean anychest = OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && plugin.getPlayerAnyChestStatus(player);
|
||||||
|
|
||||||
int x = event.getClickedBlock().getX();
|
int x = event.getClickedBlock().getX();
|
||||||
int y = event.getClickedBlock().getY();
|
int y = event.getClickedBlock().getY();
|
||||||
int z = event.getClickedBlock().getZ();
|
int z = event.getClickedBlock().getZ();
|
||||||
|
|
||||||
if (OpenInv.hasPermission(player, Permissions.PERM_SILENT) && plugin.getPlayerSilentChestStatus(player)) {
|
// If anychest or silentchest is active
|
||||||
silentchest = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OpenInv.hasPermission(player, Permissions.PERM_ANYCHEST) && plugin.getPlayerAnyChestStatus(player)) {
|
|
||||||
try {
|
|
||||||
anychest = plugin.getAnySilentChest().isAnyChestNeeded(player, x, y, z);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
player.sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the anychest or silentchest is active
|
|
||||||
if (anychest || silentchest) {
|
if (anychest || silentchest) {
|
||||||
if (!plugin.getAnySilentChest().activateChest(player, anychest, silentchest, x, y, z)) {
|
if (plugin.getAnySilentContainer().activateContainer(player, anychest, silentchest, x, y, z)) {
|
||||||
if (silentchest && plugin.notifySilentChest()) {
|
if (silentchest && plugin.notifySilentChest() && anychest && plugin.notifyAnyChest()) {
|
||||||
|
player.sendMessage("You are opening a blocked chest silently.");
|
||||||
|
} else if (silentchest && plugin.notifySilentChest()) {
|
||||||
player.sendMessage("You are opening a chest silently.");
|
player.sendMessage("You are opening a chest silently.");
|
||||||
}
|
} else if (anychest && plugin.notifyAnyChest()) {
|
||||||
if (anychest && plugin.notifyAnyChest()) {
|
|
||||||
player.sendMessage("You are opening a blocked chest.");
|
player.sendMessage("You are opening a blocked chest.");
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
@@ -63,8 +63,16 @@ public class InternalAccessor {
|
|||||||
return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess");
|
return (IInventoryAccess) createObject(IInventoryAccess.class, "InventoryAccess");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IAnySilentContainer newAnySilentContainer() {
|
||||||
|
return (IAnySilentContainer) createObject(IAnySilentContainer.class, "AnySilentContainer");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link #newAnySilentContainer()}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public IAnySilentChest newAnySilentChest() {
|
public IAnySilentChest newAnySilentChest() {
|
||||||
return (IAnySilentChest) createObject(IAnySilentChest.class, "AnySilentChest");
|
return newAnySilentContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) {
|
public ISpecialPlayerInventory newSpecialPlayerInventory(Player player, boolean offline) {
|
||||||
|
10
README.MD
10
README.MD
@@ -9,6 +9,16 @@ This fork of OpenInv was created when the lag caused by offline player lookups p
|
|||||||
## Previous Versions
|
## Previous Versions
|
||||||
This fork supports any version after 1.4.5. Binaries are available in the [releases tab](https://github.com/Jikoo/OpenInv/releases). Please allow a brief period after the release of a new version for updates.
|
This fork supports any version after 1.4.5. Binaries are available in the [releases tab](https://github.com/Jikoo/OpenInv/releases). Please allow a brief period after the release of a new version for updates.
|
||||||
|
|
||||||
|
## For Developers
|
||||||
|
To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin.
|
||||||
|
Ex: `install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT`
|
||||||
|
|
||||||
|
Compiling OpenInv for a specific version is very easy - just compile the correct module.
|
||||||
|
|
||||||
|
Compiling for a set of versions is slightly more complex. You'll need to use a profile for the versions you want to compile. Provided profiles are latest, modern (versions 1.7.10+), and all. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html).
|
||||||
|
|
||||||
|
Regarding deprecation: Any deprecated methods will be removed in the next minor revision bump.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
```
|
```
|
||||||
Copyright (C) 2011-2014 lishid. All rights reserved.
|
Copyright (C) 2011-2014 lishid. All rights reserved.
|
||||||
|
Reference in New Issue
Block a user