LATEST VERSION 1.6.6

This commit is contained in:
lishd 2012-01-12 14:23:53 -05:00
parent 7d4d830c77
commit 7d06601fe9
8 changed files with 406 additions and 295 deletions

View file

@ -2,12 +2,9 @@
package lishid.openinv; package lishid.openinv;
import lishid.openinv.commands.*; import lishid.openinv.commands.*;
import lishid.openinv.utils.PlayerInventoryChest;
import net.minecraft.server.ContainerPlayer; import org.bukkit.ChatColor;
import net.minecraft.server.EntityPlayer; import org.bukkit.entity.Player;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -60,31 +57,9 @@ public class OpenInv extends JavaPlugin {
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this)); getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this)); getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this));
getCommand("toggleopeninv").setExecutor(new OpenInvPluginCommand(this)); getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this)); getCommand("silentchest").setExecutor(new SilentChestPluginCommand(this));
} getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
public static void ReplaceInv(CraftPlayer player)
{
try{
EntityPlayer entityplayer = player.getHandle();
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory, entityplayer);
entityplayer.defaultContainer = new ContainerPlayer(entityplayer.inventory, !entityplayer.world.isStatic);
//sync
try
{
entityplayer.syncInventory();
}catch(Exception e){}
entityplayer.a(entityplayer.activeContainer, entityplayer.activeContainer.b());
entityplayer.activeContainer.a();
entityplayer.defaultContainer.a();
player.setHandle(entityplayer);
}
catch(Exception e)
{
System.out.println("[OpenInv] Error while trying to override player inventory, error: " + e.getMessage());
}
} }
public static boolean GetPlayerItemOpenInvStatus(String name) public static boolean GetPlayerItemOpenInvStatus(String name)
@ -109,6 +84,17 @@ public class OpenInv extends JavaPlugin {
mainPlugin.saveConfig(); mainPlugin.saveConfig();
} }
public static boolean GetPlayerAnyChestStatus(String name)
{
return mainPlugin.getConfig().getBoolean("AnyChest." + name.toLowerCase() + ".toggle", true);
}
public static void SetPlayerAnyChestStatus(String name, boolean status)
{
mainPlugin.getConfig().set("AnyChest." + name.toLowerCase() + ".toggle", status);
mainPlugin.saveConfig();
}
public static int GetItemOpenInvItem() public static int GetItemOpenInvItem()
{ {
if(mainPlugin.getConfig().get("ItemOpenInvItemID") == null) if(mainPlugin.getConfig().get("ItemOpenInvItemID") == null)
@ -137,4 +123,19 @@ public class OpenInv extends JavaPlugin {
mainPlugin.getConfig().set(data, value); mainPlugin.getConfig().set(data, value);
mainPlugin.saveConfig(); mainPlugin.saveConfig();
} }
public static void ShowHelp(Player player)
{
player.sendMessage(ChatColor.GREEN + "/openinv <Player> - Open a player's inventory");
player.sendMessage(ChatColor.GREEN + " (aliases: oi, inv, open)");
player.sendMessage(ChatColor.GREEN + "/toggleopeninv - Toggle item openinv function");
player.sendMessage(ChatColor.GREEN + " (aliases: toi, toggleoi, toggleinv)");
player.sendMessage(ChatColor.GREEN + "/searchinv <Item> [MinAmount] - ");
player.sendMessage(ChatColor.GREEN + " Search and list players having a specific item.");
player.sendMessage(ChatColor.GREEN + " (aliases: si, search)");
player.sendMessage(ChatColor.GREEN + "/anychest - Toggle anychest function");
player.sendMessage(ChatColor.GREEN + " (aliases: ac)");
player.sendMessage(ChatColor.GREEN + "/silentchest - Toggle silent chest function");
player.sendMessage(ChatColor.GREEN + " (aliases: sc, silent)");
}
} }

View file

