From c3a8bc9486b388f6a690eb83f374c98839a90a79 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Thu, 9 Jun 2016 22:41:21 +1000 Subject: [PATCH 1/3] Update to 1.10 --- pom.xml | 6 +- .../com/lishid/openinv/ConfigUpdater.java | 4 +- src/main/java/com/lishid/openinv/OpenInv.java | 40 +++---- .../openinv/commands/OpenEnderCommand.java | 6 +- .../openinv/commands/OpenInvCommand.java | 107 ++++++++++++------ .../openinv/internal/AnySilentChest.java | 31 ++--- .../openinv/internal/EnumDirectionList.java | 4 +- .../openinv/internal/InventoryAccess.java | 4 +- .../openinv/internal/PlayerDataManager.java | 8 +- .../openinv/internal/SilentInventory.java | 18 +-- .../openinv/internal/SpecialEnderChest.java | 34 ++++-- .../internal/SpecialPlayerInventory.java | 15 +-- .../utils/{UUIDUtil.java => UUIDUtils.java} | 6 +- src/main/resources/plugin.yml | 2 +- 14 files changed, 174 insertions(+), 111 deletions(-) rename src/main/java/com/lishid/openinv/utils/{UUIDUtil.java => UUIDUtils.java} (95%) diff --git a/pom.xml b/pom.xml index 11fd144..efe52d4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.lishid openinv jar - 2.3.8 + 2.3.9 OpenInv http://dev.bukkit.org/bukkit-plugins/openinv/ @@ -23,14 +23,14 @@ org.bukkit bukkit - 1.9.4-R0.1-SNAPSHOT + 1.10-R0.1-SNAPSHOT provided org.bukkit craftbukkit - 1.9.4-R0.1-SNAPSHOT + 1.10-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index 31a2fd9..cf0772c 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -10,7 +10,7 @@ import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; -import com.lishid.openinv.utils.UUIDUtil; +import com.lishid.openinv.utils.UUIDUtils; public class ConfigUpdater { @@ -136,7 +136,7 @@ public class ConfigUpdater { int converted = 0; for (String playerName : keys) { - UUID uuid = UUIDUtil.getUUIDOf(playerName); + UUID uuid = UUIDUtils.getPlayerUUID(playerName); if (uuid != null) { boolean toggled = section.getBoolean(playerName + ".toggle", false); diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index c7fa0fc..6b62e35 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -129,6 +129,7 @@ public class OpenInv extends JavaPlugin { */ public SpecialPlayerInventory getPlayerInventory(Player player, boolean createIfNull) { SpecialPlayerInventory inventory = inventories.get(player.getUniqueId()); + if (inventory == null && createIfNull) { inventory = new SpecialPlayerInventory(player, player.isOnline()); inventories.put(player.getUniqueId(), inventory); @@ -146,6 +147,7 @@ public class OpenInv extends JavaPlugin { */ public SpecialEnderChest getPlayerEnderChest(Player player, boolean createIfNull) { SpecialEnderChest enderChest = enderChests.get(player.getUniqueId()); + if (enderChest == null && createIfNull) { enderChest = new SpecialEnderChest(player, player.isOnline()); enderChests.put(player.getUniqueId(), enderChest); @@ -206,33 +208,33 @@ public class OpenInv extends JavaPlugin { } /** - * Outputs OpenInv help information to a player. + * Outputs OpenInv help information to a CommandSender. * - * @param player the player to show help to + * @param sender the CommandSender to show help to */ - public static void showHelp(Player player) { - player.sendMessage(ChatColor.GREEN + "/openinv - Opens a player's inventory."); - player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); + public static void showHelp(CommandSender sender) { + sender.sendMessage(ChatColor.GREEN + "/openinv - Opens a player's inventory."); + sender.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)"); - player.sendMessage(ChatColor.GREEN + "/openender - Opens a player's ender chest."); - player.sendMessage(ChatColor.GREEN + " (aliases: oe)"); + sender.sendMessage(ChatColor.GREEN + "/openender - Opens a player's ender chest."); + sender.sendMessage(ChatColor.GREEN + " (aliases: oe)"); - player.sendMessage(ChatColor.GREEN + "/searchinv [minAmount] -"); - player.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their inventory."); - player.sendMessage(ChatColor.GREEN + " (aliases: si)"); + sender.sendMessage(ChatColor.GREEN + "/searchinv [minAmount] -"); + sender.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their inventory."); + sender.sendMessage(ChatColor.GREEN + " (aliases: si)"); - player.sendMessage(ChatColor.GREEN + "/searchender [minAmount] -"); - player.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their ender chest."); - player.sendMessage(ChatColor.GREEN + " (aliases: se)"); + sender.sendMessage(ChatColor.GREEN + "/searchender [minAmount] -"); + sender.sendMessage(ChatColor.GREEN + " Searches and lists players that have a specific item in their ender chest."); + sender.sendMessage(ChatColor.GREEN + " (aliases: se)"); - player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggles the item openinv function."); - player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)"); + sender.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggles the item openinv function."); + sender.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)"); - player.sendMessage(ChatColor.GREEN + "/anychest - Toggles the any chest function."); - player.sendMessage(ChatColor.GREEN + " (aliases: ac)"); + sender.sendMessage(ChatColor.GREEN + "/anychest - Toggles the any chest function."); + sender.sendMessage(ChatColor.GREEN + " (aliases: ac)"); - player.sendMessage(ChatColor.GREEN + "/silentchest - Toggles the silent chest function."); - player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)"); + sender.sendMessage(ChatColor.GREEN + "/silentchest - Toggles the silent chest function."); + sender.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)"); } /** diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java index 6ff14b9..11727a4 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.SpecialEnderChest; -import com.lishid.openinv.utils.UUIDUtil; +import com.lishid.openinv.utils.UUIDUtils; public class OpenEnderCommand implements CommandExecutor { @@ -55,7 +55,7 @@ public class OpenEnderCommand implements CommandExecutor { } if (args.length > 0 && args[0].equalsIgnoreCase("?")) { - OpenInv.showHelp((Player) sender); + OpenInv.showHelp(sender); return true; } @@ -80,7 +80,7 @@ public class OpenEnderCommand implements CommandExecutor { } } else { - uuid = UUIDUtil.getUUIDOf(args[0]); + uuid = UUIDUtils.getPlayerUUID(args[0]); if (uuid == null) { player.sendMessage(ChatColor.RED + "Player not found!"); return true; diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index cae130e..29b9094 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -25,12 +25,15 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.SpecialPlayerInventory; -import com.lishid.openinv.utils.UUIDUtil; +import com.lishid.openinv.utils.UUIDUtils; public class OpenInvCommand implements CommandExecutor { @@ -42,12 +45,9 @@ public class OpenInvCommand implements CommandExecutor { } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("openinv")) { - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "You can't use this command from the console."); - return true; - } + final boolean isConsole = sender instanceof ConsoleCommandSender; if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) { sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories."); @@ -55,34 +55,38 @@ public class OpenInvCommand implements CommandExecutor { } if (args.length > 0 && args[0].equalsIgnoreCase("?")) { - OpenInv.showHelp((Player) sender); + OpenInv.showHelp(sender); return true; } - final Player player = (Player) sender; - - // History management - UUID history = openInvHistory.get(player.getUniqueId()); - if (history == null) { - history = player.getUniqueId(); - openInvHistory.put(player.getUniqueId(), history); - } - + Player player = isConsole ? null : (Player) sender; final UUID uuid; // Read from history if target is not named if (args.length < 1) { + if (isConsole) { + // TODO: Should this output the command's usage instead? + sender.sendMessage(ChatColor.RED + "Player not found!"); + return true; + } + + // History management + UUID history = openInvHistory.get(player.getUniqueId()); + if (history == null) { + history = player.getUniqueId(); + openInvHistory.put(player.getUniqueId(), history); + } + uuid = history; - } - else { - uuid = UUIDUtil.getUUIDOf(args[0]); + } else { + uuid = UUIDUtils.getPlayerUUID(args[0]); if (uuid == null) { - player.sendMessage(ChatColor.RED + "Player not found!"); + sender.sendMessage(ChatColor.RED + "Player not found!"); return true; } } - final UUID playerUUID = player.getUniqueId(); + final UUID playerUUID = isConsole ? null : player.getUniqueId(); Player target = Bukkit.getPlayer(uuid); if (target == null) { @@ -93,27 +97,40 @@ public class OpenInvCommand implements CommandExecutor { // Try loading the player's data asynchronously final Player target = plugin.getPlayerLoader().loadPlayer(uuid); if (target == null) { - player.sendMessage(ChatColor.RED + "Player not found!"); + sender.sendMessage(ChatColor.RED + "Player not found!"); return; } - // Open target's inventory synchronously - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - Player player = Bukkit.getPlayer(playerUUID); - // If sender is no longer online after loading the target, abort! - if (player == null) { - return; + // Open/output target's inventory synchronously + if (isConsole) { + Bukkit.getScheduler().runTask(plugin, new Runnable() { + @Override + public void run() { + outputInventory(sender, target); } + }); + } else { + Bukkit.getScheduler().runTask(plugin, new Runnable() { + @Override + public void run() { + Player player = Bukkit.getPlayer(playerUUID); + // If sender is no longer online after loading the target, abort! + if (player == null) { + return; + } - openInventory(player, target); - } - }); + openInventory(player, target); + } + }); + } } }); } else { - openInventory(player, target); + if (isConsole) { + outputInventory(sender, target); + } else { + openInventory(player, target); + } } return true; @@ -122,6 +139,28 @@ public class OpenInvCommand implements CommandExecutor { return false; } + @SuppressWarnings("deprecation") + private void outputInventory(CommandSender sender, Player target) { + // Get the inventory and open it + SpecialPlayerInventory specialInv = plugin.getPlayerInventory(target, true); + Inventory inventory = specialInv.getBukkitInventory(); + + for (int slot = 0; slot < inventory.getSize(); slot++) { + ItemStack itemStack = inventory.getItem(slot); + + if (itemStack != null) { + String itemID = (itemStack.getDurability() != -1) + ? (itemStack.getTypeId() + ":" + itemStack.getDurability()) + : String.valueOf(itemStack.getTypeId()); + + sender.sendMessage(ChatColor.GREEN + "Slot " + slot + ": " + ChatColor.WHITE + + itemStack.getType().toString() + "(" + itemID + ") x" + itemStack.getAmount()); + } else { + sender.sendMessage(ChatColor.GREEN + "Slot " + slot + ": " + ChatColor.WHITE + "Empty"); + } + } + } + private void openInventory(Player player, Player target) { // Null target check if (target == null) { diff --git a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java index f25903f..f8cb40c 100644 --- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java @@ -18,25 +18,25 @@ package com.lishid.openinv.internal; import java.util.Iterator; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; -import net.minecraft.server.v1_9_R2.AxisAlignedBB; -import net.minecraft.server.v1_9_R2.Block; -import net.minecraft.server.v1_9_R2.BlockChest; -import net.minecraft.server.v1_9_R2.BlockChest.Type; -import net.minecraft.server.v1_9_R2.BlockPosition; -import net.minecraft.server.v1_9_R2.Entity; -import net.minecraft.server.v1_9_R2.EntityOcelot; -import net.minecraft.server.v1_9_R2.EntityPlayer; -import net.minecraft.server.v1_9_R2.EnumDirection; -import net.minecraft.server.v1_9_R2.ITileInventory; -import net.minecraft.server.v1_9_R2.InventoryLargeChest; -import net.minecraft.server.v1_9_R2.TileEntity; -import net.minecraft.server.v1_9_R2.TileEntityChest; -import net.minecraft.server.v1_9_R2.World; +import net.minecraft.server.v1_10_R1.AxisAlignedBB; +import net.minecraft.server.v1_10_R1.Block; +import net.minecraft.server.v1_10_R1.BlockChest; +import net.minecraft.server.v1_10_R1.BlockChest.Type; +import net.minecraft.server.v1_10_R1.BlockPosition; +import net.minecraft.server.v1_10_R1.Entity; +import net.minecraft.server.v1_10_R1.EntityOcelot; +import net.minecraft.server.v1_10_R1.EntityPlayer; +import net.minecraft.server.v1_10_R1.EnumDirection; +import net.minecraft.server.v1_10_R1.ITileInventory; +import net.minecraft.server.v1_10_R1.InventoryLargeChest; +import net.minecraft.server.v1_10_R1.TileEntity; +import net.minecraft.server.v1_10_R1.TileEntityChest; +import net.minecraft.server.v1_10_R1.World; public class AnySilentChest { @@ -78,6 +78,7 @@ public class AnySilentChest { return this.blockOnTop(world, position) || this.ocelotOnTop(world, position); } + @SuppressWarnings("deprecation") private boolean blockOnTop(World world, BlockPosition position) { Block block = world.getType(position.up()).getBlock(); return block.isOccluding(block.getBlockData()); diff --git a/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java b/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java index cd8a8c2..3f0f5d4 100644 --- a/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java +++ b/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java @@ -4,8 +4,8 @@ import java.util.Iterator; import com.google.common.collect.Iterators; -import net.minecraft.server.v1_9_R2.EnumDirection; -import net.minecraft.server.v1_9_R2.EnumDirection.EnumDirectionLimit; +import net.minecraft.server.v1_10_R1.EnumDirection; +import net.minecraft.server.v1_10_R1.EnumDirection.EnumDirectionLimit; public enum EnumDirectionList implements Iterable { diff --git a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java index 5c388f1..d468a14 100644 --- a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java +++ b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java @@ -18,14 +18,14 @@ package com.lishid.openinv.internal; import java.lang.reflect.Field; -import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.Inventory; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; -import net.minecraft.server.v1_9_R2.IInventory; +import net.minecraft.server.v1_10_R1.IInventory; public class InventoryAccess { diff --git a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java index ac600fb..c576c6b 100644 --- a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java @@ -20,15 +20,15 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_9_R2.CraftServer; +import org.bukkit.craftbukkit.v1_10_R1.CraftServer; import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.mojang.authlib.GameProfile; -import net.minecraft.server.v1_9_R2.EntityPlayer; -import net.minecraft.server.v1_9_R2.MinecraftServer; -import net.minecraft.server.v1_9_R2.PlayerInteractManager; +import net.minecraft.server.v1_10_R1.EntityPlayer; +import net.minecraft.server.v1_10_R1.MinecraftServer; +import net.minecraft.server.v1_10_R1.PlayerInteractManager; public class PlayerDataManager { diff --git a/src/main/java/com/lishid/openinv/internal/SilentInventory.java b/src/main/java/com/lishid/openinv/internal/SilentInventory.java index 509795b..fd5ecd4 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SilentInventory.java @@ -3,18 +3,18 @@ package com.lishid.openinv.internal; import java.util.List; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.InventoryHolder; -import net.minecraft.server.v1_9_R2.ChestLock; -import net.minecraft.server.v1_9_R2.Container; -import net.minecraft.server.v1_9_R2.ContainerChest; -import net.minecraft.server.v1_9_R2.EntityHuman; -import net.minecraft.server.v1_9_R2.IChatBaseComponent; -import net.minecraft.server.v1_9_R2.ITileInventory; -import net.minecraft.server.v1_9_R2.ItemStack; -import net.minecraft.server.v1_9_R2.PlayerInventory; +import net.minecraft.server.v1_10_R1.ChestLock; +import net.minecraft.server.v1_10_R1.Container; +import net.minecraft.server.v1_10_R1.ContainerChest; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.IChatBaseComponent; +import net.minecraft.server.v1_10_R1.ITileInventory; +import net.minecraft.server.v1_10_R1.ItemStack; +import net.minecraft.server.v1_10_R1.PlayerInventory; public class SilentInventory implements ITileInventory { diff --git a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java index 5ce95a8..0ccc6fe 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java @@ -16,15 +16,18 @@ package com.lishid.openinv.internal; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftHumanEntity; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventory; +import java.lang.reflect.Field; + +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import net.minecraft.server.v1_9_R2.InventoryEnderChest; -import net.minecraft.server.v1_9_R2.InventorySubcontainer; +import net.minecraft.server.v1_10_R1.InventoryEnderChest; +import net.minecraft.server.v1_10_R1.InventorySubcontainer; +import net.minecraft.server.v1_10_R1.ItemStack; public class SpecialEnderChest extends InventorySubcontainer { @@ -41,8 +44,8 @@ public class SpecialEnderChest extends InventorySubcontainer { super(enderChest.getName(), enderChest.hasCustomName(), enderChest.getSize()); this.owner = (CraftPlayer) p; this.enderChest = enderChest; - this.items = this.enderChest.getContents(); this.playerOnline = online; + reflectContents(getClass().getSuperclass(), this, this.enderChest.getContents()); } private void saveOnExit() { @@ -51,8 +54,24 @@ public class SpecialEnderChest extends InventorySubcontainer { } } + private void reflectContents(Class clazz, InventorySubcontainer enderChest, ItemStack[] items) { + try { + Field itemsField = clazz.getDeclaredField("items"); + itemsField.setAccessible(true); + itemsField.set(enderChest, items); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + private void linkInventory(InventoryEnderChest inventory) { - inventory.items = this.items; + reflectContents(inventory.getClass(), inventory, this.items); } public Inventory getBukkitInventory() { @@ -61,6 +80,7 @@ public class SpecialEnderChest extends InventorySubcontainer { public boolean inventoryRemovalCheck(boolean save) { boolean offline = transaction.isEmpty() && !playerOnline; + if (offline && save) { owner.saveData(); } diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index 8c86ba1..605a65b 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -18,16 +18,16 @@ package com.lishid.openinv.internal; import java.lang.reflect.Field; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftHumanEntity; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventory; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import net.minecraft.server.v1_9_R2.ContainerUtil; -import net.minecraft.server.v1_9_R2.EntityHuman; -import net.minecraft.server.v1_9_R2.ItemStack; -import net.minecraft.server.v1_9_R2.PlayerInventory; +import net.minecraft.server.v1_10_R1.ContainerUtil; +import net.minecraft.server.v1_10_R1.EntityHuman; +import net.minecraft.server.v1_10_R1.ItemStack; +import net.minecraft.server.v1_10_R1.PlayerInventory; public class SpecialPlayerInventory extends PlayerInventory { @@ -80,6 +80,7 @@ public class SpecialPlayerInventory extends PlayerInventory { public boolean inventoryRemovalCheck(boolean save) { boolean offline = transaction.isEmpty() && !playerOnline; + if (offline && save) { owner.saveData(); } diff --git a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java b/src/main/java/com/lishid/openinv/utils/UUIDUtils.java similarity index 95% rename from src/main/java/com/lishid/openinv/utils/UUIDUtil.java rename to src/main/java/com/lishid/openinv/utils/UUIDUtils.java index f7faad1..0ac6aba 100644 --- a/src/main/java/com/lishid/openinv/utils/UUIDUtil.java +++ b/src/main/java/com/lishid/openinv/utils/UUIDUtils.java @@ -10,9 +10,9 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -public final class UUIDUtil { +public final class UUIDUtils { - private UUIDUtil() {} + private UUIDUtils() {} private static Player getPlayer(String name) { Validate.notNull(name, "Name cannot be null"); @@ -50,7 +50,7 @@ public final class UUIDUtil { * @param name the name of the player to get the UUID of * @return the player's UUID or null */ - public static UUID getUUIDOf(String name) { + public static UUID getPlayerUUID(String name) { UUID uuid; Player player = getPlayer(name); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4860eb4..f98c9b1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: com.lishid.openinv.OpenInv -version: 2.3.8 +version: 2.3.9 author: lishid authors: [ShadowRanger] description: > From de0d28b12d2c8f9ea0ffb4ac08928bb17bdb0966 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Thu, 9 Jun 2016 22:43:20 +1000 Subject: [PATCH 2/3] Update to 1.10 --- .../openinv/commands/OpenInvCommand.java | 100 ++++++------------ 1 file changed, 32 insertions(+), 68 deletions(-) diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index 29b9094..addeba0 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -45,9 +45,12 @@ public class OpenInvCommand implements CommandExecutor { } @Override - public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("openinv")) { - final boolean isConsole = sender instanceof ConsoleCommandSender; + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "You can't use this command from the console."); + return true; + } if (!OpenInv.hasPermission(sender, Permissions.PERM_OPENINV)) { sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories."); @@ -55,38 +58,34 @@ public class OpenInvCommand implements CommandExecutor { } if (args.length > 0 && args[0].equalsIgnoreCase("?")) { - OpenInv.showHelp(sender); + OpenInv.showHelp((Player) sender); return true; } - Player player = isConsole ? null : (Player) sender; + final Player player = (Player) sender; + + // History management + UUID history = openInvHistory.get(player.getUniqueId()); + if (history == null) { + history = player.getUniqueId(); + openInvHistory.put(player.getUniqueId(), history); + } + final UUID uuid; // Read from history if target is not named if (args.length < 1) { - if (isConsole) { - // TODO: Should this output the command's usage instead? - sender.sendMessage(ChatColor.RED + "Player not found!"); - return true; - } - - // History management - UUID history = openInvHistory.get(player.getUniqueId()); - if (history == null) { - history = player.getUniqueId(); - openInvHistory.put(player.getUniqueId(), history); - } - uuid = history; - } else { + } + else { uuid = UUIDUtils.getPlayerUUID(args[0]); if (uuid == null) { - sender.sendMessage(ChatColor.RED + "Player not found!"); + player.sendMessage(ChatColor.RED + "Player not found!"); return true; } } - final UUID playerUUID = isConsole ? null : player.getUniqueId(); + final UUID playerUUID = player.getUniqueId(); Player target = Bukkit.getPlayer(uuid); if (target == null) { @@ -97,40 +96,27 @@ public class OpenInvCommand implements CommandExecutor { // Try loading the player's data asynchronously final Player target = plugin.getPlayerLoader().loadPlayer(uuid); if (target == null) { - sender.sendMessage(ChatColor.RED + "Player not found!"); + player.sendMessage(ChatColor.RED + "Player not found!"); return; } - // Open/output target's inventory synchronously - if (isConsole) { - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - outputInventory(sender, target); + // Open target's inventory synchronously + Bukkit.getScheduler().runTask(plugin, new Runnable() { + @Override + public void run() { + Player player = Bukkit.getPlayer(playerUUID); + // If sender is no longer online after loading the target, abort! + if (player == null) { + return; } - }); - } else { - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - Player player = Bukkit.getPlayer(playerUUID); - // If sender is no longer online after loading the target, abort! - if (player == null) { - return; - } - openInventory(player, target); - } - }); - } + openInventory(player, target); + } + }); } }); } else { - if (isConsole) { - outputInventory(sender, target); - } else { - openInventory(player, target); - } + openInventory(player, target); } return true; @@ -139,28 +125,6 @@ public class OpenInvCommand implements CommandExecutor { return false; } - @SuppressWarnings("deprecation") - private void outputInventory(CommandSender sender, Player target) { - // Get the inventory and open it - SpecialPlayerInventory specialInv = plugin.getPlayerInventory(target, true); - Inventory inventory = specialInv.getBukkitInventory(); - - for (int slot = 0; slot < inventory.getSize(); slot++) { - ItemStack itemStack = inventory.getItem(slot); - - if (itemStack != null) { - String itemID = (itemStack.getDurability() != -1) - ? (itemStack.getTypeId() + ":" + itemStack.getDurability()) - : String.valueOf(itemStack.getTypeId()); - - sender.sendMessage(ChatColor.GREEN + "Slot " + slot + ": " + ChatColor.WHITE - + itemStack.getType().toString() + "(" + itemID + ") x" + itemStack.getAmount()); - } else { - sender.sendMessage(ChatColor.GREEN + "Slot " + slot + ": " + ChatColor.WHITE + "Empty"); - } - } - } - private void openInventory(Player player, Player target) { // Null target check if (target == null) { From eaabd30dc20013fa20c25ffe42d3c58df42493b7 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Thu, 9 Jun 2016 22:46:36 +1000 Subject: [PATCH 3/3] Update to 1.10 --- .../java/com/lishid/openinv/commands/OpenInvCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index addeba0..49afd30 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -58,7 +58,7 @@ public class OpenInvCommand implements CommandExecutor { } if (args.length > 0 && args[0].equalsIgnoreCase("?")) { - OpenInv.showHelp((Player) sender); + OpenInv.showHelp(sender); return true; } @@ -76,8 +76,7 @@ public class OpenInvCommand implements CommandExecutor { // Read from history if target is not named if (args.length < 1) { uuid = history; - } - else { + } else { uuid = UUIDUtils.getPlayerUUID(args[0]); if (uuid == null) { player.sendMessage(ChatColor.RED + "Player not found!");