Fix SPIGOT-2806 for silent chests, various other issues
* Fixed anychest message spam * Changed AnySilentContainer again to reduce duplicate checks * #isAnyContainerNeeded should be checked before calling #activateContainer * reorganized ifs for doublechest creation into reverse-order if elses to prevent creating extras when someone's broken Minecraft and put 3+ adjacent to each other * Fixed incorrect block being checked for anychest in 1.11 * Progress on SilentContainerShulkerBox (we're getting there!) anychest and silentchest aren't quite at 100% after all these changes, but it won't be a priority to revisit logic until shulker boxes are done
This commit is contained in:
@@ -19,7 +19,7 @@ package com.lishid.openinv.internal.v1_10_R1;
|
||||
import com.lishid.openinv.internal.IAnySilentContainer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// Volatile
|
||||
@@ -41,32 +41,31 @@ import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||
public class AnySilentContainer implements IAnySilentContainer {
|
||||
|
||||
@Override
|
||||
public boolean isAnySilentContainer(BlockState block) {
|
||||
return block instanceof org.bukkit.block.Chest;
|
||||
public boolean isAnySilentContainer(org.bukkit.block.Block block) {
|
||||
return block.getType() == Material.ENDER_CHEST || block.getState() instanceof org.bukkit.block.Chest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateContainer(Player p, boolean anychest, boolean silentchest, int x, int y, int z) {
|
||||
public boolean activateContainer(Player p, 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)) {
|
||||
if (chest == null) {
|
||||
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)
|
||||
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)));
|
||||
} else 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);
|
||||
} else 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)));
|
||||
} else 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);
|
||||
}
|
||||
|
||||
boolean returnValue = false;
|
||||
if (!silentchest) {
|
||||
@@ -97,8 +96,9 @@ public class AnySilentContainer implements IAnySilentContainer {
|
||||
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))
|
||||
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());
|
||||
|
||||
@@ -133,12 +133,12 @@ public class AnySilentContainer implements IAnySilentContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #activateContainer(Player, boolean, boolean, int, int, int)}.
|
||||
* @deprecated Use {@link #activateContainer(Player, 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);
|
||||
return !activateContainer(player, silentchest, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -31,10 +31,11 @@ import net.minecraft.server.v1_10_R1.IInventory;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
|
||||
@Override
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = grabInventory(inventory);
|
||||
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
|
||||
return false;
|
||||
@@ -51,24 +52,24 @@ public class InventoryAccess implements IInventoryAccess {
|
||||
}
|
||||
|
||||
private IInventory grabInventory(Inventory inventory) {
|
||||
if(inventory instanceof CraftInventory) {
|
||||
if (inventory instanceof CraftInventory) {
|
||||
return ((CraftInventory) inventory).getInventory();
|
||||
}
|
||||
|
||||
//Use reflection to find the iinventory
|
||||
|
||||
// Use reflection to find the iinventory
|
||||
Class<? extends Inventory> clazz = inventory.getClass();
|
||||
IInventory result = null;
|
||||
for(Field f : clazz.getDeclaredFields()) {
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
f.setAccessible(true);
|
||||
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
||||
if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
|
||||
try {
|
||||
result = (IInventory) f.get(inventory);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ package com.lishid.openinv.internal.v1_10_R1;
|
||||
import net.minecraft.server.v1_10_R1.ContainerChest;
|
||||
import net.minecraft.server.v1_10_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_10_R1.IInventory;
|
||||
import net.minecraft.server.v1_10_R1.ItemStack;
|
||||
import net.minecraft.server.v1_10_R1.PlayerInventory;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
@@ -38,8 +39,9 @@ public class SilentContainerChest extends ContainerChest {
|
||||
PlayerInventory playerinventory = entityHuman.inventory;
|
||||
|
||||
if (playerinventory.getCarried() != null) {
|
||||
entityHuman.drop(playerinventory.getCarried(), false);
|
||||
ItemStack carried = playerinventory.getCarried();
|
||||
playerinventory.setCarried(null);
|
||||
entityHuman.drop(carried, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user