@ -3,7 +3,6 @@ package lishid.openinv;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import lishid.openinv.commands.OpenInvPluginCommand; import lishid.openinv.commands.OpenInvPluginCommand;
import lishid.openinv.utils.PlayerInventoryChest;
import lishid.openinv.utils.SilentContainerChest; import lishid.openinv.utils.SilentContainerChest;
import net.minecraft.server.Block; import net.minecraft.server.Block;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
@ -16,7 +15,6 @@ import net.minecraft.server.TileEntityChest;
import net.minecraft.server.World; import net.minecraft.server.World;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
@ -37,20 +35,15 @@ public class OpenInvPlayerListener extends PlayerListener{
public void onPlayerLogin(PlayerLoginEvent event) public void onPlayerLogin(PlayerLoginEvent event)
{ {
try{ try{
for(Player target : OpenInvPluginCommand.offlineInv.values()) for(Player target : OpenInvPluginCommand.offlineInv.keySet())
{ {
if(target.getName().equalsIgnoreCase(event.getPlayer().getName())) if(target.getName().equalsIgnoreCase(event.getPlayer().getName()))
{ {
System.out.print("[OpenInv] PlayerLogin event triggered closing openinv."); ((CraftPlayer)OpenInvPluginCommand.offlineInv.get(target).Opener).getHandle().netServerHandler.sendPacket(new Packet101CloseWindow());
EntityPlayer player = ((CraftPlayer)target).getHandle();
if(player.inventory instanceof PlayerInventoryChest)
{
((CraftPlayer)((PlayerInventoryChest)player.inventory).Opener).getHandle().netServerHandler.sendPacket(new Packet101CloseWindow());
}
target.saveData(); target.saveData();
OpenInvPluginCommand.offlineInv.remove(player.inventory); OpenInvPluginCommand.offlineInv.remove(target);
event.getPlayer().loadData(); event.getPlayer().loadData();
break; return;
} }
} }
} }
@ -60,29 +53,27 @@ public class OpenInvPlayerListener extends PlayerListener{
@Override @Override
public void onPlayerInteract(PlayerInteractEvent event) public void onPlayerInteract(PlayerInteractEvent event)
{ {
if(event.useInteractedBlock() == Result.DENY || event.isCancelled()) if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY)
return; return;
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest)
{
boolean silentchest = false; boolean silentchest = false;
boolean anychest = false; boolean anychest = false;
int x = event.getClickedBlock().getX(); int x = event.getClickedBlock().getX();
int y = event.getClickedBlock().getY(); int y = event.getClickedBlock().getY();
int z = event.getClickedBlock().getZ(); int z = event.getClickedBlock().getZ();
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && if(PermissionRelay.hasPermission(event.getPlayer(), "silent") && OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName()))
event.getClickedBlock().getState() instanceof Chest &&
PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.silent") &&
OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName()))
{ {
silentchest = true; silentchest = true;
} }
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && if(PermissionRelay.hasPermission(event.getPlayer(), "anychest") && OpenInv.GetPlayerAnyChestStatus(event.getPlayer().getName()))
event.getClickedBlock().getState() instanceof Chest &&
PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.anychest"))
{ {
try try
{ {
//FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle(); EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
World world = player.world; World world = player.world;
//If block on top //If block on top
@ -99,15 +90,14 @@ public class OpenInvPlayerListener extends PlayerListener{
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1))) if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1)))
anychest = true; anychest = true;
} }
catch(Exception e) //Incompatible CraftBukkit? catch(Exception e)
{ {
e.printStackTrace();
event.getPlayer().sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit."); event.getPlayer().sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
e.printStackTrace();
} }
} }
//If the anychest or silentchest is active
//If the chest is blocked
if(anychest || silentchest) if(anychest || silentchest)
{ {
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle(); EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
@ -143,10 +133,11 @@ public class OpenInvPlayerListener extends PlayerListener{
ciField.setInt(player, ci); ciField.setInt(player, ci);
player.netServerHandler.sendPacket(new Packet100OpenWindow(ci, 0, ((IInventory)chest).getName(), ((IInventory)chest).getSize())); player.netServerHandler.sendPacket(new Packet100OpenWindow(ci, 0, ((IInventory)chest).getName(), ((IInventory)chest).getSize()));
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory)chest)); player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory)chest));
System.out.println(player.activeContainer.toString());
player.activeContainer.windowId = ci; player.activeContainer.windowId = ci;
player.activeContainer.a((ICrafting)player); player.activeContainer.a((ICrafting)player);
event.getPlayer().sendMessage("You are opening a silent chest."); event.getPlayer().sendMessage("You are opening a chest silently.");
event.setUseInteractedBlock(Result.DENY);
event.setCancelled(true);
} }
catch(Exception e) catch(Exception e)
{ {
@ -158,46 +149,17 @@ public class OpenInvPlayerListener extends PlayerListener{
if(anychest) if(anychest)
event.getPlayer().sendMessage("You are opening a blocked chest."); event.getPlayer().sendMessage("You are opening a blocked chest.");
} }
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
(event.getClickedBlock() == Block.CHEST ||
event.getClickedBlock() == Block.FURNACE ||
event.getClickedBlock() == Block.DISPENSER))
{
return;
} }
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Sign)
{
Player player = event.getPlayer();
if(!(player.getItemInHand().getType() == Material.STICK)
|| (!OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
|| !PermissionRelay.hasPermission(player, "openinv"))
{
return;
}
player.performCommand("openinv");
}
if(event.getAction() == Action.LEFT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Sign)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
try{ try{
if (PermissionRelay.hasPermission(player, "openinv") &&
((Sign)event.getClickedBlock().getState()).getLine(0).equalsIgnoreCase("[openinv]"))
{
if(plugin.getServer().getPlayer(((Sign)event.getClickedBlock().getState()).getLine(1)) != null)
{
Sign sign = ((Sign)event.getClickedBlock().getState()); Sign sign = ((Sign)event.getClickedBlock().getState());
String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(2).trim(); if (PermissionRelay.hasPermission(player, "openinv") && sign.getLine(0).equalsIgnoreCase("[openinv]"))
player.performCommand("openinv " + text);
}
else
{ {
player.sendMessage("Player not found."); String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(3).trim();
} player.performCommand("openinv " + text);
} }
} }
catch(Exception ex) catch(Exception ex)
@ -206,5 +168,19 @@ public class OpenInvPlayerListener extends PlayerListener{
ex.printStackTrace(); ex.printStackTrace();
} }
} }
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
{
Player player = event.getPlayer();
if(!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem())
|| (!OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
|| !PermissionRelay.hasPermission(player, "openinv"))
{
return;
}
player.performCommand("openinv");
}
} }
} }

