From 346036b7e78375dd9ae6b407c5f4ce49a84ada2b Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Wed, 2 Mar 2016 13:44:16 +1100 Subject: [PATCH 1/5] Updated to CraftBukkit 1.9 --- pom.xml | 6 ++--- .../openinv/internal/AnySilentChest.java | 15 ++++++++----- .../openinv/internal/EnumDirectionList.java | 8 +++---- .../openinv/internal/InventoryAccess.java | 11 +++++----- .../openinv/internal/PlayerDataManager.java | 4 ++-- .../internal/SilentContainerChest.java | 2 +- .../openinv/internal/SilentInventory.java | 22 ++++++++++++------- .../openinv/internal/SpecialEnderChest.java | 6 ++--- .../internal/SpecialPlayerInventory.java | 11 +++++++--- .../listeners/OpenInvEntityListener.java | 2 +- .../listeners/OpenInvPlayerListener.java | 2 +- src/main/resources/plugin.yml | 2 +- 12 files changed, 54 insertions(+), 37 deletions(-) diff --git a/pom.xml b/pom.xml index 1505c64..391df44 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.lishid openinv jar - 2.3.4 + 2.3.5 OpenInv http://dev.bukkit.org/bukkit-plugins/openinv/ @@ -23,14 +23,14 @@ org.bukkit bukkit - 1.8.8-R0.1-SNAPSHOT + 1.9-R0.1-SNAPSHOT provided org.bukkit craftbukkit - 1.8.8-R0.1-SNAPSHOT + 1.9-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java index 6c88ad6..0f4fb06 100644 --- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java @@ -23,9 +23,10 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; // Volatile -import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_9_R1.*; +import net.minecraft.server.v1_9_R1.BlockChest.Type; -import org.bukkit.craftbukkit.v1_8_R3.entity.*; +import org.bukkit.craftbukkit.v1_9_R1.entity.*; public class AnySilentChest { public boolean isAnyChestNeeded(Player p, int x, int y, int z) { @@ -33,7 +34,7 @@ public class AnySilentChest { BlockPosition position = new BlockPosition(x, y, z); EntityPlayer player = ((CraftPlayer) p).getHandle(); World world = player.world; - BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).b == 1 ? + BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).g == Type.TRAP ? Block.getByName("trapped_chest") : Block.getByName("chest")); // If block on top @@ -59,7 +60,11 @@ public class AnySilentChest { } private boolean blockOnTop(World world, BlockPosition position) { - return world.getType(position.up()).getBlock().isOccluding(); + // return world.getType(position.up()).getBlock().isOccluding(); + + // TODO: Does this work? + Block block = world.getType(position.up()).getBlock(); + return block.isOccluding(block.getBlockData()); } private boolean ocelotOnTop(World world, BlockPosition position) { @@ -89,7 +94,7 @@ public class AnySilentChest { return true; } - BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).b == 1 ? + BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).g == Type.TRAP ? Block.getByName("trapped_chest") : Block.getByName("chest")); TileEntity tileEntity = world.getTileEntity(position); diff --git a/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java b/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java index 56c5b48..fece744 100644 --- a/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java +++ b/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java @@ -4,16 +4,16 @@ import java.util.Iterator; import com.google.common.collect.Iterators; -import net.minecraft.server.v1_8_R3.EnumDirection; -import net.minecraft.server.v1_8_R3.EnumDirection.EnumDirectionLimit; +import net.minecraft.server.v1_9_R1.EnumDirection; +import net.minecraft.server.v1_9_R1.EnumDirection.EnumDirectionLimit; public enum EnumDirectionList implements Iterable { HORIZONTAL(EnumDirectionLimit.HORIZONTAL), VERTICAL(EnumDirectionLimit.VERTICAL); - private final EnumDirectionLimit list; + private final EnumDirection.EnumDirectionLimit list; - private EnumDirectionList(EnumDirectionLimit list) { + EnumDirectionList(EnumDirection.EnumDirectionLimit list) { this.list = list; } diff --git a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java index 9d6940b..ef1357f 100644 --- a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java +++ b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java @@ -25,9 +25,9 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; // Volatile -import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_9_R1.*; -import org.bukkit.craftbukkit.v1_8_R3.inventory.*; +import org.bukkit.craftbukkit.v1_9_R1.inventory.*; public class InventoryAccess { public boolean check(Inventory inventory, HumanEntity player) { @@ -49,16 +49,17 @@ public class InventoryAccess { } private IInventory grabInventory(Inventory inventory) { - if(inventory instanceof CraftInventory) { + if (inventory instanceof CraftInventory) { return ((CraftInventory) inventory).getInventory(); } // Use reflection to find the inventory Class clazz = inventory.getClass(); IInventory result = null; - for(Field f : clazz.getDeclaredFields()) { + for (Field f : clazz.getDeclaredFields()) { f.setAccessible(true); - if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) { + + if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) { try { result = (IInventory) f.get(inventory); } diff --git a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java index d6fa177..9a06cbb 100644 --- a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java @@ -26,9 +26,9 @@ import com.lishid.openinv.OpenInv; import com.mojang.authlib.GameProfile; // Volatile -import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_9_R1.*; -import org.bukkit.craftbukkit.v1_8_R3.*; +import org.bukkit.craftbukkit.v1_9_R1.*; public class PlayerDataManager { public Player loadPlayer(UUID uuid) { diff --git a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java index b9bc4be..2be1435 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java +++ b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java @@ -17,7 +17,7 @@ package com.lishid.openinv.internal; // Volatile -import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_9_R1.*; public class SilentContainerChest extends ContainerChest { public IInventory inv; diff --git a/src/main/java/com/lishid/openinv/internal/SilentInventory.java b/src/main/java/com/lishid/openinv/internal/SilentInventory.java index a2f50a6..b05211c 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SilentInventory.java @@ -2,12 +2,13 @@ package com.lishid.openinv.internal; import java.util.List; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftHumanEntity; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.InventoryHolder; // Volatile -import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_9_R1.*; public class SilentInventory implements ITileInventory { public ITileInventory inv; @@ -17,8 +18,8 @@ public class SilentInventory implements ITileInventory { } @Override - public boolean r_() { - return inv.r_(); + public boolean x_() { + return inv.x_(); } @Override @@ -27,8 +28,8 @@ public class SilentInventory implements ITileInventory { } @Override - public ChestLock i() { - return inv.i(); + public ChestLock y_() { + return inv.y_(); } @Override @@ -92,8 +93,8 @@ public class SilentInventory implements ITileInventory { } @Override - public void b(int i, int i1) { - inv.b(i, i1); + public void setProperty(int i, int i1) { + inv.setProperty(i, i1); } @Override @@ -136,6 +137,11 @@ public class SilentInventory implements ITileInventory { inv.setMaxStackSize(i); } + @Override + public Location getLocation() { + return inv.getLocation(); + } + @Override public String getName() { return inv.getName(); diff --git a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java index 91f7b94..40d4a5d 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java @@ -23,10 +23,10 @@ import org.bukkit.inventory.InventoryHolder; import com.lishid.openinv.OpenInv; // Volatile -import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_9_R1.*; -import org.bukkit.craftbukkit.v1_8_R3.entity.*; -import org.bukkit.craftbukkit.v1_8_R3.inventory.*; +import org.bukkit.craftbukkit.v1_9_R1.entity.*; +import org.bukkit.craftbukkit.v1_9_R1.inventory.*; public class SpecialEnderChest extends InventorySubcontainer { private final CraftInventory inventory = new CraftInventory(this); diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index fe1cdad..390dc03 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -22,11 +22,16 @@ import org.bukkit.inventory.Inventory; import com.lishid.openinv.OpenInv; // Volatile -import net.minecraft.server.v1_8_R3.*; +import net.minecraft.server.v1_9_R1.*; -import org.bukkit.craftbukkit.v1_8_R3.entity.*; -import org.bukkit.craftbukkit.v1_8_R3.inventory.*; +import org.bukkit.craftbukkit.v1_9_R1.entity.*; +import org.bukkit.craftbukkit.v1_9_R1.inventory.*; +/* + * ----------------------------------------------- + * This class still needs to be updated for 1.9. + * ----------------------------------------------- + */ public class SpecialPlayerInventory extends PlayerInventory { private final CraftInventory inventory = new CraftInventory(this); private final ItemStack[] extra = new ItemStack[5]; diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java index 3508af5..25b6785 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvEntityListener.java @@ -38,7 +38,7 @@ public class OpenInvEntityListener implements Listener { Player player = (Player) attacker; - if (player.getItemInHand().getType() == OpenInv.getOpenInvItem()) { + if (player.getInventory().getItemInMainHand().getType() == OpenInv.getOpenInvItem()) { if (!OpenInv.getPlayerItemOpenInvStatus(player) || !OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { return; } diff --git a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java index 2c479f0..5e1f42b 100644 --- a/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java +++ b/src/main/java/com/lishid/openinv/listeners/OpenInvPlayerListener.java @@ -143,7 +143,7 @@ public class OpenInvPlayerListener implements Listener { } case RIGHT_CLICK_AIR: // OpenInv item - if (player.getItemInHand().getType() == OpenInv.getOpenInvItem() && OpenInv.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { + if (player.getInventory().getItemInMainHand().getType() == OpenInv.getOpenInvItem() && OpenInv.getPlayerItemOpenInvStatus(player) && OpenInv.hasPermission(player, Permissions.PERM_OPENINV)) { player.performCommand("openinv"); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fc8109c..c05d306 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.4 +version: 2.3.5 author: lishid description: > This plugin allows you to open a player's inventory as a chest and interact with it in real time. From 7ae87d1dbe93bd0482e5dcf564fc1397e1fd5144 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Wed, 2 Mar 2016 13:46:42 +1100 Subject: [PATCH 2/5] Updated to CraftBukkit 1.9 --- src/main/java/com/lishid/openinv/internal/AnySilentChest.java | 3 --- .../java/com/lishid/openinv/internal/EnumDirectionList.java | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java index 0f4fb06..d03a756 100644 --- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java @@ -60,9 +60,6 @@ public class AnySilentChest { } private boolean blockOnTop(World world, BlockPosition position) { - // return world.getType(position.up()).getBlock().isOccluding(); - - // TODO: Does this work? 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 fece744..2f49d3f 100644 --- a/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java +++ b/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java @@ -11,9 +11,9 @@ public enum EnumDirectionList implements Iterable { HORIZONTAL(EnumDirectionLimit.HORIZONTAL), VERTICAL(EnumDirectionLimit.VERTICAL); - private final EnumDirection.EnumDirectionLimit list; + private final EnumDirectionLimit list; - EnumDirectionList(EnumDirection.EnumDirectionLimit list) { + EnumDirectionList(EnumDirectionLimit list) { this.list = list; } From c4a9cb0a4a744a8a46ebc063a628d435e6aaaece Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Wed, 2 Mar 2016 20:11:45 +1100 Subject: [PATCH 3/5] 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 From 71ac05ae8515d3795df1f25919435e01308f4278 Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Fri, 4 Mar 2016 13:45:54 +1100 Subject: [PATCH 4/5] Updated to CraftBukkit 1.9 --- .../com/lishid/openinv/ConfigUpdater.java | 7 +- src/main/java/com/lishid/openinv/OpenInv.java | 13 ++- .../openinv/commands/AnyChestCommand.java | 1 + .../openinv/commands/OpenEnderCommand.java | 5 +- .../openinv/commands/OpenInvCommand.java | 1 + .../openinv/commands/SearchEnderCommand.java | 5 +- .../openinv/commands/SearchInvCommand.java | 5 +- .../openinv/commands/SilentChestCommand.java | 1 + .../commands/ToggleOpenInvCommand.java | 1 + .../openinv/internal/AnySilentChest.java | 30 ++++-- .../openinv/internal/EnumDirectionList.java | 1 + .../openinv/internal/InventoryAccess.java | 5 +- .../openinv/internal/PlayerDataManager.java | 7 +- .../internal/SilentContainerChest.java | 1 + .../openinv/internal/SilentInventory.java | 1 + .../openinv/internal/SpecialEnderChest.java | 1 + .../internal/SpecialPlayerInventory.java | 102 ++++++++++-------- 17 files changed, 115 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/lishid/openinv/ConfigUpdater.java b/src/main/java/com/lishid/openinv/ConfigUpdater.java index f3fa1bb..31a2fd9 100644 --- a/src/main/java/com/lishid/openinv/ConfigUpdater.java +++ b/src/main/java/com/lishid/openinv/ConfigUpdater.java @@ -13,6 +13,7 @@ import org.bukkit.configuration.file.FileConfiguration; import com.lishid.openinv.utils.UUIDUtil; public class ConfigUpdater { + private final OpenInv plugin; private static final int CONFIG_VERSION = 2; @@ -33,8 +34,7 @@ public class ConfigUpdater { if (isConfigOutdated()) { plugin.getLogger().info("[Config] Update found! Performing update..."); performUpdate(); - } - else { + } else { plugin.getLogger().info("[Config] Update not required."); } } @@ -137,6 +137,7 @@ public class ConfigUpdater { for (String playerName : keys) { UUID uuid = UUIDUtil.getUUIDOf(playerName); + if (uuid != null) { boolean toggled = section.getBoolean(playerName + ".toggle", false); toggles.put(uuid, toggled); @@ -152,9 +153,11 @@ public class ConfigUpdater { @SuppressWarnings("deprecation") private Material getMaterialById(int id) { Material material = Material.getMaterial(id); + if (material == null) { material = Material.STICK; } + return material; } } diff --git a/src/main/java/com/lishid/openinv/OpenInv.java b/src/main/java/com/lishid/openinv/OpenInv.java index 70a7aeb..863891b 100644 --- a/src/main/java/com/lishid/openinv/OpenInv.java +++ b/src/main/java/com/lishid/openinv/OpenInv.java @@ -45,12 +45,8 @@ import com.lishid.openinv.listeners.OpenInvEntityListener; import com.lishid.openinv.listeners.OpenInvInventoryListener; import com.lishid.openinv.listeners.OpenInvPlayerListener; -/** - * Open other player's inventory - * - * @author lishid - */ public class OpenInv extends JavaPlugin { + public static final Map inventories = new HashMap(); public static final Map enderChests = new HashMap(); @@ -114,11 +110,11 @@ public class OpenInv extends JavaPlugin { public static Object getFromConfig(String path, Object defaultValue) { Object val = mainPlugin.getConfig().get(path); + if (val == null) { mainPlugin.getConfig().set(path, defaultValue); return defaultValue; - } - else { + } else { return val; } } @@ -216,12 +212,15 @@ public class OpenInv extends JavaPlugin { public static boolean hasPermission(Permissible player, String permission) { String[] parts = permission.split("\\."); String perm = ""; + for (int i = 0; i < parts.length; i++) { if (player.hasPermission(perm + "*")) { return true; } + perm += parts[i] + "."; } + return player.hasPermission(permission); } } diff --git a/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java b/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java index 2ceae54..732f641 100644 --- a/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java +++ b/src/main/java/com/lishid/openinv/commands/AnyChestCommand.java @@ -26,6 +26,7 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; public class AnyChestCommand implements CommandExecutor { + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("anychest")) { diff --git a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java index 8d3b79f..ceb6472 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenEnderCommand.java @@ -33,6 +33,7 @@ import com.lishid.openinv.internal.SpecialEnderChest; import com.lishid.openinv.utils.UUIDUtil; public class OpenEnderCommand implements CommandExecutor { + private final OpenInv plugin; private final Map openEnderHistory = new ConcurrentHashMap(); @@ -73,8 +74,7 @@ public class OpenEnderCommand implements CommandExecutor { if (args.length < 1) { if (history != null) { uuid = history; - } - else { + } else { sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!"); return true; } @@ -111,6 +111,7 @@ public class OpenEnderCommand implements CommandExecutor { if (player == null) { return; } + openInventory(player, target); } }); diff --git a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java index fee3a81..75e093a 100644 --- a/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/OpenInvCommand.java @@ -33,6 +33,7 @@ import com.lishid.openinv.internal.SpecialPlayerInventory; import com.lishid.openinv.utils.UUIDUtil; public class OpenInvCommand implements CommandExecutor { + private final OpenInv plugin; private final Map openInvHistory = new ConcurrentHashMap(); diff --git a/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java index 71c4557..778a762 100644 --- a/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SearchEnderCommand.java @@ -12,6 +12,7 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; public class SearchEnderCommand implements CommandExecutor { + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("searchender")) { @@ -30,11 +31,11 @@ public class SearchEnderCommand implements CommandExecutor { gData = args[0].split(":"); material = Material.matchMaterial(gData[0]); } + if (args.length >= 2) { try { count = Integer.parseInt(args[1]); - } - catch (NumberFormatException ex) { + } catch (NumberFormatException e) { sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!"); return false; } diff --git a/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java index 584c5ad..46bf5f3 100644 --- a/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SearchInvCommand.java @@ -28,6 +28,7 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; public class SearchInvCommand implements CommandExecutor { + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("searchinv")) { @@ -46,11 +47,11 @@ public class SearchInvCommand implements CommandExecutor { gData = args[0].split(":"); material = Material.matchMaterial(gData[0]); } + if (args.length >= 2) { try { count = Integer.parseInt(args[1]); - } - catch (NumberFormatException ex) { + } catch (NumberFormatException e) { sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!"); return false; } diff --git a/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java b/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java index e2b0a46..afdc8c6 100644 --- a/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java +++ b/src/main/java/com/lishid/openinv/commands/SilentChestCommand.java @@ -26,6 +26,7 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; public class SilentChestCommand implements CommandExecutor { + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("silentchest")) { diff --git a/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java b/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java index 26d14ea..ac3c714 100644 --- a/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java +++ b/src/main/java/com/lishid/openinv/commands/ToggleOpenInvCommand.java @@ -26,6 +26,7 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; public class ToggleOpenInvCommand implements CommandExecutor { + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("toggleopeninv")) { diff --git a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java index e303823..8347aa6 100644 --- a/src/main/java/com/lishid/openinv/internal/AnySilentChest.java +++ b/src/main/java/com/lishid/openinv/internal/AnySilentChest.java @@ -29,6 +29,7 @@ import net.minecraft.server.v1_9_R1.BlockChest.Type; import org.bukkit.craftbukkit.v1_9_R1.entity.*; public class AnySilentChest { + public boolean isAnyChestNeeded(Player p, int x, int y, int z) { // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest BlockPosition position = new BlockPosition(x, y, z); @@ -37,16 +38,17 @@ public class AnySilentChest { BlockChest chest = (BlockChest) (((BlockChest) world.getType(position).getBlock()).g == Type.TRAP ? Block.getByName("trapped_chest") : Block.getByName("chest")); - // If block on top + // If a block is on top if (topBlocking(world, position)) { return true; } - // If block next to chest is chest and has a block on top + // If the block next to the chest is chest and has a block on top for (EnumDirection direction : EnumDirectionList.HORIZONTAL) { BlockPosition sidePosition = position.shift(direction); - Block var8 = world.getType(sidePosition).getBlock(); - if (var8 == chest) { + Block block = world.getType(sidePosition).getBlock(); + + if (block == chest) { if (this.topBlocking(world, sidePosition)) { return true; } @@ -55,6 +57,7 @@ public class AnySilentChest { return false; } + private boolean topBlocking(World world, BlockPosition position) { return this.blockOnTop(world, position) || this.ocelotOnTop(world, position); } @@ -65,20 +68,22 @@ public class AnySilentChest { } private boolean ocelotOnTop(World world, BlockPosition position) { - Iterator var3 = world.a(EntityOcelot.class, + Iterator iterator = world.a(EntityOcelot.class, new AxisAlignedBB((double) position.getX(), (double) (position.getY() + 1), (double) position.getZ(), (double) (position.getX() + 1), (double) (position.getY() + 2), (double) (position.getZ() + 1))).iterator(); - EntityOcelot var5; + EntityOcelot entityOcelot; + do { - if (!var3.hasNext()) { + if (!iterator.hasNext()) { return false; } - Entity var4 = (Entity) var3.next(); - var5 = (EntityOcelot) var4; - } while (!var5.isSitting()); + Entity entity = (Entity) iterator.next(); + + entityOcelot = (EntityOcelot) entity; + } while (!entityOcelot.isSitting()); return true; } @@ -107,12 +112,14 @@ public class AnySilentChest { for (EnumDirection direction : EnumDirectionList.HORIZONTAL) { BlockPosition side = position.shift(direction); Block block = world.getType(side).getBlock(); + if (block == chest) { if (!anyChest && this.topBlocking(world, side)) { return true; } TileEntity sideTileEntity = world.getTileEntity(side); + if (sideTileEntity instanceof TileEntityChest) { if (direction != EnumDirection.WEST && direction != EnumDirection.NORTH) { tileInventory = new InventoryLargeChest("container.chestDouble", tileInventory, (TileEntityChest) sideTileEntity); @@ -124,11 +131,14 @@ public class AnySilentChest { } boolean returnValue = true; + if (silentChest) { tileInventory = new SilentInventory(tileInventory); + if (OpenInv.notifySilentChest()) { OpenInv.sendMessage(p, "You are opening a chest silently."); } + returnValue = false; } diff --git a/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java b/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java index 2f49d3f..2cd77f6 100644 --- a/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java +++ b/src/main/java/com/lishid/openinv/internal/EnumDirectionList.java @@ -8,6 +8,7 @@ import net.minecraft.server.v1_9_R1.EnumDirection; import net.minecraft.server.v1_9_R1.EnumDirection.EnumDirectionLimit; public enum EnumDirectionList implements Iterable { + HORIZONTAL(EnumDirectionLimit.HORIZONTAL), VERTICAL(EnumDirectionLimit.VERTICAL); diff --git a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java index 8c6327a..cf8e2f1 100644 --- a/src/main/java/com/lishid/openinv/internal/InventoryAccess.java +++ b/src/main/java/com/lishid/openinv/internal/InventoryAccess.java @@ -30,6 +30,7 @@ import net.minecraft.server.v1_9_R1.*; import org.bukkit.craftbukkit.v1_9_R1.inventory.*; public class InventoryAccess { + public boolean check(Inventory inventory, HumanEntity player) { IInventory inv = grabInventory(inventory); @@ -62,12 +63,12 @@ public class InventoryAccess { if (IInventory.class.isAssignableFrom(f.getDeclaringClass())) { try { result = (IInventory) f.get(inventory); - } - catch (Exception e) { + } catch (Exception e) { OpenInv.log(e); } } } + return result; } } diff --git a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java index dc4083f..4e4aef0 100644 --- a/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java +++ b/src/main/java/com/lishid/openinv/internal/PlayerDataManager.java @@ -31,12 +31,14 @@ import net.minecraft.server.v1_9_R1.*; import org.bukkit.craftbukkit.v1_9_R1.*; public class PlayerDataManager { + public Player loadPlayer(UUID uuid) { try { OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); if (player == null || !player.hasPlayedBefore()) { return null; } + GameProfile profile = new GameProfile(uuid, player.getName()); MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); // Create an entity to load the player data @@ -44,14 +46,15 @@ public class PlayerDataManager { // Get the bukkit entity Player target = entity.getBukkitEntity(); + if (target != null) { // Load data target.loadData(); + // Return the entity return target; } - } - catch (Exception e) { + } catch (Exception e) { OpenInv.log(e); } diff --git a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java index f2af89f..301c813 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java +++ b/src/main/java/com/lishid/openinv/internal/SilentContainerChest.java @@ -20,6 +20,7 @@ package com.lishid.openinv.internal; import net.minecraft.server.v1_9_R1.*; public class SilentContainerChest extends ContainerChest { + public IInventory inv; public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman human) { diff --git a/src/main/java/com/lishid/openinv/internal/SilentInventory.java b/src/main/java/com/lishid/openinv/internal/SilentInventory.java index b05211c..ee802c5 100644 --- a/src/main/java/com/lishid/openinv/internal/SilentInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SilentInventory.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.InventoryHolder; import net.minecraft.server.v1_9_R1.*; public class SilentInventory implements ITileInventory { + public ITileInventory inv; public SilentInventory(ITileInventory inv) { diff --git a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java index fdccf4a..4c37370 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialEnderChest.java @@ -29,6 +29,7 @@ import org.bukkit.craftbukkit.v1_9_R1.entity.*; import org.bukkit.craftbukkit.v1_9_R1.inventory.*; public class SpecialEnderChest extends InventorySubcontainer { + private final CraftInventory inventory = new CraftInventory(this); private final InventoryEnderChest enderChest; private final CraftPlayer owner; diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index 40e8193..f16661b 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -16,40 +16,67 @@ package com.lishid.openinv.internal; +import java.lang.reflect.Field; + import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import com.lishid.openinv.OpenInv; - // Volatile import net.minecraft.server.v1_9_R1.*; import org.bukkit.craftbukkit.v1_9_R1.entity.*; 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. - * ----------------------------------------------- - */ +import com.lishid.openinv.OpenInv; + 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 ItemStack[][] arrays; private final CraftPlayer owner; private boolean playerOnline; public SpecialPlayerInventory(Player p, boolean online) { super(((CraftPlayer) p).getHandle()); this.owner = (CraftPlayer) p; - 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}; + // applyContents(); + reflectContents(getClass().getSuperclass(), player.inventory, this); + this.arrays = new ItemStack[][] { this.items, this.armor, this.extra }; this.playerOnline = online; - // OpenInv.inventories.put(owner.getUniqueId(), this); + OpenInv.inventories.put(owner.getUniqueId(), this); + } + + private void reflectContents(Class clazz, PlayerInventory src, PlayerInventory dest) { + // Items + try { + Field itemsField = clazz.getDeclaredField("items"); + itemsField.setAccessible(true); + itemsField.set(dest, src.items); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + // Armor + try { + Field armorField = clazz.getDeclaredField("armor"); + armorField.setAccessible(true); + armorField.set(dest, src.armor); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } } public Inventory getBukkitInventory() { @@ -57,19 +84,14 @@ 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) { - System.arraycopy(this.items, 0, inventory.items, 0, inventory.items.length); - System.arraycopy(this.armor, 0, inventory.armor, 0, inventory.armor.length); + reflectContents(inventory.getClass(), inventory, this); } public void playerOnline(Player player) { @@ -104,17 +126,18 @@ public class SpecialPlayerInventory extends PlayerInventory { @Override public int getSize() { - return super.getSize() + 5; // super.getSize() - this.extraSlots.length + 5; + return super.getSize() - this.extraSlots.length + 5; } @Override public ItemStack getItem(int i) { ItemStack[] is = null; - ItemStack[][] contents = this.g; + ItemStack[][] contents = this.arrays; int j = contents.length; for (int k = 0; k < j; ++k) { ItemStack[] is2 = contents[k]; + if (i < is2.length) { is = is2; break; @@ -137,11 +160,12 @@ public class SpecialPlayerInventory extends PlayerInventory { @Override public ItemStack splitStack(int i, int j) { ItemStack[] is = null; - ItemStack[][] contents = this.g; + ItemStack[][] contents = this.arrays; int k = contents.length; for (int l = 0; l < k; ++l) { ItemStack[] is2 = contents[l]; + if (i < is2.length) { is = is2; break; @@ -164,11 +188,12 @@ public class SpecialPlayerInventory extends PlayerInventory { @Override public ItemStack splitWithoutUpdate(int i) { ItemStack[] is = null; - ItemStack[][] contents = this.g; + ItemStack[][] contents = this.arrays; int j = contents.length; for (int object = 0; object < j; ++object) { ItemStack[] is2 = contents[object]; + if (i < is2.length) { is = is2; break; @@ -177,7 +202,6 @@ public class SpecialPlayerInventory extends PlayerInventory { i -= is2.length; } - if (is != null && is[i] != null) { if (is == this.items) { i = getReversedItemSlotNum(i); @@ -198,11 +222,12 @@ public class SpecialPlayerInventory extends PlayerInventory { @Override public void setItem(int i, ItemStack itemStack) { ItemStack[] is = null; - ItemStack[][] contents = this.g; + ItemStack[][] contents = this.arrays; int j = contents.length; for (int k = 0; k < j; ++k) { ItemStack[] is2 = contents[k]; + if (i < is2.length) { is = is2; break; @@ -223,28 +248,19 @@ public class SpecialPlayerInventory extends PlayerInventory { is[i] = itemStack; - // owner.getHandle().defaultContainer.b(); + owner.getHandle().defaultContainer.b(); } } private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return i + 9; + return (i >= 27) ? (i - 27) : (i + 9); } private int getReversedArmorSlotNum(int i) { - if (i == 0) - return 3; - if (i == 1) - return 2; - if (i == 2) - return 1; - if (i == 3) - return 0; - else - return i; + if (i == 0) return 3; + if (i == 1) return 2; + if (i == 2) return 1; + return (i == 3) ? 0 : i; } @Override From 14ec280d26a59fde18a0a85229cb8c0e385d180a Mon Sep 17 00:00:00 2001 From: ShadowRanger Date: Fri, 4 Mar 2016 13:46:29 +1100 Subject: [PATCH 5/5] Updated to CraftBukkit 1.9 --- .../java/com/lishid/openinv/internal/SpecialPlayerInventory.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java index f16661b..029a8cf 100644 --- a/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java +++ b/src/main/java/com/lishid/openinv/internal/SpecialPlayerInventory.java @@ -40,7 +40,6 @@ public class SpecialPlayerInventory extends PlayerInventory { public SpecialPlayerInventory(Player p, boolean online) { super(((CraftPlayer) p).getHandle()); this.owner = (CraftPlayer) p; - // applyContents(); reflectContents(getClass().getSuperclass(), player.inventory, this); this.arrays = new ItemStack[][] { this.items, this.armor, this.extra }; this.playerOnline = online;