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_8_R3;
 | 
			
		||||
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
 | 
			
		||||
@@ -40,32 +40,31 @@ import org.bukkit.craftbukkit.v1_8_R3.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) {
 | 
			
		||||
@@ -131,12 +130,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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,7 @@ package com.lishid.openinv.internal.v1_8_R3;
 | 
			
		||||
import net.minecraft.server.v1_8_R3.ContainerChest;
 | 
			
		||||
import net.minecraft.server.v1_8_R3.EntityHuman;
 | 
			
		||||
import net.minecraft.server.v1_8_R3.IInventory;
 | 
			
		||||
import net.minecraft.server.v1_8_R3.ItemStack;
 | 
			
		||||
import net.minecraft.server.v1_8_R3.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