From c4a9cb0a4a744a8a46ebc063a628d435e6aaaece Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Wed, 2 Mar 2016 20:11:45 +1100 Subject: [PATCH] Updated to CraftBukkit 1.9 --- README | 2 +- src/main/java/com/lishid/openinv/OpenInv.java | 3 +- .../openinv/commands/AnyChestCommand.java | 2 +- .../openinv/commands/OpenEnderCommand.java | 2 +- .../openinv/commands/OpenInvCommand.java | 6 +- .../openinv/commands/SearchInvCommand.java | 2 +- .../openinv/commands/SilentChestCommand.java | 2 +- .../commands/ToggleOpenInvCommand.java | 2 +- .../openinv/internal/AnySilentChest.java | 2 +- .../openinv/internal/InventoryAccess.java | 2 +- .../openinv/internal/PlayerDataManager.java | 2 +- .../internal/SilentContainerChest.java | 2 +- .../openinv/internal/SpecialEnderChest.java | 2 +- .../internal/SpecialPlayerInventory.java | 183 ++++++++++-------- .../listeners/OpenInvEntityListener.java | 2 +- .../listeners/OpenInvInventoryListener.java | 2 +- .../listeners/OpenInvPlayerListener.java | 2 +- 17 files changed, 119 insertions(+), 101 deletions(-) diff --git a/README b/README index 209e1e8..ebd75f3 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -Copyright (C) 2011-2014 lishid. All rights reserved. +Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index 8bf491c..70a7aeb 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java b/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java index 3bcde82..2ceae54 100644 --- a/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java +++ b/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java index f39fce8..8d3b79f 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index 4368ac7..fee3a81 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 @@ -147,10 +147,14 @@ public class OpenInvCommand implements CommandExecutor { openInvHistory.put(player.getUniqueId(), target.getUniqueId()); // Create the inventory + /* SpecialPlayerInventory inv = OpenInv.inventories.get(target.getUniqueId()); if (inv == null) { inv = new SpecialPlayerInventory(target, target.isOnline()); } + */ + + SpecialPlayerInventory inv = new SpecialPlayerInventory(target, target.isOnline()); // Open the inventory player.openInventory(inv.getBukkitInventory()); diff --git a/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java index babe370..584c5ad 100644 --- a/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java b/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java index ce94e88..e2b0a46 100644 --- a/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java index a024c24..26d14ea 100644 --- a/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java index d03a756..e303823 100644 --- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java index ef1357f..8c6327a 100644 --- a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java +++ b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java index 9a06cbb..dc4083f 100644 --- a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java index 2be1435..f2af89f 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java +++ b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java index 40d4a5d..fdccf4a 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index 390dc03..40e8193 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 @@ -30,21 +30,26 @@ import org.bukkit.craftbukkit.v1_9_R1.inventory.*; /* * ----------------------------------------------- * This class still needs to be updated for 1.9. + * + * It has been partially updated, but is very buggy + * and does not work correctly. * ----------------------------------------------- */ public class SpecialPlayerInventory extends PlayerInventory { private final CraftInventory inventory = new CraftInventory(this); private final ItemStack[] extra = new ItemStack[5]; + private final ItemStack[][] g; private final CraftPlayer owner; private boolean playerOnline; public SpecialPlayerInventory(Player p, boolean online) { super(((CraftPlayer) p).getHandle()); this.owner = (CraftPlayer) p; - this.items = player.inventory.items; - this.armor = player.inventory.armor; + System.arraycopy(player.inventory.items, 0, this.items, 0, this.items.length); + System.arraycopy(player.inventory.armor, 0, this.armor, 0, this.armor.length); + this.g = new ItemStack[][]{this.items, this.armor, this.extra}; this.playerOnline = online; - OpenInv.inventories.put(owner.getUniqueId(), this); + // OpenInv.inventories.put(owner.getUniqueId(), this); } public Inventory getBukkitInventory() { @@ -52,15 +57,19 @@ public class SpecialPlayerInventory extends PlayerInventory { } private void saveOnExit() { + if (playerOnline) { + linkInventory(player.inventory); + } + if (transaction.isEmpty() && !playerOnline) { owner.saveData(); - OpenInv.inventories.remove(owner.getUniqueId()); + // OpenInv.inventories.remove(owner.getUniqueId()); } } private void linkInventory(PlayerInventory inventory) { - inventory.items = this.items; - inventory.armor = this.armor; + System.arraycopy(this.items, 0, inventory.items, 0, inventory.items.length); + System.arraycopy(this.armor, 0, inventory.armor, 0, inventory.armor.length); } public void playerOnline(Player player) { @@ -87,99 +96,100 @@ public class SpecialPlayerInventory extends PlayerInventory { @Override public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(armor, 0, C, items.length, armor.length); - return C; + ItemStack[] contents = new ItemStack[getSize()]; + System.arraycopy(this.items, 0, contents, 0, this.items.length); + System.arraycopy(this.armor, 0, contents, this.items.length, this.armor.length); + return contents; } @Override public int getSize() { - return super.getSize() + 5; + return super.getSize() + 5; // super.getSize() - this.extraSlots.length + 5; } @Override public ItemStack getItem(int i) { - ItemStack[] is = this.items; + ItemStack[] is = null; + ItemStack[][] contents = this.g; + int j = contents.length; - if (i >= is.length) { - i -= is.length; - is = this.armor; - } else { - i = getReversedItemSlotNum(i); + for (int k = 0; k < j; ++k) { + ItemStack[] is2 = contents[k]; + if (i < is2.length) { + is = is2; + break; + } + + i -= is2.length; } - if (i >= is.length) { - i -= is.length; - is = this.extra; + if (is == this.items) { + i = getReversedItemSlotNum(i); } else if (is == this.armor) { i = getReversedArmorSlotNum(i); + } else if (is == this.extra) { + // Do nothing } - return is[i]; + return is == null ? null : is[i]; } @Override public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; + ItemStack[] is = null; + ItemStack[][] contents = this.g; + int k = contents.length; - if (i >= is.length) { - i -= is.length; - is = this.armor; - } else { - i = getReversedItemSlotNum(i); + for (int l = 0; l < k; ++l) { + ItemStack[] is2 = contents[l]; + if (i < is2.length) { + is = is2; + break; + } + + i -= is2.length; } - if (i >= is.length) { - i -= is.length; - is = this.extra; + if (is == this.items) { + i = getReversedItemSlotNum(i); } else if (is == this.armor) { i = getReversedArmorSlotNum(i); + } else if (is == this.extra) { + // Do nothing } - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } else { - itemstack = is[i].cloneAndSubtract(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } else { - return null; - } + return is != null && is[i] != null ? ContainerUtil.a(is, i, j) : null; } @Override public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; + ItemStack[] is = null; + ItemStack[][] contents = this.g; + int j = contents.length; - if (i >= is.length) { - i -= is.length; - is = this.armor; - } else { - i = getReversedItemSlotNum(i); + for (int object = 0; object < j; ++object) { + ItemStack[] is2 = contents[object]; + if (i < is2.length) { + is = is2; + break; + } + + i -= is2.length; } - if (i >= is.length) { - i -= is.length; - is = this.extra; - } else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - if (is[i] != null) { - ItemStack itemstack = is[i]; + if (is != null && is[i] != null) { + if (is == this.items) { + i = getReversedItemSlotNum(i); + } else if (is == this.armor) { + i = getReversedArmorSlotNum(i); + } else if (is == this.extra) { + // Do nothing + } + Object object = is[i]; is[i] = null; - return itemstack; + return (ItemStack) object; } else { return null; } @@ -187,31 +197,34 @@ public class SpecialPlayerInventory extends PlayerInventory { @Override public void setItem(int i, ItemStack itemStack) { - ItemStack[] is = this.items; + ItemStack[] is = null; + ItemStack[][] contents = this.g; + int j = contents.length; - if (i >= is.length) { - i -= is.length; - is = this.armor; - } else { - i = getReversedItemSlotNum(i); + for (int k = 0; k < j; ++k) { + ItemStack[] is2 = contents[k]; + if (i < is2.length) { + is = is2; + break; + } + + i -= is2.length; } - if (i >= is.length) { - i -= is.length; - is = this.extra; - } else if (is == this.armor) { - i = getReversedArmorSlotNum(i); + if (is != null) { + if (is == this.items) { + i = getReversedItemSlotNum(i); + } else if (is == this.armor) { + i = getReversedArmorSlotNum(i); + } else if (is == this.extra) { + owner.getHandle().drop(itemStack, true); + itemStack = null; + } + + is[i] = itemStack; + + // owner.getHandle().defaultContainer.b(); } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemStack, true); - itemStack = null; - } - - is[i] = itemStack; - - owner.getHandle().defaultContainer.b(); } private int getReversedItemSlotNum(int i) { diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java index 25b6785..0411f6f 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java index 6d3250e..e81fd5c 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvInventoryListener.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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 diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java index 5e1f42b..579d93d 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2014 lishid. All rights reserved. + * Copyright (C) 2011-2016 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