From 4058463f7fbcf5cd33630183d5a4029427d3850a Mon Sep 17 00:00:00 2001 From: Jikoo Date: Wed, 11 Mar 2015 16:37:13 -0400 Subject: [PATCH] OpenInv 2.2.7 Updated for Spigot 1.8.3 Dropped support for all other versions Fixed lookup not working for players on first login/incomplete names --- .../commands/OpenEnderPluginCommand.java | 9 ++- .../commands/OpenInvPluginCommand.java | 10 ++- .../{v1_8_R1 => v1_8_R2}/AnySilentChest.java | 29 +++++---- .../{v1_8_R1 => v1_8_R2}/InventoryAccess.java | 10 +-- .../PlayerDataManager.java | 13 ++-- .../SilentContainerChest.java | 6 +- .../SpecialEnderChest.java | 65 ++++++++++++------- .../SpecialPlayerInventory.java | 16 +++-- src/plugin.yml | 2 +- 9 files changed, 104 insertions(+), 56 deletions(-) rename src/com/lishid/openinv/internal/{v1_8_R1 => v1_8_R2}/AnySilentChest.java (86%) rename src/com/lishid/openinv/internal/{v1_8_R1 => v1_8_R2}/InventoryAccess.java (90%) rename src/com/lishid/openinv/internal/{v1_8_R1 => v1_8_R2}/PlayerDataManager.java (93%) rename src/com/lishid/openinv/internal/{v1_8_R1 => v1_8_R2}/SilentContainerChest.java (84%) rename src/com/lishid/openinv/internal/{v1_8_R1 => v1_8_R2}/SpecialEnderChest.java (68%) rename src/com/lishid/openinv/internal/{v1_8_R1 => v1_8_R2}/SpecialPlayerInventory.java (92%) diff --git a/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java b/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java index 92a29c4f..f2d9078d 100644 --- a/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java +++ b/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java @@ -17,6 +17,7 @@ package com.lishid.openinv.commands; import java.util.HashMap; +import java.util.List; import java.util.UUID; import org.bukkit.Bukkit; @@ -41,7 +42,8 @@ public OpenEnderPluginCommand(OpenInv plugin) { this.plugin = plugin; } - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You can't use this from the console."); return true; @@ -82,6 +84,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St new BukkitRunnable() { @Override public void run() { + List matches = Bukkit.matchPlayer(name); + if (!matches.isEmpty()) { + openInventory(player, matches.get(0).getUniqueId()); + return; + } final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); if (Bukkit.getPlayer(senderID) == null) { return; diff --git a/src/com/lishid/openinv/commands/OpenInvPluginCommand.java b/src/com/lishid/openinv/commands/OpenInvPluginCommand.java index 71e7527c..6bb88156 100644 --- a/src/com/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/com/lishid/openinv/commands/OpenInvPluginCommand.java @@ -17,6 +17,7 @@ package com.lishid.openinv.commands; import java.util.HashMap; +import java.util.List; import java.util.UUID; import org.bukkit.Bukkit; @@ -41,7 +42,8 @@ public OpenInvPluginCommand(OpenInv plugin) { this.plugin = plugin; } - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You can't use this from the console."); return true; @@ -76,11 +78,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St name = args[0]; } - sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup."); final UUID senderID = player.getUniqueId(); new BukkitRunnable() { @Override public void run() { + List matches = Bukkit.matchPlayer(name); + if (!matches.isEmpty()) { + openInventory(player, matches.get(0).getUniqueId()); + return; + } final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); if (Bukkit.getPlayer(senderID) == null) { return; diff --git a/src/com/lishid/openinv/internal/v1_8_R1/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java similarity index 86% rename from src/com/lishid/openinv/internal/v1_8_R1/AnySilentChest.java rename to src/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java index 9ec68157..a50a60e0 100644 --- a/src/com/lishid/openinv/internal/v1_8_R1/AnySilentChest.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_8_R1; +package com.lishid.openinv.internal.v1_8_R2; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -22,18 +22,22 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IAnySilentChest; - - - - - //Volatile -import net.minecraft.server.v1_8_R1.*; - -import org.bukkit.craftbukkit.v1_8_R1.entity.*; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; + +import net.minecraft.server.v1_8_R2.Block; +import net.minecraft.server.v1_8_R2.BlockPosition; +import net.minecraft.server.v1_8_R2.EntityPlayer; +import net.minecraft.server.v1_8_R2.IInventory; +import net.minecraft.server.v1_8_R2.ITileInventory; +import net.minecraft.server.v1_8_R2.InventoryLargeChest; +import net.minecraft.server.v1_8_R2.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_8_R2.TileEntityChest; +import net.minecraft.server.v1_8_R2.World; public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { + @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; @@ -56,10 +60,11 @@ public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { return false; } - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { + @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 = (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z)); + Object chest = world.getTileEntity(new BlockPosition(x, y, z)); if (chest == null) return true; diff --git a/src/com/lishid/openinv/internal/v1_8_R1/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java similarity index 90% rename from src/com/lishid/openinv/internal/v1_8_R1/InventoryAccess.java rename to src/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java index 47238af0..6edb813c 100644 --- a/src/com/lishid/openinv/internal/v1_8_R1/InventoryAccess.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_8_R1; +package com.lishid.openinv.internal.v1_8_R2; import java.lang.reflect.Field; @@ -25,12 +25,14 @@ import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.IInventoryAccess; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + //Volatile -import net.minecraft.server.v1_8_R1.*; -import org.bukkit.craftbukkit.v1_8_R1.inventory.*; +import net.minecraft.server.v1_8_R2.IInventory; public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { + @Override + public boolean check(Inventory inventory, HumanEntity player) { IInventory inv = grabInventory(inventory); if (inv instanceof SpecialPlayerInventory) { diff --git a/src/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java similarity index 93% rename from src/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java rename to src/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java index beb0fb97..d7ac3f9b 100644 --- a/src/com/lishid/openinv/internal/v1_8_R1/PlayerDataManager.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_8_R1; +package com.lishid.openinv.internal.v1_8_R2; import java.io.File; import java.util.UUID; @@ -27,13 +27,16 @@ import com.lishid.openinv.internal.IPlayerDataManager; import com.mojang.authlib.GameProfile; -//Volatile -import net.minecraft.server.v1_8_R1.*; +import org.bukkit.craftbukkit.v1_8_R2.CraftServer; -import org.bukkit.craftbukkit.v1_8_R1.*; +import net.minecraft.server.v1_8_R2.EntityPlayer; +//Volatile +import net.minecraft.server.v1_8_R2.MinecraftServer; +import net.minecraft.server.v1_8_R2.PlayerInteractManager; public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { + @Override + public Player loadPlayer(String name) { try { UUID uuid = matchUser(name); if (uuid == null) { diff --git a/src/com/lishid/openinv/internal/v1_8_R1/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java similarity index 84% rename from src/com/lishid/openinv/internal/v1_8_R1/SilentContainerChest.java rename to src/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java index 1cbf8953..f2b02766 100644 --- a/src/com/lishid/openinv/internal/v1_8_R1/SilentContainerChest.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java @@ -14,10 +14,12 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_8_R1; +package com.lishid.openinv.internal.v1_8_R2; //Volatile -import net.minecraft.server.v1_8_R1.*; +import net.minecraft.server.v1_8_R2.ContainerChest; +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.IInventory; public class SilentContainerChest extends ContainerChest { public IInventory inv; diff --git a/src/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java similarity index 68% rename from src/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java rename to src/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java index a580f157..6cda9209 100644 --- a/src/com/lishid/openinv/internal/v1_8_R1/SpecialEnderChest.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java @@ -14,32 +14,38 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_8_R1; +package com.lishid.openinv.internal.v1_8_R2; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.ISpecialEnderChest; + +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + //Volatile -import net.minecraft.server.v1_8_R1.*; -import org.bukkit.craftbukkit.v1_8_R1.entity.*; -import org.bukkit.craftbukkit.v1_8_R1.inventory.*; +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.IInventory; +import net.minecraft.server.v1_8_R2.InventoryEnderChest; +import net.minecraft.server.v1_8_R2.InventorySubcontainer; +import net.minecraft.server.v1_8_R2.ItemStack; public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { public List transaction = new ArrayList(); public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); + private final CraftInventory inventory = new CraftInventory(this); public SpecialEnderChest(Player p, Boolean online) { super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); @@ -50,18 +56,21 @@ public SpecialEnderChest(Player p, Boolean online) { OpenInv.enderChests.put(owner.getName().toLowerCase(), this); } - public Inventory getBukkitInventory() { + @Override + public Inventory getBukkitInventory() { return inventory; } - public void InventoryRemovalCheck() { + @Override + public void InventoryRemovalCheck() { owner.saveData(); if (transaction.isEmpty() && !playerOnline) { OpenInv.enderChests.remove(owner.getName().toLowerCase()); } } - public void PlayerGoOnline(Player p) { + @Override + public void PlayerGoOnline(Player p) { if (!playerOnline) { try { InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); @@ -75,40 +84,49 @@ public void PlayerGoOnline(Player p) { } } - public void PlayerGoOffline() { + @Override + public void PlayerGoOffline() { playerOnline = false; } - public ItemStack[] getContents() { + @Override + public ItemStack[] getContents() { return this.items; } - public void onOpen(CraftHumanEntity who) { + @Override + public void onOpen(CraftHumanEntity who) { transaction.add(who); } - public void onClose(CraftHumanEntity who) { + @Override + public void onClose(CraftHumanEntity who) { transaction.remove(who); this.InventoryRemovalCheck(); } - public List getViewers() { + @Override + public List getViewers() { return transaction; } - public InventoryHolder getOwner() { + @Override + public InventoryHolder getOwner() { return this.owner; } - public void setMaxStackSize(int size) { + @Override + public void setMaxStackSize(int size) { maxStack = size; } - public int getMaxStackSize() { + @Override + public int getMaxStackSize() { return maxStack; } - public boolean a(EntityHuman entityhuman) { + @Override + public boolean a(EntityHuman entityhuman) { return true; } @@ -120,7 +138,8 @@ public void f() { } - public void update() { + @Override + public void update() { enderChest.update(); } } diff --git a/src/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java similarity index 92% rename from src/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java rename to src/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java index 42ae0524..38fa2caf 100644 --- a/src/com/lishid/openinv/internal/v1_8_R1/SpecialPlayerInventory.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_8_R1; +package com.lishid.openinv.internal.v1_8_R2; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -23,15 +23,19 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory; //Volatile -import net.minecraft.server.v1_8_R1.*; -import org.bukkit.craftbukkit.v1_8_R1.entity.*; -import org.bukkit.craftbukkit.v1_8_R1.inventory.*; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.ItemStack; +import net.minecraft.server.v1_8_R2.PlayerInventory; 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); + private final ItemStack[] extra = new ItemStack[5]; + private final CraftInventory inventory = new CraftInventory(this); public SpecialPlayerInventory(Player p, Boolean online) { super(((CraftPlayer) p).getHandle()); diff --git a/src/plugin.yml b/src/plugin.yml index c6a21476..24d84796 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: com.lishid.openinv.OpenInv -version: 2.2.6 +version: 2.2.7 author: lishid description: > This plugin allows you to open a player's inventory as a chest and interact with it in real time.