New formatting.
This commit is contained in:
@@ -29,19 +29,17 @@ import net.minecraft.server.v1_7_R1.*;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
|
||||
|
||||
public class AnySilentChest implements IAnySilentChest
|
||||
{
|
||||
public boolean IsAnyChestNeeded(Player p, int x, int y, int z)
|
||||
{
|
||||
public class AnySilentChest implements IAnySilentChest {
|
||||
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 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;
|
||||
@@ -51,22 +49,20 @@ public class AnySilentChest implements IAnySilentChest
|
||||
return true;
|
||||
if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c()))
|
||||
return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z)
|
||||
{
|
||||
|
||||
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 = (TileEntityChest) world.getTileEntity(x, y, z);
|
||||
if (chest == null)
|
||||
return true;
|
||||
|
||||
|
||||
int id = Block.b(world.getType(x, y, z));
|
||||
|
||||
if (!anychest)
|
||||
{
|
||||
|
||||
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()))
|
||||
@@ -78,7 +74,7 @@ public class AnySilentChest implements IAnySilentChest
|
||||
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)
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest);
|
||||
if (Block.b(world.getType(x + 1, y, z)) == id)
|
||||
@@ -87,50 +83,42 @@ public class AnySilentChest implements IAnySilentChest
|
||||
chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest);
|
||||
if (Block.b(world.getType(x, y, z + 1)) == id)
|
||||
chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1));
|
||||
|
||||
|
||||
boolean returnValue = true;
|
||||
if (!silentchest)
|
||||
{
|
||||
if (!silentchest) {
|
||||
player.openContainer((IInventory) chest);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
else {
|
||||
try {
|
||||
int windowId = 0;
|
||||
try
|
||||
{
|
||||
try {
|
||||
Field windowID = player.getClass().getDeclaredField("containerCounter");
|
||||
windowID.setAccessible(true);
|
||||
windowId = windowID.getInt(player);
|
||||
windowId = windowId % 100 + 1;
|
||||
windowID.setInt(player, windowId);
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{}
|
||||
|
||||
catch (NoSuchFieldException e) {}
|
||||
|
||||
player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest));
|
||||
player.activeContainer.windowId = windowId;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
if (OpenInv.NotifySilentChest())
|
||||
{
|
||||
if (OpenInv.NotifySilentChest()) {
|
||||
p.sendMessage("You are opening a chest silently.");
|
||||
}
|
||||
returnValue = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
p.sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
if (anychest && OpenInv.NotifyAnyChest())
|
||||
{
|
||||
|
||||
if (anychest && OpenInv.NotifyAnyChest()) {
|
||||
p.sendMessage("You are opening a blocked chest.");
|
||||
}
|
||||
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
@@ -27,28 +27,22 @@ import com.lishid.openinv.internal.IInventoryAccess;
|
||||
import net.minecraft.server.v1_7_R1.*;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.*;
|
||||
|
||||
public class InventoryAccess implements IInventoryAccess
|
||||
{
|
||||
public boolean check(Inventory inventory, HumanEntity player)
|
||||
{
|
||||
public class InventoryAccess implements IInventoryAccess {
|
||||
public boolean check(Inventory inventory, HumanEntity player) {
|
||||
IInventory inv = ((CraftInventory) inventory).getInventory();
|
||||
|
||||
if (inv instanceof SpecialPlayerInventory)
|
||||
{
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV))
|
||||
{
|
||||
|
||||
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))
|
||||
{
|
||||
|
||||
else if (inv instanceof SpecialEnderChest) {
|
||||
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -19,21 +19,18 @@ package com.lishid.openinv.internal.v1_7_R1;
|
||||
//Volatile
|
||||
import net.minecraft.server.v1_7_R1.*;
|
||||
|
||||
public class SilentContainerChest extends ContainerChest
|
||||
{
|
||||
public class SilentContainerChest extends ContainerChest {
|
||||
public IInventory inv;
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2)
|
||||
{
|
||||
|
||||
public SilentContainerChest(IInventory i1, IInventory i2) {
|
||||
super(i1, i2);
|
||||
inv = i2;
|
||||
// close signal
|
||||
inv.l_();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void b(EntityHuman paramEntityHuman)
|
||||
{
|
||||
public void b(EntityHuman paramEntityHuman) {
|
||||
// Don't send close signal twice, might screw up
|
||||
}
|
||||
}
|
@@ -33,17 +33,15 @@ import net.minecraft.server.v1_7_R1.*;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.*;
|
||||
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest
|
||||
{
|
||||
public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest {
|
||||
public List<HumanEntity> transaction = new ArrayList<HumanEntity>();
|
||||
public boolean playerOnline = false;
|
||||
private CraftPlayer owner;
|
||||
private InventoryEnderChest enderChest;
|
||||
private int maxStack = MAX_STACK;
|
||||
private CraftInventory inventory = new CraftInventory(this);
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online)
|
||||
{
|
||||
|
||||
public SpecialEnderChest(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize());
|
||||
CraftPlayer player = (CraftPlayer) p;
|
||||
this.enderChest = player.getHandle().getEnderChest();
|
||||
@@ -51,98 +49,78 @@ public class SpecialEnderChest extends InventorySubcontainer implements IInvento
|
||||
this.items = enderChest.getContents();
|
||||
OpenInv.enderChests.put(owner.getName().toLowerCase(), this);
|
||||
}
|
||||
|
||||
public Inventory getBukkitInventory()
|
||||
{
|
||||
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public void InventoryRemovalCheck()
|
||||
{
|
||||
|
||||
public void InventoryRemovalCheck() {
|
||||
owner.saveData();
|
||||
if (transaction.isEmpty() && !playerOnline)
|
||||
{
|
||||
if (transaction.isEmpty() && !playerOnline) {
|
||||
OpenInv.enderChests.remove(owner.getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayerGoOnline(Player p)
|
||||
{
|
||||
if (!playerOnline)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
public void PlayerGoOnline(Player p) {
|
||||
if (!playerOnline) {
|
||||
try {
|
||||
InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest();
|
||||
Field field = playerEnderChest.getClass().getField("items");
|
||||
field.setAccessible(true);
|
||||
field.set(playerEnderChest, this.items);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
catch (Exception e) {}
|
||||
p.saveData();
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayerGoOffline()
|
||||
{
|
||||
|
||||
public void PlayerGoOffline() {
|
||||
playerOnline = false;
|
||||
}
|
||||
|
||||
public ItemStack[] getContents()
|
||||
{
|
||||
|
||||
public ItemStack[] getContents() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public void onOpen(CraftHumanEntity who)
|
||||
{
|
||||
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
transaction.add(who);
|
||||
}
|
||||
|
||||
public void onClose(CraftHumanEntity who)
|
||||
{
|
||||
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
transaction.remove(who);
|
||||
this.InventoryRemovalCheck();
|
||||
}
|
||||
|
||||
public List<HumanEntity> getViewers()
|
||||
{
|
||||
|
||||
public List<HumanEntity> getViewers() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
public InventoryHolder getOwner()
|
||||
{
|
||||
|
||||
public InventoryHolder getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public void setMaxStackSize(int size)
|
||||
{
|
||||
|
||||
public void setMaxStackSize(int size) {
|
||||
maxStack = size;
|
||||
}
|
||||
|
||||
public int getMaxStackSize()
|
||||
{
|
||||
|
||||
public int getMaxStackSize() {
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
public boolean a(EntityHuman entityhuman)
|
||||
{
|
||||
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void startOpen()
|
||||
{
|
||||
|
||||
|
||||
public void startOpen() {
|
||||
|
||||
}
|
||||
|
||||
public void f()
|
||||
{
|
||||
|
||||
|
||||
public void f() {
|
||||
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
|
||||
public void update() {
|
||||
enderChest.update();
|
||||
}
|
||||
}
|
||||
|
@@ -27,15 +27,13 @@ import net.minecraft.server.v1_7_R1.*;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.*;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.inventory.*;
|
||||
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory
|
||||
{
|
||||
public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory {
|
||||
CraftPlayer owner;
|
||||
public boolean playerOnline = false;
|
||||
private ItemStack[] extra = new ItemStack[5];
|
||||
private CraftInventory inventory = new CraftInventory(this);
|
||||
|
||||
public SpecialPlayerInventory(Player p, Boolean online)
|
||||
{
|
||||
|
||||
public SpecialPlayerInventory(Player p, Boolean online) {
|
||||
super(((CraftPlayer) p).getHandle());
|
||||
this.owner = ((CraftPlayer) p);
|
||||
this.playerOnline = online;
|
||||
@@ -43,28 +41,23 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
this.armor = player.inventory.armor;
|
||||
OpenInv.inventories.put(owner.getName().toLowerCase(), this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Inventory getBukkitInventory()
|
||||
{
|
||||
public Inventory getBukkitInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void InventoryRemovalCheck()
|
||||
{
|
||||
public void InventoryRemovalCheck() {
|
||||
owner.saveData();
|
||||
if (transaction.isEmpty() && !playerOnline)
|
||||
{
|
||||
if (transaction.isEmpty() && !playerOnline) {
|
||||
OpenInv.inventories.remove(owner.getName().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void PlayerGoOnline(Player player)
|
||||
{
|
||||
if (!playerOnline)
|
||||
{
|
||||
public void PlayerGoOnline(Player player) {
|
||||
if (!playerOnline) {
|
||||
CraftPlayer p = (CraftPlayer) player;
|
||||
p.getHandle().inventory.items = this.items;
|
||||
p.getHandle().inventory.armor = this.armor;
|
||||
@@ -72,201 +65,167 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
playerOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void PlayerGoOffline()
|
||||
{
|
||||
public void PlayerGoOffline() {
|
||||
playerOnline = false;
|
||||
this.InventoryRemovalCheck();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClose(CraftHumanEntity who)
|
||||
{
|
||||
public void onClose(CraftHumanEntity who) {
|
||||
super.onClose(who);
|
||||
this.InventoryRemovalCheck();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack[] getContents()
|
||||
{
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] C = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, C, 0, items.length);
|
||||
System.arraycopy(items, 0, C, items.length, armor.length);
|
||||
return C;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize()
|
||||
{
|
||||
public int getSize() {
|
||||
return super.getSize() + 5;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int i)
|
||||
{
|
||||
public ItemStack getItem(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor)
|
||||
{
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
|
||||
return is[i];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack splitStack(int i, int j)
|
||||
{
|
||||
public ItemStack splitStack(int i, int j) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor)
|
||||
{
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null)
|
||||
{
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack;
|
||||
|
||||
if (is[i].count <= j)
|
||||
{
|
||||
|
||||
if (is[i].count <= j) {
|
||||
itemstack = is[i];
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
itemstack = is[i].a(j);
|
||||
if (is[i].count == 0)
|
||||
{
|
||||
if (is[i].count == 0) {
|
||||
is[i] = null;
|
||||
}
|
||||
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack splitWithoutUpdate(int i)
|
||||
{
|
||||
public ItemStack splitWithoutUpdate(int i) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor)
|
||||
{
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
if (is[i] != null)
|
||||
{
|
||||
|
||||
if (is[i] != null) {
|
||||
ItemStack itemstack = is[i];
|
||||
|
||||
|
||||
is[i] = null;
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setItem(int i, ItemStack itemstack)
|
||||
{
|
||||
public void setItem(int i, ItemStack itemstack) {
|
||||
ItemStack[] is = this.items;
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.armor;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
i = getReversedItemSlotNum(i);
|
||||
}
|
||||
|
||||
if (i >= is.length)
|
||||
{
|
||||
|
||||
if (i >= is.length) {
|
||||
i -= is.length;
|
||||
is = this.extra;
|
||||
}
|
||||
else if (is == this.armor)
|
||||
{
|
||||
else if (is == this.armor) {
|
||||
i = getReversedArmorSlotNum(i);
|
||||
}
|
||||
|
||||
|
||||
// Effects
|
||||
if (is == this.extra)
|
||||
{
|
||||
if (is == this.extra) {
|
||||
owner.getHandle().drop(itemstack, true);
|
||||
itemstack = null;
|
||||
}
|
||||
|
||||
|
||||
is[i] = itemstack;
|
||||
|
||||
|
||||
owner.getHandle().defaultContainer.b();
|
||||
}
|
||||
|
||||
private int getReversedItemSlotNum(int i)
|
||||
{
|
||||
|
||||
private int getReversedItemSlotNum(int i) {
|
||||
if (i >= 27)
|
||||
return i - 27;
|
||||
else
|
||||
return i + 9;
|
||||
}
|
||||
|
||||
private int getReversedArmorSlotNum(int i)
|
||||
{
|
||||
|
||||
private int getReversedArmorSlotNum(int i) {
|
||||
if (i == 0)
|
||||
return 3;
|
||||
if (i == 1)
|
||||
@@ -278,20 +237,17 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
else
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
if (player.getName().length() > 16)
|
||||
{
|
||||
public String getInventoryName() {
|
||||
if (player.getName().length() > 16) {
|
||||
return player.getName().substring(0, 16);
|
||||
}
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman)
|
||||
{
|
||||
public boolean a(EntityHuman entityhuman) {
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user