From e100dff6ab356972c4e0131cdc28b9e5a4c3664f Mon Sep 17 00:00:00 2001 From: Jikoo Date: Thu, 17 Nov 2016 02:34:52 -0500 Subject: [PATCH] Update for 1.11 --- OpenInv/pom.xml | 2 +- OpenInvCraftbukkit1_11_R1/pom.xml | 32 +++ .../internal/v1_11_R1/AnySilentChest.java | 144 ++++++++++ .../internal/v1_11_R1/InventoryAccess.java | 74 +++++ .../internal/v1_11_R1/PlayerDataManager.java | 62 +++++ .../v1_11_R1/SilentContainerChest.java | 45 +++ .../internal/v1_11_R1/SpecialEnderChest.java | 105 +++++++ .../v1_11_R1/SpecialPlayerInventory.java | 257 ++++++++++++++++++ pom.xml | 20 +- 9 files changed, 735 insertions(+), 6 deletions(-) create mode 100644 OpenInvCraftbukkit1_11_R1/pom.xml create mode 100644 OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentChest.java create mode 100644 OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/InventoryAccess.java create mode 100644 OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java create mode 100644 OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SilentContainerChest.java create mode 100644 OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialEnderChest.java create mode 100644 OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialPlayerInventory.java diff --git a/OpenInv/pom.xml b/OpenInv/pom.xml index e975cef..d4005fe 100644 --- a/OpenInv/pom.xml +++ b/OpenInv/pom.xml @@ -8,7 +8,7 @@ openinv OpenInv - 2.5.1 + 2.5.2 ../target diff --git a/OpenInvCraftbukkit1_11_R1/pom.xml b/OpenInvCraftbukkit1_11_R1/pom.xml new file mode 100644 index 0000000..cb15387 --- /dev/null +++ b/OpenInvCraftbukkit1_11_R1/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + + + com.lishid + openinvparent + 1.0-SNAPSHOT + + + OpenInvCraftbukkit1_11_R1 + OpenInvCraftbukkit1_11_R1 + + + + com.lishid + openinvcore + 1.0-SNAPSHOT + + + com.lishid + openinvplugin + 1.0-SNAPSHOT + + + org.spigotmc + spigot + 1.11-R0.1-SNAPSHOT + provided + + + diff --git a/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentChest.java b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentChest.java new file mode 100644 index 0000000..9652f5b --- /dev/null +++ b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/AnySilentChest.java @@ -0,0 +1,144 @@ +/* + * 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 . + */ + +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; + } +} diff --git a/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/InventoryAccess.java b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/InventoryAccess.java new file mode 100644 index 0000000..dc40405 --- /dev/null +++ b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/InventoryAccess.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011-2014 lishid. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lishid.openinv.internal.v1_11_R1; + +import java.lang.reflect.Field; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.Inventory; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.Permissions; +import com.lishid.openinv.internal.IInventoryAccess; + +// Volatile +import net.minecraft.server.v1_11_R1.IInventory; + +import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory; + +public class InventoryAccess implements IInventoryAccess { + @Override + public boolean check(Inventory inventory, HumanEntity player) { + IInventory inv = grabInventory(inventory); + + if (inv instanceof SpecialPlayerInventory) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { + return false; + } + } + + else if (inv instanceof SpecialEnderChest) { + if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { + return false; + } + } + + return true; + } + + private IInventory grabInventory(Inventory inventory) { + if(inventory instanceof CraftInventory) { + return ((CraftInventory) inventory).getInventory(); + } + + //Use reflection to find the iinventory + Class clazz = inventory.getClass(); + IInventory result = null; + for(Field f : clazz.getDeclaredFields()) { + f.setAccessible(true); + if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) { + try { + result = (IInventory) f.get(inventory); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + return result; + } +} diff --git a/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java new file mode 100644 index 0000000..f538dfb --- /dev/null +++ b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/PlayerDataManager.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2011-2014 lishid. All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lishid.openinv.internal.v1_11_R1; + +import com.lishid.openinv.internal.IPlayerDataManager; + +import com.mojang.authlib.GameProfile; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +// Volatile +import net.minecraft.server.v1_11_R1.EntityPlayer; +import net.minecraft.server.v1_11_R1.MinecraftServer; +import net.minecraft.server.v1_11_R1.PlayerInteractManager; + +import org.bukkit.craftbukkit.v1_11_R1.CraftServer; + +public class PlayerDataManager implements IPlayerDataManager { + + @Override + public Player loadPlayer(OfflinePlayer offline) { + if (offline == null || !offline.hasPlayedBefore()) { + return null; + } + GameProfile profile = new GameProfile(offline.getUniqueId(), offline.getName()); + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + // Create an entity to load the player data + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + + // Get the bukkit entity + Player target = (entity == null) ? null : entity.getBukkitEntity(); + if (target != null) { + // Load data + target.loadData(); + // Return the entity + return target; + } + return null; + } + + @Override + public String getPlayerDataID(OfflinePlayer player) { + return player.getUniqueId().toString(); + } + +} diff --git a/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SilentContainerChest.java b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SilentContainerChest.java new file mode 100644 index 0000000..4512f7a --- /dev/null +++ b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SilentContainerChest.java @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +package com.lishid.openinv.internal.v1_11_R1; + +// Volatile +import net.minecraft.server.v1_11_R1.ContainerChest; +import net.minecraft.server.v1_11_R1.EntityHuman; +import net.minecraft.server.v1_11_R1.IInventory; +import net.minecraft.server.v1_11_R1.PlayerInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) { + super(i1, i2, e1); + inv = i2; + // close signal + inv.closeContainer(e1); + } + + @Override + public void b(EntityHuman entityHuman) { + // Don't send close signal twice, might screw up + PlayerInventory playerinventory = entityHuman.inventory; + + if (playerinventory.getCarried() != null) { + entityHuman.drop(playerinventory.getCarried(), false); + playerinventory.setCarried(null); + } + } +} diff --git a/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialEnderChest.java b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialEnderChest.java new file mode 100644 index 0000000..e90c028 --- /dev/null +++ b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialEnderChest.java @@ -0,0 +1,105 @@ +/* + * 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 . + */ + +package com.lishid.openinv.internal.v1_11_R1; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.List; + +import com.lishid.openinv.internal.ISpecialEnderChest; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +// Volatile +import net.minecraft.server.v1_11_R1.IInventory; +import net.minecraft.server.v1_11_R1.InventoryEnderChest; +import net.minecraft.server.v1_11_R1.InventorySubcontainer; +import net.minecraft.server.v1_11_R1.ItemStack; + +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + + private final InventoryEnderChest enderChest; + private final CraftInventory inventory = new CraftInventory(this); + public boolean playerOnline = false; + + public SpecialEnderChest(Player player, Boolean online) { + super(((CraftPlayer) player).getHandle().getEnderChest().getName(), ((CraftPlayer) player).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) player).getHandle().getEnderChest().getSize()); + CraftPlayer craftPlayer = (CraftPlayer) player; + this.enderChest = craftPlayer.getHandle().getEnderChest(); + this.bukkitOwner = craftPlayer; + setItemLists(this, enderChest.getContents()); + } + + private void setItemLists(InventorySubcontainer subcontainer, List list) { + try { + // Prepare to remove final modifier + Field modifiers = Field.class.getDeclaredField("modifiers"); + modifiers.setAccessible(true); + // Access and replace main inventory array + Field field = InventorySubcontainer.class.getField("items"); + modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(subcontainer, list); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public void setPlayerOnline(Player player) { + if (!playerOnline) { + try { + this.bukkitOwner = player; + CraftPlayer craftPlayer = (CraftPlayer) player; + setItemLists(craftPlayer.getHandle().getEnderChest(), this.items); + } + catch (Exception e) {} + playerOnline = true; + } + } + + @Override + public void setPlayerOffline() { + playerOnline = false; + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); + } + + @Override + public void update() { + super.update(); + enderChest.update(); + } + +} diff --git a/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialPlayerInventory.java b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialPlayerInventory.java new file mode 100644 index 0000000..b325b47 --- /dev/null +++ b/OpenInvCraftbukkit1_11_R1/src/main/java/com/lishid/openinv/internal/v1_11_R1/SpecialPlayerInventory.java @@ -0,0 +1,257 @@ +/* + * 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 . + */ + +package com.lishid.openinv.internal.v1_11_R1; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Arrays; + +import com.lishid.openinv.internal.ISpecialPlayerInventory; + +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; + +import net.minecraft.server.v1_11_R1.ContainerUtil; +// Volatile +import net.minecraft.server.v1_11_R1.EntityHuman; +import net.minecraft.server.v1_11_R1.ItemStack; +import net.minecraft.server.v1_11_R1.NonNullList; +import net.minecraft.server.v1_11_R1.PlayerInventory; + +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory; + +public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { + + private final CraftInventory inventory = new CraftInventory(this); + private boolean playerOnline = false; + + public SpecialPlayerInventory(Player bukkitPlayer, Boolean online) { + super(((CraftPlayer) bukkitPlayer).getHandle()); + this.playerOnline = online; + setItemArrays(this, player.inventory.items, player.inventory.armor, player.inventory.extraSlots); + } + + private void setItemArrays(PlayerInventory inventory, NonNullList items, + NonNullList armor, NonNullList extraSlots) { + try { + // Prepare to remove final modifier + Field modifiers = Field.class.getDeclaredField("modifiers"); + modifiers.setAccessible(true); + + // Access and replace main inventory array + Field field = PlayerInventory.class.getField("items"); + modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(inventory, items); + + // Access and replace armor inventory array + field = PlayerInventory.class.getField("armor"); + modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(inventory, armor); + + // Access and replace offhand inventory array + field = PlayerInventory.class.getField("extraSlots"); + modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(inventory, extraSlots); + + // Access and replace array containing all inventory arrays + field = PlayerInventory.class.getDeclaredField("g"); + field.setAccessible(true); + modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(inventory, Arrays.asList(new NonNullList[] { items, armor, extraSlots })); + } catch (NoSuchFieldException e) { + // Unable to set final fields to item arrays, we're screwed. Noisily fail. + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public void setPlayerOnline(Player player) { + if (!playerOnline) { + this.player = ((CraftPlayer) player).getHandle(); + setItemArrays(this.player.inventory, items, armor, extraSlots); + playerOnline = true; + } + } + + @Override + public void setPlayerOffline() { + playerOnline = false; + } + + @Override + public boolean isInUse() { + return !this.getViewers().isEmpty(); + } + + @Override + public int getSize() { + return super.getSize() + 4; + } + + @Override + public ItemStack getItem(int i) { + NonNullList list = this.items; + + if (i >= list.size()) { + i -= list.size(); + list = this.armor; + } else { + i = getReversedItemSlotNum(i); + } + + if (i >= list.size()) { + i -= list.size(); + list = this.extraSlots; + } else if (list == this.armor) { + i = getReversedArmorSlotNum(i); + } + + if (i >= list.size()) { + return ItemStack.a; + } + + return list.get(i); + } + + @Override + public ItemStack splitStack(int i, int j) { + NonNullList list = this.items; + + if (i >= list.size()) { + i -= list.size(); + list = this.armor; + } else { + i = getReversedItemSlotNum(i); + } + + if (i >= list.size()) { + i -= list.size(); + list = this.extraSlots; + } else if (list == this.armor) { + i = getReversedArmorSlotNum(i); + } + + if (i >= list.size()) { + return ItemStack.a; + } + + return list == null || list.get(i).isEmpty() ? ItemStack.a : ContainerUtil.a(list, i, j); + } + + @Override + public ItemStack splitWithoutUpdate(int i) { + NonNullList list = this.items; + + if (i >= list.size()) { + i -= list.size(); + list = this.armor; + } else { + i = getReversedItemSlotNum(i); + } + + if (i >= list.size()) { + i -= list.size(); + list = this.extraSlots; + } else if (list == this.armor) { + i = getReversedArmorSlotNum(i); + } + + if (i >= list.size()) { + return ItemStack.a; + } + + if (list != null && !list.get(i).isEmpty()) { + ItemStack itemstack = list.get(i); + + list.set(i, ItemStack.a); + return itemstack; + } + + return ItemStack.a; + } + + @Override + public void setItem(int i, ItemStack itemstack) { + NonNullList list = this.items; + + if (i >= list.size()) { + i -= list.size(); + list = this.armor; + } else { + i = getReversedItemSlotNum(i); + } + + if (i >= list.size()) { + i -= list.size(); + list = this.extraSlots; + } else if (list == this.armor) { + i = getReversedArmorSlotNum(i); + } + + if (i >= list.size()) { + player.drop(itemstack, true); + return; + } + + if (list != null) { + list.set(i, itemstack); + } + } + + private int getReversedItemSlotNum(int i) { + if (i >= 27) + return i - 27; + else + return i + 9; + } + + private int getReversedArmorSlotNum(int i) { + if (i == 0) + return 3; + if (i == 1) + return 2; + if (i == 2) + return 1; + if (i == 3) + return 0; + else + return i; + } + + @Override + public String getName() { + if (player.getName().length() > 16) { + return player.getName().substring(0, 16); + } + return player.getName(); + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } +} diff --git a/pom.xml b/pom.xml index 032993e..3c00ff5 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ OpenInvCore OpenInvPlugin OpenInv + OpenInvCraftbukkit1_11_R1 @@ -27,12 +28,12 @@ - OpenInvCraftbukkit1_10_R1 + OpenInvCraftbukkit1_11_R1 com.lishid - openinvcraftbukkit1_10_R1 + openinvcraftbukkit1_11_R1 1.0-SNAPSHOT @@ -47,9 +48,6 @@ - OpenInvCraftbukkit1_7_R1 - OpenInvCraftbukkit1_7_R2 - OpenInvCraftbukkit1_7_R3 OpenInvCraftbukkit1_7_R4 OpenInvCraftbukkit1_8_R1 OpenInvCraftbukkit1_8_R2 @@ -57,6 +55,7 @@ OpenInvCraftbukkit1_9_R1 OpenInvCraftbukkit1_9_R2 OpenInvCraftbukkit1_10_R1 + OpenInvCraftbukkit1_11_R1 @@ -94,6 +93,11 @@ openinvcraftbukkit1_10_R1 1.0-SNAPSHOT + + com.lishid + openinvcraftbukkit1_11_R1 + 1.0-SNAPSHOT + @@ -124,6 +128,7 @@ OpenInvCraftbukkit1_9_R1 OpenInvCraftbukkit1_9_R2 OpenInvCraftbukkit1_10_R1 + OpenInvCraftbukkit1_11_R1 @@ -216,6 +221,11 @@ openinvcraftbukkit1_10_R1 1.0-SNAPSHOT + + com.lishid + openinvcraftbukkit1_11_R1 + 1.0-SNAPSHOT +