View file

@ -5,6 +5,13 @@ import org.bukkit.entity.Player;
public class PermissionRelay { public class PermissionRelay {
public static boolean hasPermission(Player player, String permission) public static boolean hasPermission(Player player, String permission)
{
if(hasPermission2(player, "*") || hasPermission2(player, "OpenInv.*"))
return true;
return hasPermission2(player, "OpenInv." + permission);
}
public static boolean hasPermission2(Player player, String permission)
{ {
if (OpenInv.permissionHandler == null) { if (OpenInv.permissionHandler == null) {
return player.isOp() ? true : player.hasPermission(permission); return player.isOp() ? true : player.hasPermission(permission);

View file

@ -5,14 +5,12 @@ import java.util.HashMap;
import lishid.openinv.PermissionRelay; import lishid.openinv.PermissionRelay;
import lishid.openinv.OpenInv; import lishid.openinv.OpenInv;
import lishid.openinv.utils.PlayerInventoryChest; import lishid.openinv.utils.PlayerInventoryChest;
import lishid.openinv.utils.OpenInvHistory;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.ItemInWorldManager;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -22,54 +20,34 @@ import org.bukkit.entity.Player;
public class OpenInvPluginCommand implements CommandExecutor { public class OpenInvPluginCommand implements CommandExecutor {
private final OpenInv plugin; private final OpenInv plugin;
public static HashMap<PlayerInventoryChest, Player> offlineInv = new HashMap<PlayerInventoryChest, Player>(); public static HashMap<Player, PlayerInventoryChest> offlineInv = new HashMap<Player, PlayerInventoryChest>();
public static HashMap<Player, OpenInvHistory> theOpenInvHistory = new HashMap<Player, OpenInvHistory>(); public static HashMap<Player, String> openInvHistory = new HashMap<Player, String>();
public OpenInvPluginCommand(OpenInv plugin) { public OpenInvPluginCommand(OpenInv plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!PermissionRelay.hasPermission((Player) sender, "OpenInv.openinv")) { if (!PermissionRelay.hasPermission((Player)sender, "openinv")) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories"); sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true; return true;
} }
boolean Offline = false; if(args.length > 0 && args[0].equalsIgnoreCase("?"))
{
OpenInv.ShowHelp((Player)sender);
return true;
}
Player player = (Player)sender; Player player = (Player)sender;
boolean Offline = false;
//History management //History management
OpenInvHistory history = theOpenInvHistory.get(player); String history = openInvHistory.get(player);
if(history == null) if(history == null || history == "")
{ {
history = new OpenInvHistory(player); history = player.getName();
theOpenInvHistory.put(player, history); openInvHistory.put(player, history);
}
//Toggleopeninv command
if(command.getName().equalsIgnoreCase("toggleopeninv"))
{
if(args.length > 0)
{
if(args[0].equalsIgnoreCase("check"))
{
if(OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
else
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
}
if(OpenInv.GetPlayerItemOpenInvStatus(player.getName()))
{
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), false);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is OFF.");
}
else
{
OpenInv.SetPlayerItemOpenInvStatus(player.getName(), true);
player.sendMessage("OpenInv with " + Material.getMaterial(OpenInv.GetItemOpenInvItem()).toString() + " is ON.");
}
return true;
} }
//Target selecting //Target selecting
@ -77,10 +55,11 @@ public class OpenInvPluginCommand implements CommandExecutor {
String name = ""; String name = "";
//Read from history if target is not named
if (args.length < 1) { if (args.length < 1) {
if(history.lastPlayer != null) if(history != null && history != "")
{ {
name = history.lastPlayer; name = history;
} }
else else
{ {
@ -95,16 +74,17 @@ public class OpenInvPluginCommand implements CommandExecutor {
target = this.plugin.getServer().getPlayer(name); target = this.plugin.getServer().getPlayer(name);
if(target == null) if(target == null)
{ {
//Offline inv here... //Offline inv here...
try{ try{
//See if the player has data files
if(!this.plugin.getServer().getOfflinePlayer(name).hasPlayedBefore()) if(!this.plugin.getServer().getOfflinePlayer(name).hasPlayedBefore())
{ {
sender.sendMessage(ChatColor.RED + "Player not found!"); sender.sendMessage(ChatColor.RED + "Player not found!");
return true; return true;
} }
//Create an entity to load the player data
MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer(); MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer();
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), name, new ItemInWorldManager(server.getWorldServer(0))); EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), name, new ItemInWorldManager(server.getWorldServer(0)));
target = (entity == null) ? null : (Player) entity.getBukkitEntity(); target = (entity == null) ? null : (Player) entity.getBukkitEntity();
@ -112,8 +92,6 @@ public class OpenInvPluginCommand implements CommandExecutor {
{ {
Offline = true; Offline = true;
target.loadData(); target.loadData();
EntityPlayer entityplayer = ((CraftPlayer)target).getHandle();
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory, entityplayer);
} }
else else
{ {
@ -125,57 +103,48 @@ public class OpenInvPluginCommand implements CommandExecutor {
{ {
sender.sendMessage("Error while retrieving offline player data!"); sender.sendMessage("Error while retrieving offline player data!");
e.printStackTrace(); e.printStackTrace();
//sender.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found!");
return true; return true;
} }
} }
//Check if target is the player him/her self
if(target == player)
{
sender.sendMessage(ChatColor.RED + "Cannot OpenInv yourself!");
return true;
}
//Permissions checks //Permissions checks
if (!PermissionRelay.hasPermission(player, "OpenInv.override") && PermissionRelay.hasPermission(target, "OpenInv.exempt")) { if (!PermissionRelay.hasPermission(player, "override") && PermissionRelay.hasPermission(target, "exempt")) {
sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!"); sender.sendMessage(ChatColor.RED + target.getDisplayName() + "'s inventory is protected!");
return true; return true;
} }
if((!PermissionRelay.hasPermission(player, "OpenInv.crossworld") && !PermissionRelay.hasPermission(player, "OpenInv.override")) && if((!PermissionRelay.hasPermission(player, "crossworld") && !PermissionRelay.hasPermission(player, "override")) &&
target.getWorld() != player.getWorld()){ target.getWorld() != player.getWorld()){
sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!"); sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
return true; return true;
} }
//The actual openinv //Record the target
history.lastPlayer = target.getName(); history = target.getName();
openInvHistory.put(player, history);
// Get the EntityPlayer handle from the sender //Get the EntityPlayer handle from the sender
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle(); EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
// Get the EntityPlayer from the Target //Get the EntityPlayer from the Target
EntityPlayer entitytarget = ((CraftPlayer) target).getHandle(); EntityPlayer entitytarget = ((CraftPlayer) target).getHandle();
if(!(entitytarget.inventory instanceof PlayerInventoryChest)) //Create the inventory
{ PlayerInventoryChest inv = new PlayerInventoryChest(entitytarget.inventory, entitytarget);
OpenInv.ReplaceInv((CraftPlayer) target);
}
if(entitytarget.inventory instanceof PlayerInventoryChest) //Save data into the inventory for tracking
{ inv.Opener = player;
((PlayerInventoryChest)entitytarget.inventory).Opener = player; inv.Target = target;
((PlayerInventoryChest)entitytarget.inventory).Target = target;
//Saves offline openinv
if(Offline) if(Offline)
{ {
((PlayerInventoryChest)entitytarget.inventory).Offline = true; inv.Offline = true;
offlineInv.put((PlayerInventoryChest) entitytarget.inventory, target); offlineInv.put(target, inv);
}
} }
entityplayer.a(entitytarget.inventory); //Open the inventory
entityplayer.a(inv);
return true; return true;
} }

View file

@ -17,7 +17,7 @@ public class SearchInvPluginCommand implements CommandExecutor {
} }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!PermissionRelay.hasPermission((Player) sender, "OpenInv.search")) { if (!PermissionRelay.hasPermission((Player) sender, "search")) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories"); sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true; return true;
} }

View file

@ -1,14 +0,0 @@
package lishid.openinv.utils;
import org.bukkit.entity.Player;
public class OpenInvHistory {
public Player player = null;
public String lastPlayer = "";
public OpenInvHistory(Player player)
{
this.player = player;
}
}

View file

@ -5,46 +5,207 @@ import org.bukkit.entity.Player;
import lishid.openinv.commands.OpenInvPluginCommand; import lishid.openinv.commands.OpenInvPluginCommand;
import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityHuman;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.IInventory;
import net.minecraft.server.ItemStack;
import net.minecraft.server.PlayerInventory; import net.minecraft.server.PlayerInventory;
public class PlayerInventoryChest extends PlayerInventory public class PlayerInventoryChest implements IInventory
{ {
public boolean Offline = false; public boolean Offline = false;
public Player Opener; public Player Opener;
EntityPlayer player;
public Player Target; public Player Target;
public PlayerInventoryChest(PlayerInventory inventory, EntityPlayer entityplayer) { private ItemStack[] items = new ItemStack[36];
super(entityplayer); private ItemStack[] armor = new ItemStack[4];
this.armor = inventory.armor; private ItemStack[] extra = new ItemStack[5];
public PlayerInventoryChest(PlayerInventory inventory, EntityPlayer entityplayer)
{
player = entityplayer;
this.items = inventory.items; this.items = inventory.items;
this.itemInHandIndex = inventory.itemInHandIndex; this.armor = inventory.armor;
this.e = inventory.e;
this.b(inventory.l());
} }
@Override public ItemStack[] getContents()
public String getName() { {
if(this.d.name.length() > 16) ItemStack[] C = new ItemStack[getSize()];
return this.d.name.substring(0, 16); System.arraycopy(items, 0, C, 0, items.length);
System.arraycopy(items, 0, C, items.length, armor.length);
return C;
}
public int getSize()
{
return 45;
}
public ItemStack getItem(int i)
{
ItemStack[] is = this.items;
if (i >= is.length)
{
i -= is.length;
is = this.armor;
}
else else
return this.d.name; {
i = getReversedItemSlotNum(i);
}
if (i >= is.length)
{
i -= is.length;
is = this.extra;
}
else if(is == this.armor)
{
i = getReversedArmorSlotNum(i);
}
return is[i];
}
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;
}
}
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)
{
if(i == 0)
{
itemstack.setData(0);
}
}
is[i] = itemstack;
}
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;
}
public String getName()
{
if (player.name.length() > 16) return player.name.substring(0, 16);
return player.name;
}
public int getMaxStackSize()
{
return 64;
} }
@Override
public boolean a(EntityHuman entityhuman) public boolean a(EntityHuman entityhuman)
{ {
return true; return true;
} }
@Override public void f()
public void g() {
try{
Player player = OpenInvPluginCommand.offlineInv.get(this);
if(player != null)
{ {
player.saveData();
OpenInvPluginCommand.offlineInv.remove(this);
} }
}catch(Exception e){}
public void g()
{
try
{
PlayerInventoryChest inv = OpenInvPluginCommand.offlineInv.get(this.Target);
if (inv != null)
{
this.Target.saveData();
OpenInvPluginCommand.offlineInv.remove(this.Target);
}
}
catch (Exception e)
{}
}
public void update()
{
} }
} }

View file

@ -1,23 +1,34 @@
name: OpenInv name: OpenInv
main: lishid.openinv.OpenInv main: lishid.openinv.OpenInv
version: 1.6.2 version: 1.6.6
author: lishid author: lishid
website: http://forums.bukkit.org/threads/15379/
description: > description: >
This plugin allows you to open another player's inventory as a chest This plugin allows you to open a player's inventory as a chest and interact with it in real time.
commands: commands:
openinv: openinv:
aliases: [oi, inv, open]
description: Open a player's inventory description: Open a player's inventory
usage: | usage: |
/<command> <Player> /<command> - Open last person's inventory
/<command> <Player> - Open a player's inventory
searchinv: searchinv:
aliases: [si, search]
description: Search and list players having a specific item description: Search and list players having a specific item
usage: | usage: |
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered. /<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
toggleopeninv: toggleopeninv:
description: Toggle the stick openinv aliases: [toi, toggleoi, toggleinv]
description: Toggle item openinv function
usage: | usage: |
/<command> [check] - Checks whether stick openinv is enabled /<command> [Check] - Checks whether item openinv is enabled
silentchest: silentchest:
description: Toggle silent chest, which does not animate a chest when opened or closed, and suppresses the sound. aliases: [sc, silent]
description: Toggle silent chest function, which hides the animation of a chest when opened or closed, and suppresses the sound.
usage: | usage: |
/<command> [check] - Checks whether silent chest is enabled /<command> [Check] - Checks whether silent chest is enabled
anychest:
aliases: [ac]
description: Toggle anychest function, which allows opening of blocked chests.
usage: |
/<command> [Check] - Checks whether anychest is enabled