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..49afd30 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 { @@ -55,7 +58,7 @@ public class OpenInvCommand implements CommandExecutor { } if (args.length > 0 && args[0].equalsIgnoreCase("?")) { - OpenInv.showHelp((Player) sender); + OpenInv.showHelp(sender); return true; } @@ -73,9 +76,8 @@ public class OpenInvCommand implements CommandExecutor { // Read from history if target is not named if (args.length < 1) { uuid = history; - } - else { - uuid = UUIDUtil.getUUIDOf(args[0]); + } else { + 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/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: >