diff --git a/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java b/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java index 364c3dd..59624a9 100644 --- a/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java +++ b/src/com/lishid/openinv/commands/OpenEnderPluginCommand.java @@ -17,12 +17,17 @@ package com.lishid.openinv.commands; import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; @@ -37,6 +42,7 @@ public class OpenEnderPluginCommand implements CommandExecutor { this.plugin = plugin; } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You can't use this from the console."); @@ -53,8 +59,7 @@ public class OpenEnderPluginCommand implements CommandExecutor { return true; } - Player player = (Player) sender; - boolean offline = false; + final Player player = (Player) sender; // History management String history = openEnderHistory.get(player); @@ -64,55 +69,79 @@ public class OpenEnderPluginCommand implements CommandExecutor { openEnderHistory.put(player, history); } - // Target selecting - Player target; - - String name = ""; + final String name; // Read from history if target is not named if (args.length < 1) { - if (history != null && history != "") { - name = history; - } - else { - sender.sendMessage(ChatColor.RED + "OpenEnder history is empty!"); - return true; - } + name = history; } else { name = args[0]; } - target = this.plugin.getServer().getPlayer(name); + sender.sendMessage(ChatColor.GREEN + "Starting inventory lookup."); + final UUID senderID = player.getUniqueId(); + new BukkitRunnable() { + @Override + public void run() { + List matches = Bukkit.matchPlayer(name); + if (!matches.isEmpty()) { + openInventory(player, matches.get(0).getUniqueId()); + return; + } + final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); + if (Bukkit.getPlayer(senderID) == null) { + return; + } + if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return; + } + new BukkitRunnable() { + @Override + public void run() { + if (Bukkit.getPlayer(senderID) == null) { + return; + } + openInventory(player, offlinePlayer.getUniqueId()); + } + }.runTask(plugin); + } + }.runTaskAsynchronously(plugin); + + return true; + } + + private void openInventory(Player player, UUID uuid) { + + Player target = this.plugin.getServer().getPlayer(uuid); if (target == null) { // Try loading the player's data - target = OpenInv.playerLoader.loadPlayer(name); + target = OpenInv.playerLoader.loadPlayer(uuid); if (target == null) { - sender.sendMessage(ChatColor.RED + "Player " + name + " not found!"); - return true; + player.sendMessage(ChatColor.RED + "Player not found!"); + return; } } - if (target != sender && !OpenInv.hasPermission(sender, Permissions.PERM_ENDERCHEST_ALL)) { - sender.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest"); - return true; + + if (target != player && !OpenInv.hasPermission(player, Permissions.PERM_ENDERCHEST_ALL)) { + player.sendMessage(ChatColor.RED + "You do not have permission to access other player's enderchest"); + return; } // Record the target - history = target.getName(); - openEnderHistory.put(player, history); + openEnderHistory.put(player, target.getName()); // Create the inventory ISpecialEnderChest chest = OpenInv.enderChests.get(target.getName().toLowerCase()); if (chest == null) { - chest = InternalAccessor.Instance.newSpecialEnderChest(target, !offline); + chest = InternalAccessor.Instance.newSpecialEnderChest(target, !target.isOnline()); } // Open the inventory player.openInventory(chest.getBukkitInventory()); - - return true; } } diff --git a/src/com/lishid/openinv/commands/OpenInvPluginCommand.java b/src/com/lishid/openinv/commands/OpenInvPluginCommand.java index 4457cde..108e0dc 100644 --- a/src/com/lishid/openinv/commands/OpenInvPluginCommand.java +++ b/src/com/lishid/openinv/commands/OpenInvPluginCommand.java @@ -17,12 +17,17 @@ package com.lishid.openinv.commands; import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; @@ -37,6 +42,7 @@ public class OpenInvPluginCommand implements CommandExecutor { this.plugin = plugin; } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "You can't use this from the console."); @@ -52,8 +58,7 @@ public class OpenInvPluginCommand implements CommandExecutor { return true; } - Player player = (Player) sender; - boolean offline = false; + final Player player = (Player) sender; // History management String history = openInvHistory.get(player); @@ -63,10 +68,7 @@ public class OpenInvPluginCommand implements CommandExecutor { openInvHistory.put(player, history); } - // Target selecting - Player target; - - String name = ""; + final String name; // Read from history if target is not named if (args.length < 1) { @@ -76,51 +78,80 @@ public class OpenInvPluginCommand implements CommandExecutor { name = args[0]; } - target = this.plugin.getServer().getPlayer(name); + final UUID senderID = player.getUniqueId(); + new BukkitRunnable() { + @Override + public void run() { + List matches = Bukkit.matchPlayer(name); + if (!matches.isEmpty()) { + openInventory(player, matches.get(0).getUniqueId()); + return; + } + final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); + if (Bukkit.getPlayer(senderID) == null) { + return; + } + if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return; + } + new BukkitRunnable() { + @Override + public void run() { + if (Bukkit.getPlayer(senderID) == null) { + return; + } + openInventory(player, offlinePlayer.getUniqueId()); + } + }.runTask(plugin); + } + }.runTaskAsynchronously(plugin); + + return true; + } + + private void openInventory(Player player, UUID uuid) { + + Player target = this.plugin.getServer().getPlayer(uuid); if (target == null) { - if (target == null) { - // Try loading the player's data - target = OpenInv.playerLoader.loadPlayer(name); + // Try loading the player's data + target = OpenInv.playerLoader.loadPlayer(uuid); - if (target == null) { - sender.sendMessage(ChatColor.RED + "Player " + name + " not found!"); - return true; - } + if (target == null) { + player.sendMessage(ChatColor.RED + "Player not found!"); + return; } } // Permissions checks if (!OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE) && OpenInv.hasPermission(target, Permissions.PERM_EXEMPT)) { - sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!"); - return true; + player.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!"); + return; } // Crosswork check if ((!OpenInv.hasPermission(player, Permissions.PERM_CROSSWORLD) && !OpenInv.hasPermission(player, Permissions.PERM_OVERRIDE)) && target.getWorld() != player.getWorld()) { - sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!"); - return true; + player.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!"); + return; } // Self-open check if (!OpenInv.hasPermission(player, Permissions.PERM_OPENSELF) && target.equals(player)) { - sender.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself."); - return true; + player.sendMessage(ChatColor.RED + "You're not allowed to openinv yourself."); + return; } // Record the target - history = target.getName(); - openInvHistory.put(player, history); + openInvHistory.put(player, target.getName()); // Create the inventory ISpecialPlayerInventory inv = OpenInv.inventories.get(target.getName().toLowerCase()); if (inv == null) { - inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, !offline); + inv = InternalAccessor.Instance.newSpecialPlayerInventory(target, !target.isOnline()); } // Open the inventory player.openInventory(inv.getBukkitInventory()); - - return true; } } diff --git a/src/com/lishid/openinv/internal/IPlayerDataManager.java b/src/com/lishid/openinv/internal/IPlayerDataManager.java index ce0ed2f..ec2af50 100644 --- a/src/com/lishid/openinv/internal/IPlayerDataManager.java +++ b/src/com/lishid/openinv/internal/IPlayerDataManager.java @@ -16,8 +16,11 @@ package com.lishid.openinv.internal; +import java.util.UUID; + import org.bukkit.entity.Player; public interface IPlayerDataManager { public Player loadPlayer(String name); + public Player loadPlayer(UUID uuid); } diff --git a/src/com/lishid/openinv/internal/craftbukkit/AnySilentChest.java b/src/com/lishid/openinv/internal/craftbukkit/AnySilentChest.java deleted file mode 100644 index df0b089..0000000 --- a/src/com/lishid/openinv/internal/craftbukkit/AnySilentChest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.craftbukkit; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.*; - -import org.bukkit.craftbukkit.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.s(x, y + 1, z)) - return true; - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - if (!anychest) { - if (world.s(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int id = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - id = windowID.getInt(player); - id = id % 100 + 1; - windowID.setInt(player, id); - } - catch (NoSuchFieldException e) {} - - player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = id; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/craftbukkit/InventoryAccess.java b/src/com/lishid/openinv/internal/craftbukkit/InventoryAccess.java deleted file mode 100644 index 3ac3352..0000000 --- a/src/com/lishid/openinv/internal/craftbukkit/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.craftbukkit; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.*; -import org.bukkit.craftbukkit.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/craftbukkit/PlayerDataManager.java b/src/com/lishid/openinv/internal/craftbukkit/PlayerDataManager.java deleted file mode 100644 index 6a67c37..0000000 --- a/src/com/lishid/openinv/internal/craftbukkit/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.craftbukkit; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.*; -import org.bukkit.craftbukkit.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new ItemInWorldManager(server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/craftbukkit/SilentContainerChest.java b/src/com/lishid/openinv/internal/craftbukkit/SilentContainerChest.java deleted file mode 100644 index a5128f0..0000000 --- a/src/com/lishid/openinv/internal/craftbukkit/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.craftbukkit; - -//Volatile -import net.minecraft.server.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.f(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/craftbukkit/SpecialEnderChest.java b/src/com/lishid/openinv/internal/craftbukkit/SpecialEnderChest.java deleted file mode 100644 index 5b10faa..0000000 --- a/src/com/lishid/openinv/internal/craftbukkit/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.craftbukkit; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.*; -import org.bukkit.craftbukkit.entity.*; -import org.bukkit.craftbukkit.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/craftbukkit/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/craftbukkit/SpecialPlayerInventory.java deleted file mode 100644 index 280cce2..0000000 --- a/src/com/lishid/openinv/internal/craftbukkit/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.craftbukkit; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.*; -import org.bukkit.craftbukkit.entity.*; -import org.bukkit.craftbukkit.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); - } - return player.name; - } - - @Override - public boolean a_(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java deleted file mode 100644 index 50d6921..0000000 --- a/src/com/lishid/openinv/internal/v1_4_5/AnySilentChest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_5; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_4_5.*; - -import org.bukkit.craftbukkit.v1_4_5.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.s(x, y + 1, z)) - return true; - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - if (!anychest) { - if (world.s(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int id = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - id = windowID.getInt(player); - id = id % 100 + 1; - windowID.setInt(player, id); - } - catch (NoSuchFieldException e) {} - - player.netServerHandler.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = id; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_5/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_4_5/InventoryAccess.java deleted file mode 100644 index b4f6d7e..0000000 --- a/src/com/lishid/openinv/internal/v1_4_5/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_5; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_4_5.*; -import org.bukkit.craftbukkit.v1_4_5.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java deleted file mode 100644 index 9138717..0000000 --- a/src/com/lishid/openinv/internal/v1_4_5/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_5; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_4_5.*; -import org.bukkit.craftbukkit.v1_4_5.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new ItemInWorldManager(server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_5/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_4_5/SilentContainerChest.java deleted file mode 100644 index 9663096..0000000 --- a/src/com/lishid/openinv/internal/v1_4_5/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_5; - -//Volatile -import net.minecraft.server.v1_4_5.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.f(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java deleted file mode 100644 index 912f8dc..0000000 --- a/src/com/lishid/openinv/internal/v1_4_5/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_5; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_4_5.*; -import org.bukkit.craftbukkit.v1_4_5.entity.*; -import org.bukkit.craftbukkit.v1_4_5.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); - } - return player.name; - } - - @Override - public boolean a_(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java deleted file mode 100644 index ea08779..0000000 --- a/src/com/lishid/openinv/internal/v1_4_6/AnySilentChest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_6; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_4_6.*; - -import org.bukkit.craftbukkit.v1_4_6.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.s(x, y + 1, z)) - return true; - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - if (!anychest) { - if (world.s(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int id = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - id = windowID.getInt(player); - id = id % 100 + 1; - windowID.setInt(player, id); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = id; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_6/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_4_6/InventoryAccess.java deleted file mode 100644 index b71024c..0000000 --- a/src/com/lishid/openinv/internal/v1_4_6/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_6; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_4_6.*; -import org.bukkit.craftbukkit.v1_4_6.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java deleted file mode 100644 index 84b37ad..0000000 --- a/src/com/lishid/openinv/internal/v1_4_6/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_6; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_4_6.*; -import org.bukkit.craftbukkit.v1_4_6.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager(server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java deleted file mode 100644 index 953e8d6..0000000 --- a/src/com/lishid/openinv/internal/v1_4_6/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_6; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_4_6.*; -import org.bukkit.craftbukkit.v1_4_6.entity.*; -import org.bukkit.craftbukkit.v1_4_6.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java deleted file mode 100644 index e5299f1..0000000 --- a/src/com/lishid/openinv/internal/v1_4_6/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_6; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_4_6.*; -import org.bukkit.craftbukkit.v1_4_6.entity.*; -import org.bukkit.craftbukkit.v1_4_6.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); - } - return player.name; - } - - @Override - public boolean a_(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java deleted file mode 100644 index aa21018..0000000 --- a/src/com/lishid/openinv/internal/v1_4_R1/AnySilentChest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_R1; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_4_R1.*; - -import org.bukkit.craftbukkit.v1_4_R1.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.s(x, y + 1, z)) - return true; - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - if (!anychest) { - if (world.s(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.s(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.s(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.s(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.s(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == Block.CHEST.id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int id = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - id = windowID.getInt(player); - id = id % 100 + 1; - windowID.setInt(player, id); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new Packet100OpenWindow(id, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize())); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = id; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_R1/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_4_R1/InventoryAccess.java deleted file mode 100644 index 6ac96fe..0000000 --- a/src/com/lishid/openinv/internal/v1_4_R1/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_R1; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_4_R1.*; -import org.bukkit.craftbukkit.v1_4_R1.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java deleted file mode 100644 index 0f69936..0000000 --- a/src/com/lishid/openinv/internal/v1_4_R1/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_R1; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_4_R1.*; -import org.bukkit.craftbukkit.v1_4_R1.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager(server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_R1/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_4_R1/SilentContainerChest.java deleted file mode 100644 index 7364a38..0000000 --- a/src/com/lishid/openinv/internal/v1_4_R1/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_R1; - -//Volatile -import net.minecraft.server.v1_4_R1.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.f(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java deleted file mode 100644 index 93e02c2..0000000 --- a/src/com/lishid/openinv/internal/v1_4_R1/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_R1; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_4_R1.*; -import org.bukkit.craftbukkit.v1_4_R1.entity.*; -import org.bukkit.craftbukkit.v1_4_R1.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java deleted file mode 100644 index fd6126a..0000000 --- a/src/com/lishid/openinv/internal/v1_4_R1/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_R1; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_4_R1.*; -import org.bukkit.craftbukkit.v1_4_R1.entity.*; -import org.bukkit.craftbukkit.v1_4_R1.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); - } - return player.name; - } - - @Override - public boolean a_(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java deleted file mode 100644 index f91b90e..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R2/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R2; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_5_R2.*; - -import org.bukkit.craftbukkit.v1_5_R2.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.t(x, y + 1, z)) - return true; - - int id = world.getTypeId(x, y, z); - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = world.getTypeId(x, y, z); - - if (!anychest) { - if (world.t(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java deleted file mode 100644 index 56bc450..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R2/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R2; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_5_R2.*; -import org.bukkit.craftbukkit.v1_5_R2.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java deleted file mode 100644 index 6768a97..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R2/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R2; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_5_R2.*; -import org.bukkit.craftbukkit.v1_5_R2.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java deleted file mode 100644 index 4eb0ecb..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R2/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R2; - -//Volatile -import net.minecraft.server.v1_5_R2.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.g(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java deleted file mode 100644 index add6767..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R2/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R2; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_5_R2.*; -import org.bukkit.craftbukkit.v1_5_R2.entity.*; -import org.bukkit.craftbukkit.v1_5_R2.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java deleted file mode 100644 index e4cee51..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R2/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R2; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_5_R2.*; -import org.bukkit.craftbukkit.v1_5_R2.entity.*; -import org.bukkit.craftbukkit.v1_5_R2.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); - } - return player.name; - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java deleted file mode 100644 index 0f3805c..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R3/AnySilentChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R3; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -import com.lishid.openinv.internal.v1_5_R3.SilentContainerChest; - -//Volatile -import net.minecraft.server.v1_5_R3.*; - -import org.bukkit.craftbukkit.v1_5_R3.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.t(x, y + 1, z)) - return true; - - int id = world.getTypeId(x, y, z); - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = world.getTypeId(x, y, z); - - if (!anychest) { - if (world.t(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java deleted file mode 100644 index 192619c..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R3/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R3; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_5_R3.*; -import org.bukkit.craftbukkit.v1_5_R3.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java deleted file mode 100644 index 82e03fc..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R3/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R3; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_5_R3.*; -import org.bukkit.craftbukkit.v1_5_R3.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java deleted file mode 100644 index 66615b1..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R3/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R3; - -//Volatile -import net.minecraft.server.v1_5_R3.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.g(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java deleted file mode 100644 index f3010ec..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R3/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R3; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_5_R3.*; -import org.bukkit.craftbukkit.v1_5_R3.entity.*; -import org.bukkit.craftbukkit.v1_5_R3.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java deleted file mode 100644 index 3afdec8..0000000 --- a/src/com/lishid/openinv/internal/v1_5_R3/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_5_R3; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_5_R3.*; -import org.bukkit.craftbukkit.v1_5_R3.entity.*; -import org.bukkit.craftbukkit.v1_5_R3.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.name.length() > 16) { - return player.name.substring(0, 16); - } - return player.name; - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java deleted file mode 100644 index b081942..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R1/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R1; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_6_R1.*; - -import org.bukkit.craftbukkit.v1_6_R1.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.t(x, y + 1, z)) - return true; - - int id = world.getTypeId(x, y, z); - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = world.getTypeId(x, y, z); - - if (!anychest) { - if (world.t(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java deleted file mode 100644 index 15acaa7..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R1/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R1; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_6_R1.*; -import org.bukkit.craftbukkit.v1_6_R1.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java deleted file mode 100644 index 393eedf..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R1/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R1; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_6_R1.*; -import org.bukkit.craftbukkit.v1_6_R1.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java deleted file mode 100644 index 1e63378..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R1/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R1; - -//Volatile -import net.minecraft.server.v1_6_R1.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.g(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java deleted file mode 100644 index 1a30c97..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R1/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R1; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_6_R1.*; -import org.bukkit.craftbukkit.v1_6_R1.entity.*; -import org.bukkit.craftbukkit.v1_6_R1.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java deleted file mode 100644 index 8aaa85f..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R1/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R1; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_6_R1.*; -import org.bukkit.craftbukkit.v1_6_R1.entity.*; -import org.bukkit.craftbukkit.v1_6_R1.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.getName().length() > 16) { - return player.getName().substring(0, 16); - } - return player.getName(); - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R2/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_6_R2/AnySilentChest.java deleted file mode 100644 index e516a71..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R2/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R2; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_6_R2.*; - -import org.bukkit.craftbukkit.v1_6_R2.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.t(x, y + 1, z)) - return true; - - int id = world.getTypeId(x, y, z); - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = world.getTypeId(x, y, z); - - if (!anychest) { - if (world.t(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R2/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_6_R2/InventoryAccess.java deleted file mode 100644 index 6325e80..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R2/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R2; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_6_R2.*; -import org.bukkit.craftbukkit.v1_6_R2.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java deleted file mode 100644 index 3143ab3..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R2/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R2; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_6_R2.*; -import org.bukkit.craftbukkit.v1_6_R2.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R2/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_6_R2/SilentContainerChest.java deleted file mode 100644 index d014f35..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R2/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R2; - -//Volatile -import net.minecraft.server.v1_6_R2.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.g(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java deleted file mode 100644 index 9d25cbb..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R2/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R2; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_6_R2.*; -import org.bukkit.craftbukkit.v1_6_R2.entity.*; -import org.bukkit.craftbukkit.v1_6_R2.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java deleted file mode 100644 index 3f59a7c..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R2/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R2; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_6_R2.*; -import org.bukkit.craftbukkit.v1_6_R2.entity.*; -import org.bukkit.craftbukkit.v1_6_R2.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.getName().length() > 16) { - return player.getName().substring(0, 16); - } - return player.getName(); - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R3/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_6_R3/AnySilentChest.java deleted file mode 100644 index e2a93e7..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R3/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R3; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_6_R3.*; - -import org.bukkit.craftbukkit.v1_6_R3.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.t(x, y + 1, z)) - return true; - - int id = world.getTypeId(x, y, z); - - // If block next to chest is chest and has a block on top - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = world.getTypeId(x, y, z); - - if (!anychest) { - if (world.t(x, y + 1, z)) - return true; - if ((world.getTypeId(x - 1, y, z) == id) && (world.t(x - 1, y + 1, z))) - return true; - if ((world.getTypeId(x + 1, y, z) == id) && (world.t(x + 1, y + 1, z))) - return true; - if ((world.getTypeId(x, y, z - 1) == id) && (world.t(x, y + 1, z - 1))) - return true; - if ((world.getTypeId(x, y, z + 1) == id) && (world.t(x, y + 1, z + 1))) - return true; - } - - if (world.getTypeId(x - 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (world.getTypeId(x + 1, y, z) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (world.getTypeId(x, y, z - 1) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (world.getTypeId(x, y, z + 1) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new Packet100OpenWindow(windowId, 0, ((IInventory) chest).getName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R3/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_6_R3/InventoryAccess.java deleted file mode 100644 index ecf5740..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R3/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R3; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_6_R3.*; -import org.bukkit.craftbukkit.v1_6_R3.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java deleted file mode 100644 index e87eb7a..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R3/PlayerDataManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R3; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; - -//Volatile -import net.minecraft.server.v1_6_R3.*; -import org.bukkit.craftbukkit.v1_6_R3.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), playername, new PlayerInteractManager((World) server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R3/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_6_R3/SilentContainerChest.java deleted file mode 100644 index 3a37b25..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R3/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R3; - -//Volatile -import net.minecraft.server.v1_6_R3.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.g(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java deleted file mode 100644 index f04726d..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R3/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R3; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_6_R3.*; -import org.bukkit.craftbukkit.v1_6_R3.entity.*; -import org.bukkit.craftbukkit.v1_6_R3.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().c(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java deleted file mode 100644 index 485e98f..0000000 --- a/src/com/lishid/openinv/internal/v1_6_R3/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_6_R3; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_6_R3.*; -import org.bukkit.craftbukkit.v1_6_R3.entity.*; -import org.bukkit.craftbukkit.v1_6_R3.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getName() { - if (player.getName().length() > 16) { - return player.getName().substring(0, 16); - } - return player.getName(); - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_7_R1/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_7_R1/AnySilentChest.java deleted file mode 100644 index 92aa7ec..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R1/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R1; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_7_R1.*; - -import org.bukkit.craftbukkit.v1_7_R1.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.getType(x, y + 1, z).c()) - return true; - - int id = Block.b(world.getType(x, y, z)); - - // If block next to chest is chest and has a block on top - if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = Block.b(world.getType(x, y, z)); - - if (!anychest) { - if (world.getType(x, y + 1, z).c()) - return true; - if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - } - - if (Block.b(world.getType(x - 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (Block.b(world.getType(x + 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (Block.b(world.getType(x, y, z - 1)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (Block.b(world.getType(x, y, z + 1)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R1/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_7_R1/InventoryAccess.java deleted file mode 100644 index 6121bcb..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R1/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R1; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_7_R1.*; -import org.bukkit.craftbukkit.v1_7_R1.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java deleted file mode 100644 index 96423ce..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R1/PlayerDataManager.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R1; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; -import net.minecraft.util.com.mojang.authlib.GameProfile; - -//Volatile -import net.minecraft.server.v1_7_R1.*; -import org.bukkit.craftbukkit.v1_7_R1.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - GameProfile profile = new GameProfile(null, playername); - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R1/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_7_R1/SilentContainerChest.java deleted file mode 100644 index eaf44e3..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R1/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R1; - -//Volatile -import net.minecraft.server.v1_7_R1.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.l_(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java deleted file mode 100644 index 24d3dc8..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R1/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R1; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_7_R1.*; -import org.bukkit.craftbukkit.v1_7_R1.entity.*; -import org.bukkit.craftbukkit.v1_7_R1.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java deleted file mode 100644 index 7229487..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R1/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R1; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_7_R1.*; -import org.bukkit.craftbukkit.v1_7_R1.entity.*; -import org.bukkit.craftbukkit.v1_7_R1.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack, true); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getInventoryName() { - if (player.getName().length() > 16) { - return player.getName().substring(0, 16); - } - return player.getName(); - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_7_R2/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_7_R2/AnySilentChest.java deleted file mode 100644 index ef4e932..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R2/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R2; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_7_R2.*; - -import org.bukkit.craftbukkit.v1_7_R2.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.getType(x, y + 1, z).c()) - return true; - - int id = Block.b(world.getType(x, y, z)); - - // If block next to chest is chest and has a block on top - if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = Block.b(world.getType(x, y, z)); - - if (!anychest) { - if (world.getType(x, y + 1, z).c()) - return true; - if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - } - - if (Block.b(world.getType(x - 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (Block.b(world.getType(x + 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (Block.b(world.getType(x, y, z - 1)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (Block.b(world.getType(x, y, z + 1)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R2/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_7_R2/InventoryAccess.java deleted file mode 100644 index 5d04cd3..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R2/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R2; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_7_R2.*; -import org.bukkit.craftbukkit.v1_7_R2.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java deleted file mode 100644 index 35ce584..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R2/PlayerDataManager.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R2; - -import java.io.File; -import java.util.Arrays; -import java.util.Collection; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; -import net.minecraft.util.com.mojang.authlib.GameProfile; - -//Volatile -import net.minecraft.server.v1_7_R2.*; -import org.bukkit.craftbukkit.v1_7_R2.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "players"); - if (!playerfolder.exists()) { - return null; - } - - String playername = matchUser(Arrays.asList(playerfolder.listFiles()), name); - - if (playername == null) { - return null; - } - - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - - GameProfile profile = new GameProfile(null, playername); - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - /** - * @author Balor (aka Antoine Aflalo) - */ - private static String matchUser(final Collection container, final String search) { - String found = null; - if (search == null) { - return found; - } - final String lowerSearch = search.toLowerCase(); - int delta = Integer.MAX_VALUE; - for (final File file : container) { - final String filename = file.getName(); - final String str = filename.substring(0, filename.length() - 4); - if (!str.toLowerCase().startsWith(lowerSearch)) { - continue; - } - final int curDelta = str.length() - lowerSearch.length(); - if (curDelta < delta) { - found = str; - delta = curDelta; - } - if (curDelta == 0) { - break; - } - - } - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R2/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_7_R2/SilentContainerChest.java deleted file mode 100644 index ef092cb..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R2/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R2; - -//Volatile -import net.minecraft.server.v1_7_R2.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.l_(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java deleted file mode 100644 index a24f7b5..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R2/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R2; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_7_R2.*; -import org.bukkit.craftbukkit.v1_7_R2.entity.*; -import org.bukkit.craftbukkit.v1_7_R2.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java deleted file mode 100644 index d3e0160..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R2/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R2; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_7_R2.*; -import org.bukkit.craftbukkit.v1_7_R2.entity.*; -import org.bukkit.craftbukkit.v1_7_R2.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack, true); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getInventoryName() { - if (player.getName().length() > 16) { - return player.getName().substring(0, 16); - } - return player.getName(); - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_7_R3/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_7_R3/AnySilentChest.java deleted file mode 100644 index 7eb95a5..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R3/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R3; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_7_R3.*; - -import org.bukkit.craftbukkit.v1_7_R3.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.getType(x, y + 1, z).c()) - return true; - - int id = Block.b(world.getType(x, y, z)); - - // If block next to chest is chest and has a block on top - if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = Block.b(world.getType(x, y, z)); - - if (!anychest) { - if (world.getType(x, y + 1, z).c()) - return true; - if ((Block.b(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.b(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.b(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - } - - if (Block.b(world.getType(x - 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (Block.b(world.getType(x + 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (Block.b(world.getType(x, y, z - 1)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (Block.b(world.getType(x, y, z + 1)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R3/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_7_R3/InventoryAccess.java deleted file mode 100644 index 234fd2b..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R3/InventoryAccess.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R3; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.Permissions; -import com.lishid.openinv.internal.IInventoryAccess; - -//Volatile -import net.minecraft.server.v1_7_R3.*; -import org.bukkit.craftbukkit.v1_7_R3.inventory.*; - -public class InventoryAccess implements IInventoryAccess { - public boolean check(Inventory inventory, HumanEntity player) { - IInventory inv = ((CraftInventory) inventory).getInventory(); - - if (inv instanceof SpecialPlayerInventory) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { - return false; - } - } - - else if (inv instanceof SpecialEnderChest) { - if (!OpenInv.hasPermission(player, Permissions.PERM_EDITENDER)) { - return false; - } - } - - return true; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java deleted file mode 100644 index 2976b83..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R3/PlayerDataManager.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R3; - -import java.io.File; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IPlayerDataManager; -import net.minecraft.util.com.mojang.authlib.GameProfile; - -//Volatile -import net.minecraft.server.v1_7_R3.*; - -import org.bukkit.craftbukkit.v1_7_R3.*; - -public class PlayerDataManager implements IPlayerDataManager { - public Player loadPlayer(String name) { - try { - UUID uuid = matchUser(name); - if (uuid == null) { - return null; - } - - // Default player folder - File playerfolder = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "playerdata"); - if (!playerfolder.exists()) { - return null; - } - - OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); - if (player == null) { - return null; - } - GameProfile profile = new GameProfile(uuid, player.getName()); - MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); - // Create an entity to load the player data - EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); - - // Get the bukkit entity - Player target = (entity == null) ? null : entity.getBukkitEntity(); - if (target != null) { - // Load data - target.loadData(); - // Return the entity - return target; - } - } - catch (Exception e) { - OpenInv.log(e); - } - - return null; - } - - private static UUID matchUser(String search) { - UUID found = null; - - String lowerSearch = search.toLowerCase(); - int delta = 2147483647; - - OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers(); - for (OfflinePlayer player : offlinePlayers) { - String name = player.getName(); - - if (name.equalsIgnoreCase(search)) - return player.getUniqueId(); - - if (name.toLowerCase().startsWith(lowerSearch)) { - int curDelta = name.length() - lowerSearch.length(); - if (curDelta < delta) { - found = player.getUniqueId(); - delta = curDelta; - } - if (curDelta == 0) { - break; - } - } - } - - return found; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R3/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_7_R3/SilentContainerChest.java deleted file mode 100644 index 867e714..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R3/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R3; - -//Volatile -import net.minecraft.server.v1_7_R3.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.l_(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java deleted file mode 100644 index 47a2235..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R3/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R3; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_7_R3.*; -import org.bukkit.craftbukkit.v1_7_R3.entity.*; -import org.bukkit.craftbukkit.v1_7_R3.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R4/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_7_R4/AnySilentChest.java deleted file mode 100644 index 76efb80..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R4/AnySilentChest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R4; - -import java.lang.reflect.Field; - -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.IAnySilentChest; - -//Volatile -import net.minecraft.server.v1_7_R4.*; - -import org.bukkit.craftbukkit.v1_7_R4.entity.*; - -public class AnySilentChest implements IAnySilentChest { - public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { - // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - // If block on top - if (world.getType(x, y + 1, z).c()) - return true; - - int id = Block.getId(world.getType(x, y, z)); - - // If block next to chest is chest and has a block on top - if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - - return false; - } - - public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { - EntityPlayer player = ((CraftPlayer) p).getHandle(); - World world = player.world; - Object chest = (TileEntityChest) world.getTileEntity(x, y, z); - if (chest == null) - return true; - - int id = Block.getId(world.getType(x, y, z)); - - if (!anychest) { - if (world.getType(x, y + 1, z).c()) - return true; - if ((Block.getId(world.getType(x - 1, y, z)) == id) && (world.getType(x - 1, y + 1, z).c())) - return true; - if ((Block.getId(world.getType(x + 1, y, z)) == id) && (world.getType(x + 1, y + 1, z).c())) - return true; - if ((Block.getId(world.getType(x, y, z - 1)) == id) && (world.getType(x, y + 1, z - 1).c())) - return true; - if ((Block.getId(world.getType(x, y, z + 1)) == id) && (world.getType(x, y + 1, z + 1).c())) - return true; - } - - if (Block.getId(world.getType(x - 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x - 1, y, z), (IInventory) chest); - if (Block.getId(world.getType(x + 1, y, z)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x + 1, y, z)); - if (Block.getId(world.getType(x, y, z - 1)) == id) - chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(x, y, z - 1), (IInventory) chest); - if (Block.getId(world.getType(x, y, z + 1)) == id) - chest = new InventoryLargeChest("Large chest", (IInventory) chest, (TileEntityChest) world.getTileEntity(x, y, z + 1)); - - boolean returnValue = true; - if (!silentchest) { - player.openContainer((IInventory) chest); - } - else { - try { - int windowId = 0; - try { - Field windowID = player.getClass().getDeclaredField("containerCounter"); - windowID.setAccessible(true); - windowId = windowID.getInt(player); - windowId = windowId % 100 + 1; - windowID.setInt(player, windowId); - } - catch (NoSuchFieldException e) {} - - player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, 0, ((IInventory) chest).getInventoryName(), ((IInventory) chest).getSize(), true)); - player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory) chest)); - player.activeContainer.windowId = windowId; - player.activeContainer.addSlotListener(player); - if (OpenInv.NotifySilentChest()) { - p.sendMessage("You are opening a chest silently."); - } - returnValue = false; - } - catch (Exception e) { - e.printStackTrace(); - p.sendMessage(ChatColor.RED + "Error while sending silent chest."); - } - } - - if (anychest && OpenInv.NotifyAnyChest()) { - p.sendMessage("You are opening a blocked chest."); - } - - return returnValue; - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R4/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_7_R4/SilentContainerChest.java deleted file mode 100644 index 0cbf298..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R4/SilentContainerChest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R4; - -//Volatile -import net.minecraft.server.v1_7_R4.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.closeContainer(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java deleted file mode 100644 index 8135307..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R4/SpecialEnderChest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R4; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_7_R4.*; -import org.bukkit.craftbukkit.v1_7_R4.entity.*; -import org.bukkit.craftbukkit.v1_7_R4.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getInventoryName(), ((CraftPlayer) p).getHandle().getEnderChest().k_(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} diff --git a/src/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java deleted file mode 100644 index b36388b..0000000 --- a/src/com/lishid/openinv/internal/v1_7_R4/SpecialPlayerInventory.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_7_R4; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialPlayerInventory; - -//Volatile -import net.minecraft.server.v1_7_R4.*; -import org.bukkit.craftbukkit.v1_7_R4.entity.*; -import org.bukkit.craftbukkit.v1_7_R4.inventory.*; - -public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { - CraftPlayer owner; - public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialPlayerInventory(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle()); - this.owner = ((CraftPlayer) p); - this.playerOnline = online; - this.items = player.inventory.items; - this.armor = player.inventory.armor; - OpenInv.inventories.put(owner.getName().toLowerCase(), this); - } - - @Override - public Inventory getBukkitInventory() { - return inventory; - } - - @Override - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.inventories.remove(owner.getName().toLowerCase()); - } - } - - @Override - public void PlayerGoOnline(Player player) { - if (!playerOnline) { - CraftPlayer p = (CraftPlayer) player; - p.getHandle().inventory.items = this.items; - p.getHandle().inventory.armor = this.armor; - p.saveData(); - playerOnline = true; - } - } - - @Override - public void PlayerGoOffline() { - playerOnline = false; - this.InventoryRemovalCheck(); - } - - @Override - public void onClose(CraftHumanEntity who) { - super.onClose(who); - this.InventoryRemovalCheck(); - } - - @Override - public ItemStack[] getContents() { - ItemStack[] C = new ItemStack[getSize()]; - System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); - return C; - } - - @Override - public int getSize() { - return super.getSize() + 5; - } - - @Override - public ItemStack getItem(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - return is[i]; - } - - @Override - public ItemStack splitStack(int i, int j) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - if (is[i] != null) { - ItemStack itemstack; - - if (is[i].count <= j) { - itemstack = is[i]; - is[i] = null; - return itemstack; - } - else { - itemstack = is[i].a(j); - if (is[i].count == 0) { - is[i] = null; - } - - return itemstack; - } - } - else { - return null; - } - } - - @Override - public ItemStack splitWithoutUpdate(int i) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - 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]; - - is[i] = null; - return itemstack; - } - else { - return null; - } - } - - @Override - public void setItem(int i, ItemStack itemstack) { - ItemStack[] is = this.items; - - if (i >= is.length) { - i -= is.length; - is = this.armor; - } - else { - i = getReversedItemSlotNum(i); - } - - if (i >= is.length) { - i -= is.length; - is = this.extra; - } - else if (is == this.armor) { - i = getReversedArmorSlotNum(i); - } - - // Effects - if (is == this.extra) { - owner.getHandle().drop(itemstack, true); - itemstack = null; - } - - is[i] = itemstack; - - owner.getHandle().defaultContainer.b(); - } - - private int getReversedItemSlotNum(int i) { - if (i >= 27) - return i - 27; - else - return 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; - } - - @Override - public String getInventoryName() { - if (player.getName().length() > 16) { - return player.getName().substring(0, 16); - } - return player.getName(); - } - - @Override - public boolean a(EntityHuman entityhuman) { - return true; - } -} \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java b/src/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java new file mode 100644 index 0000000..e7dae90 --- /dev/null +++ b/src/com/lishid/openinv/internal/v1_8_R2/AnySilentChest.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2011-2014 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 + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lishid.openinv.internal.v1_8_R2; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.IAnySilentChest; + +//Volatile +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; + +import net.minecraft.server.v1_8_R2.Block; +import net.minecraft.server.v1_8_R2.BlockPosition; +import net.minecraft.server.v1_8_R2.EntityPlayer; +import net.minecraft.server.v1_8_R2.IInventory; +import net.minecraft.server.v1_8_R2.ITileInventory; +import net.minecraft.server.v1_8_R2.InventoryLargeChest; +import net.minecraft.server.v1_8_R2.PacketPlayOutOpenWindow; +import net.minecraft.server.v1_8_R2.TileEntityChest; +import net.minecraft.server.v1_8_R2.World; + +public class AnySilentChest implements IAnySilentChest { + @Override + public boolean IsAnyChestNeeded(Player p, int x, int y, int z) { + // FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest + EntityPlayer player = ((CraftPlayer) p).getHandle(); + World world = player.world; + // If block on top + if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + // If block next to chest is chest and has a block on top + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + + return false; + } + + @Override + public boolean ActivateChest(Player p, boolean anychest, boolean silentchest, int x, int y, int z) { + EntityPlayer player = ((CraftPlayer) p).getHandle(); + World world = player.world; + Object chest = world.getTileEntity(new BlockPosition(x, y, z)); + if (chest == null) + return true; + + int id = Block.getId(world.getType(new BlockPosition(x, y, z)).getBlock()); + + if (!anychest) { + if (world.getType(new BlockPosition(x, y + 1, z)).getBlock().c()) + return true; + if ((Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x - 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) && (world.getType(new BlockPosition(x + 1, y + 1, z)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z - 1)).getBlock().c())) + return true; + if ((Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) && (world.getType(new BlockPosition(x, y + 1, z + 1)).getBlock().c())) + return true; + } + + if (Block.getId(world.getType(new BlockPosition(x - 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x - 1, y, z)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x + 1, y, z)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x + 1, y, z))); + if (Block.getId(world.getType(new BlockPosition(x, y, z - 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z - 1)), (ITileInventory) chest); + if (Block.getId(world.getType(new BlockPosition(x, y, z + 1)).getBlock()) == id) + chest = new InventoryLargeChest("Large chest", (ITileInventory) chest, (TileEntityChest) world.getTileEntity(new BlockPosition(x, y, z + 1))); + + boolean returnValue = true; + if (!silentchest) { + player.openContainer((IInventory) chest); + } + else { + try { + SilentContainerChest silentContainerChest = new SilentContainerChest(player.inventory, ((IInventory) chest), player); + int windowId = player.nextContainerCounter(); + player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(windowId, "minecraft:chest", ((IInventory) chest).getScoreboardDisplayName(), ((IInventory) chest).getSize())); + player.activeContainer = silentContainerChest; + player.activeContainer.windowId = windowId; + player.activeContainer.addSlotListener(player); + if (OpenInv.NotifySilentChest()) { + p.sendMessage("You are opening a chest silently."); + } + returnValue = false; + } + catch (Exception e) { + e.printStackTrace(); + p.sendMessage(ChatColor.RED + "Error while sending silent chest."); + } + } + + if (anychest && OpenInv.NotifyAnyChest()) { + p.sendMessage("You are opening a blocked chest."); + } + + return returnValue; + } +} diff --git a/src/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java b/src/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java similarity index 92% rename from src/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java rename to src/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java index 8a3977d..f09d77a 100644 --- a/src/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/InventoryAccess.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_7_R4; +package com.lishid.openinv.internal.v1_8_R2; import java.lang.reflect.Field; @@ -25,11 +25,13 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.Permissions; import com.lishid.openinv.internal.IInventoryAccess; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + //Volatile -import net.minecraft.server.v1_7_R4.*; -import org.bukkit.craftbukkit.v1_7_R4.inventory.*; +import net.minecraft.server.v1_8_R2.IInventory; public class InventoryAccess implements IInventoryAccess { + @Override public boolean check(Inventory inventory, HumanEntity player) { IInventory inv = grabInventory(inventory); diff --git a/src/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java b/src/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java similarity index 71% rename from src/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java rename to src/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java index 8cadf56..ebeece4 100644 --- a/src/com/lishid/openinv/internal/v1_7_R4/PlayerDataManager.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/PlayerDataManager.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_7_R4; +package com.lishid.openinv.internal.v1_8_R2; import java.io.File; import java.util.UUID; @@ -25,14 +25,17 @@ import org.bukkit.entity.Player; import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.IPlayerDataManager; -import net.minecraft.util.com.mojang.authlib.GameProfile; +import com.mojang.authlib.GameProfile; +import org.bukkit.craftbukkit.v1_8_R2.CraftServer; + +import net.minecraft.server.v1_8_R2.EntityPlayer; //Volatile -import net.minecraft.server.v1_7_R4.*; - -import org.bukkit.craftbukkit.v1_7_R4.*; +import net.minecraft.server.v1_8_R2.MinecraftServer; +import net.minecraft.server.v1_8_R2.PlayerInteractManager; public class PlayerDataManager implements IPlayerDataManager { + @Override public Player loadPlayer(String name) { try { UUID uuid = matchUser(name); @@ -101,4 +104,29 @@ public class PlayerDataManager implements IPlayerDataManager { return found; } + + /* (non-Javadoc) + * @see com.lishid.openinv.internal.IPlayerDataManager#loadPlayer(java.util.UUID) + */ + @Override + public Player loadPlayer(UUID uuid) { + 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 + EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0))); + + // Get the bukkit entity + Player target = (entity == null) ? null : entity.getBukkitEntity(); + if (target != null) { + // Load data + target.loadData(); + // Return the entity + return target; + } + return null; + } } diff --git a/src/com/lishid/openinv/internal/v1_4_6/SilentContainerChest.java b/src/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java similarity index 73% rename from src/com/lishid/openinv/internal/v1_4_6/SilentContainerChest.java rename to src/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java index e245206..f2b0276 100644 --- a/src/com/lishid/openinv/internal/v1_4_6/SilentContainerChest.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/SilentContainerChest.java @@ -1,36 +1,38 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_6; - -//Volatile -import net.minecraft.server.v1_4_6.*; - -public class SilentContainerChest extends ContainerChest { - public IInventory inv; - - public SilentContainerChest(IInventory i1, IInventory i2) { - super(i1, i2); - inv = i2; - // close signal - inv.f(); - } - - @Override - public void b(EntityHuman paramEntityHuman) { - // Don't send close signal twice, might screw up - } +/* + * Copyright (C) 2011-2014 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 + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lishid.openinv.internal.v1_8_R2; + +//Volatile +import net.minecraft.server.v1_8_R2.ContainerChest; +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.IInventory; + +public class SilentContainerChest extends ContainerChest { + public IInventory inv; + + public SilentContainerChest(IInventory i1, IInventory i2, EntityHuman e1) { + super(i1, i2, e1); + inv = i2; + // close signal + inv.closeContainer(e1); + } + + @Override + public void b(EntityHuman paramEntityHuman) { + // Don't send close signal twice, might screw up + } } \ No newline at end of file diff --git a/src/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java b/src/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java similarity index 77% rename from src/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java rename to src/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java index 81637bb..bcf6895 100644 --- a/src/com/lishid/openinv/internal/v1_4_5/SpecialEnderChest.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/SpecialEnderChest.java @@ -1,126 +1,145 @@ -/* - * Copyright (C) 2011-2014 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 - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lishid.openinv.internal.v1_4_5; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import com.lishid.openinv.OpenInv; -import com.lishid.openinv.internal.ISpecialEnderChest; - -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; - -//Volatile -import net.minecraft.server.v1_4_5.*; -import org.bukkit.craftbukkit.v1_4_5.entity.*; -import org.bukkit.craftbukkit.v1_4_5.inventory.*; - -public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { - public List transaction = new ArrayList(); - public boolean playerOnline = false; - private CraftPlayer owner; - private InventoryEnderChest enderChest; - private int maxStack = MAX_STACK; - private CraftInventory inventory = new CraftInventory(this); - - public SpecialEnderChest(Player p, Boolean online) { - super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); - CraftPlayer player = (CraftPlayer) p; - this.enderChest = player.getHandle().getEnderChest(); - this.owner = player; - this.items = enderChest.getContents(); - OpenInv.enderChests.put(owner.getName().toLowerCase(), this); - } - - public Inventory getBukkitInventory() { - return inventory; - } - - public void InventoryRemovalCheck() { - owner.saveData(); - if (transaction.isEmpty() && !playerOnline) { - OpenInv.enderChests.remove(owner.getName().toLowerCase()); - } - } - - public void PlayerGoOnline(Player p) { - if (!playerOnline) { - try { - InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); - Field field = playerEnderChest.getClass().getField("items"); - field.setAccessible(true); - field.set(playerEnderChest, this.items); - } - catch (Exception e) {} - p.saveData(); - playerOnline = true; - } - } - - public void PlayerGoOffline() { - playerOnline = false; - } - - public ItemStack[] getContents() { - return this.items; - } - - public void onOpen(CraftHumanEntity who) { - transaction.add(who); - } - - public void onClose(CraftHumanEntity who) { - transaction.remove(who); - this.InventoryRemovalCheck(); - } - - public List getViewers() { - return transaction; - } - - public InventoryHolder getOwner() { - return this.owner; - } - - public void setMaxStackSize(int size) { - maxStack = size; - } - - public int getMaxStackSize() { - return maxStack; - } - - public boolean a(EntityHuman entityhuman) { - return true; - } - - public void startOpen() { - - } - - public void f() { - - } - - public void update() { - enderChest.update(); - } -} +/* + * Copyright (C) 2011-2014 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 + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lishid.openinv.internal.v1_8_R2; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; + +import com.lishid.openinv.OpenInv; +import com.lishid.openinv.internal.ISpecialEnderChest; + +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + +//Volatile +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.IInventory; +import net.minecraft.server.v1_8_R2.InventoryEnderChest; +import net.minecraft.server.v1_8_R2.InventorySubcontainer; +import net.minecraft.server.v1_8_R2.ItemStack; + +public class SpecialEnderChest extends InventorySubcontainer implements IInventory, ISpecialEnderChest { + public List transaction = new ArrayList(); + public boolean playerOnline = false; + private final CraftPlayer owner; + private final InventoryEnderChest enderChest; + private int maxStack = MAX_STACK; + private final CraftInventory inventory = new CraftInventory(this); + + public SpecialEnderChest(Player p, Boolean online) { + super(((CraftPlayer) p).getHandle().getEnderChest().getName(), ((CraftPlayer) p).getHandle().getEnderChest().hasCustomName(), ((CraftPlayer) p).getHandle().getEnderChest().getSize()); + CraftPlayer player = (CraftPlayer) p; + this.enderChest = player.getHandle().getEnderChest(); + this.owner = player; + this.items = enderChest.getContents(); + OpenInv.enderChests.put(owner.getName().toLowerCase(), this); + } + + @Override + public Inventory getBukkitInventory() { + return inventory; + } + + @Override + public void InventoryRemovalCheck() { + owner.saveData(); + if (transaction.isEmpty() && !playerOnline) { + OpenInv.enderChests.remove(owner.getName().toLowerCase()); + } + } + + @Override + public void PlayerGoOnline(Player p) { + if (!playerOnline) { + try { + InventoryEnderChest playerEnderChest = ((CraftPlayer) p).getHandle().getEnderChest(); + Field field = playerEnderChest.getClass().getField("items"); + field.setAccessible(true); + field.set(playerEnderChest, this.items); + } + catch (Exception e) {} + p.saveData(); + playerOnline = true; + } + } + + @Override + public void PlayerGoOffline() { + playerOnline = false; + } + + @Override + public ItemStack[] getContents() { + return this.items; + } + + @Override + public void onOpen(CraftHumanEntity who) { + transaction.add(who); + } + + @Override + public void onClose(CraftHumanEntity who) { + transaction.remove(who); + this.InventoryRemovalCheck(); + } + + @Override + public List getViewers() { + return transaction; + } + + @Override + public InventoryHolder getOwner() { + return this.owner; + } + + @Override + public void setMaxStackSize(int size) { + maxStack = size; + } + + @Override + public int getMaxStackSize() { + return maxStack; + } + + @Override + public boolean a(EntityHuman entityhuman) { + return true; + } + + public void startOpen() { + + } + + public void f() { + + } + + @Override + public void update() { + enderChest.update(); + } +} diff --git a/src/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java b/src/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java similarity index 90% rename from src/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java rename to src/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java index 98a8cf1..38fa2ca 100644 --- a/src/com/lishid/openinv/internal/v1_7_R3/SpecialPlayerInventory.java +++ b/src/com/lishid/openinv/internal/v1_8_R2/SpecialPlayerInventory.java @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -package com.lishid.openinv.internal.v1_7_R3; +package com.lishid.openinv.internal.v1_8_R2; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -23,15 +23,19 @@ import com.lishid.openinv.OpenInv; import com.lishid.openinv.internal.ISpecialPlayerInventory; //Volatile -import net.minecraft.server.v1_7_R3.*; -import org.bukkit.craftbukkit.v1_7_R3.entity.*; -import org.bukkit.craftbukkit.v1_7_R3.inventory.*; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventory; + +import net.minecraft.server.v1_8_R2.EntityHuman; +import net.minecraft.server.v1_8_R2.ItemStack; +import net.minecraft.server.v1_8_R2.PlayerInventory; public class SpecialPlayerInventory extends PlayerInventory implements ISpecialPlayerInventory { CraftPlayer owner; public boolean playerOnline = false; - private ItemStack[] extra = new ItemStack[5]; - private CraftInventory inventory = new CraftInventory(this); + private final ItemStack[] extra = new ItemStack[5]; + private final CraftInventory inventory = new CraftInventory(this); public SpecialPlayerInventory(Player p, Boolean online) { super(((CraftPlayer) p).getHandle()); @@ -82,7 +86,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP public ItemStack[] getContents() { ItemStack[] C = new ItemStack[getSize()]; System.arraycopy(items, 0, C, 0, items.length); - System.arraycopy(items, 0, C, items.length, armor.length); + System.arraycopy(armor, 0, C, items.length, armor.length); return C; } @@ -239,7 +243,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP } @Override - public String getInventoryName() { + public String getName() { if (player.getName().length() > 16) { return player.getName().substring(0, 16); } diff --git a/src/plugin.yml b/src/plugin.yml index bf8edfc..24d8479 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: OpenInv main: com.lishid.openinv.OpenInv -version: 2.2.4 +version: 2.2.7 author: lishid description: > This plugin allows you to open a player's inventory as a chest and interact with it in real time.