mirror of
https://github.com/TotalFreedomMC/OpenInv.git
synced 2024-12-23 00:15:08 +00:00
LATEST VERSION 1.6.6
This commit is contained in:
parent
7d4d830c77
commit
7d06601fe9
8 changed files with 406 additions and 295 deletions
|
@ -2,12 +2,9 @@
|
|||
package lishid.openinv;
|
||||
|
||||
import lishid.openinv.commands.*;
|
||||
import lishid.openinv.utils.PlayerInventoryChest;
|
||||
|
||||
import net.minecraft.server.ContainerPlayer;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
@ -60,31 +57,9 @@ public class OpenInv extends JavaPlugin {
|
|||
|
||||
getCommand("openinv").setExecutor(new OpenInvPluginCommand(this));
|
||||
getCommand("searchinv").setExecutor(new SearchInvPluginCommand(this));
|
||||
getCommand("toggleopeninv").setExecutor(new OpenInvPluginCommand(this));
|
||||
getCommand("toggleopeninv").setExecutor(new ToggleOpenInvPluginCommand());
|
||||
getCommand("silentchest").setExecutor(new SilentChestPluginCommand(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());
|
||||
}
|
||||
getCommand("anychest").setExecutor(new AnyChestPluginCommand(this));
|
||||
}
|
||||
|
||||
public static boolean GetPlayerItemOpenInvStatus(String name)
|
||||
|
@ -109,6 +84,17 @@ public class OpenInv extends JavaPlugin {
|
|||
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()
|
||||
{
|
||||
if(mainPlugin.getConfig().get("ItemOpenInvItemID") == null)
|
||||
|
@ -137,4 +123,19 @@ public class OpenInv extends JavaPlugin {
|
|||
mainPlugin.getConfig().set(data, value);
|
||||
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)");
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package lishid.openinv;
|
|||
import java.lang.reflect.Field;
|
||||
|
||||
import lishid.openinv.commands.OpenInvPluginCommand;
|
||||
import lishid.openinv.utils.PlayerInventoryChest;
|
||||
import lishid.openinv.utils.SilentContainerChest;
|
||||
import net.minecraft.server.Block;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
|
@ -16,7 +15,6 @@ import net.minecraft.server.TileEntityChest;
|
|||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
|
@ -37,20 +35,15 @@ public class OpenInvPlayerListener extends PlayerListener{
|
|||
public void onPlayerLogin(PlayerLoginEvent event)
|
||||
{
|
||||
try{
|
||||
for(Player target : OpenInvPluginCommand.offlineInv.values())
|
||||
for(Player target : OpenInvPluginCommand.offlineInv.keySet())
|
||||
{
|
||||
if(target.getName().equalsIgnoreCase(event.getPlayer().getName()))
|
||||
{
|
||||
System.out.print("[OpenInv] PlayerLogin event triggered closing openinv.");
|
||||
EntityPlayer player = ((CraftPlayer)target).getHandle();
|
||||
if(player.inventory instanceof PlayerInventoryChest)
|
||||
{
|
||||
((CraftPlayer)((PlayerInventoryChest)player.inventory).Opener).getHandle().netServerHandler.sendPacket(new Packet101CloseWindow());
|
||||
}
|
||||
((CraftPlayer)OpenInvPluginCommand.offlineInv.get(target).Opener).getHandle().netServerHandler.sendPacket(new Packet101CloseWindow());
|
||||
target.saveData();
|
||||
OpenInvPluginCommand.offlineInv.remove(player.inventory);
|
||||
OpenInvPluginCommand.offlineInv.remove(target);
|
||||
event.getPlayer().loadData();
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,144 +53,113 @@ public class OpenInvPlayerListener extends PlayerListener{
|
|||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if(event.useInteractedBlock() == Result.DENY || event.isCancelled())
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Result.DENY)
|
||||
return;
|
||||
|
||||
boolean silentchest = false;
|
||||
boolean anychest = false;
|
||||
int x = event.getClickedBlock().getX();
|
||||
int y = event.getClickedBlock().getY();
|
||||
int z = event.getClickedBlock().getZ();
|
||||
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||
event.getClickedBlock().getState() instanceof Chest &&
|
||||
PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.silent") &&
|
||||
OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName()))
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Chest)
|
||||
{
|
||||
silentchest = true;
|
||||
}
|
||||
boolean silentchest = false;
|
||||
boolean anychest = false;
|
||||
int x = event.getClickedBlock().getX();
|
||||
int y = event.getClickedBlock().getY();
|
||||
int z = event.getClickedBlock().getZ();
|
||||
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
||||
event.getClickedBlock().getState() instanceof Chest &&
|
||||
PermissionRelay.hasPermission(event.getPlayer(), "OpenInv.anychest"))
|
||||
{
|
||||
try
|
||||
if(PermissionRelay.hasPermission(event.getPlayer(), "silent") && OpenInv.GetPlayerSilentChestStatus(event.getPlayer().getName()))
|
||||
{
|
||||
silentchest = true;
|
||||
}
|
||||
|
||||
if(PermissionRelay.hasPermission(event.getPlayer(), "anychest") && OpenInv.GetPlayerAnyChestStatus(event.getPlayer().getName()))
|
||||
{
|
||||
try
|
||||
{
|
||||
//FOR REFERENCE, LOOK AT net.minecraft.server.BlockChest
|
||||
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
|
||||
World world = player.world;
|
||||
//If block on top
|
||||
if(world.e(x, y + 1, z))
|
||||
anychest = 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.e(x - 1, y + 1, z)))
|
||||
anychest = true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z)))
|
||||
anychest = true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1)))
|
||||
anychest = true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1)))
|
||||
anychest = true;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//If the anychest or silentchest is active
|
||||
if(anychest || silentchest)
|
||||
{
|
||||
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
|
||||
World world = player.world;
|
||||
//If block on top
|
||||
if(world.e(x, y + 1, z))
|
||||
anychest = true;
|
||||
Object chest = (TileEntityChest)world.getTileEntity(x, y, z);
|
||||
if (chest == null) return;
|
||||
|
||||
//If block next to chest is chest and has a block on top
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z)))
|
||||
anychest = true;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z)))
|
||||
anychest = true;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1)))
|
||||
anychest = true;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1)))
|
||||
anychest = true;
|
||||
}
|
||||
catch(Exception e) //Incompatible CraftBukkit?
|
||||
{
|
||||
e.printStackTrace();
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "Error while executing openinv. Unsupported CraftBukkit.");
|
||||
}
|
||||
if(!anychest)
|
||||
{
|
||||
if (world.e(x, y + 1, z)) return;
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z))) return;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z))) return;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1))) return;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1))) return;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if(!silentchest)
|
||||
{
|
||||
player.a((IInventory)chest);
|
||||
}
|
||||
else
|
||||
{
|
||||
try{
|
||||
Field ciField = player.getClass().getDeclaredField("ci");
|
||||
ciField.setAccessible(true);
|
||||
int ci = ciField.getInt(player);
|
||||
ci = ci % 100 + 1;
|
||||
ciField.setInt(player, ci);
|
||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(ci, 0, ((IInventory)chest).getName(), ((IInventory)chest).getSize()));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory)chest));
|
||||
player.activeContainer.windowId = ci;
|
||||
player.activeContainer.a((ICrafting)player);
|
||||
event.getPlayer().sendMessage("You are opening a chest silently.");
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
if(anychest)
|
||||
event.getPlayer().sendMessage("You are opening a blocked chest.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//If the chest is blocked
|
||||
if(anychest || silentchest)
|
||||
{
|
||||
EntityPlayer player = ((CraftPlayer)event.getPlayer()).getHandle();
|
||||
World world = player.world;
|
||||
Object chest = (TileEntityChest)world.getTileEntity(x, y, z);
|
||||
if (chest == null) return;
|
||||
|
||||
if(!anychest)
|
||||
{
|
||||
if (world.e(x, y + 1, z)) return;
|
||||
if ((world.getTypeId(x - 1, y, z) == Block.CHEST.id) && (world.e(x - 1, y + 1, z))) return;
|
||||
if ((world.getTypeId(x + 1, y, z) == Block.CHEST.id) && (world.e(x + 1, y + 1, z))) return;
|
||||
if ((world.getTypeId(x, y, z - 1) == Block.CHEST.id) && (world.e(x, y + 1, z - 1))) return;
|
||||
if ((world.getTypeId(x, y, z + 1) == Block.CHEST.id) && (world.e(x, y + 1, z + 1))) return;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if(!silentchest)
|
||||
{
|
||||
player.a((IInventory)chest);
|
||||
}
|
||||
else
|
||||
{
|
||||
try{
|
||||
Field ciField = player.getClass().getDeclaredField("ci");
|
||||
ciField.setAccessible(true);
|
||||
int ci = ciField.getInt(player);
|
||||
ci = ci % 100 + 1;
|
||||
ciField.setInt(player, ci);
|
||||
player.netServerHandler.sendPacket(new Packet100OpenWindow(ci, 0, ((IInventory)chest).getName(), ((IInventory)chest).getSize()));
|
||||
player.activeContainer = new SilentContainerChest(player.inventory, ((IInventory)chest));
|
||||
System.out.println(player.activeContainer.toString());
|
||||
player.activeContainer.windowId = ci;
|
||||
player.activeContainer.a((ICrafting)player);
|
||||
event.getPlayer().sendMessage("You are opening a silent chest.");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
event.getPlayer().sendMessage(ChatColor.RED + "Error while sending silent chest.");
|
||||
}
|
||||
}
|
||||
|
||||
if(anychest)
|
||||
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)
|
||||
{
|
||||
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)
|
||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getState() instanceof Sign)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
try{
|
||||
if (PermissionRelay.hasPermission(player, "openinv") &&
|
||||
((Sign)event.getClickedBlock().getState()).getLine(0).equalsIgnoreCase("[openinv]"))
|
||||
Sign sign = ((Sign)event.getClickedBlock().getState());
|
||||
if (PermissionRelay.hasPermission(player, "openinv") && sign.getLine(0).equalsIgnoreCase("[openinv]"))
|
||||
{
|
||||
if(plugin.getServer().getPlayer(((Sign)event.getClickedBlock().getState()).getLine(1)) != null)
|
||||
{
|
||||
Sign sign = ((Sign)event.getClickedBlock().getState());
|
||||
String text = sign.getLine(1).trim() + sign.getLine(2).trim() + sign.getLine(2).trim();
|
||||
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)
|
||||
|
@ -206,5 +168,19 @@ public class OpenInvPlayerListener extends PlayerListener{
|
|||
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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,13 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public class PermissionRelay {
|
||||
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) {
|
||||
return player.isOp() ? true : player.hasPermission(permission);
|
||||
|
|
|
@ -5,14 +5,12 @@ import java.util.HashMap;
|
|||
import lishid.openinv.PermissionRelay;
|
||||
import lishid.openinv.OpenInv;
|
||||
import lishid.openinv.utils.PlayerInventoryChest;
|
||||
import lishid.openinv.utils.OpenInvHistory;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -22,54 +20,34 @@ import org.bukkit.entity.Player;
|
|||
|
||||
public class OpenInvPluginCommand implements CommandExecutor {
|
||||
private final OpenInv plugin;
|
||||
public static HashMap<PlayerInventoryChest, Player> offlineInv = new HashMap<PlayerInventoryChest, Player>();
|
||||
public static HashMap<Player, OpenInvHistory> theOpenInvHistory = new HashMap<Player, OpenInvHistory>();
|
||||
public static HashMap<Player, PlayerInventoryChest> offlineInv = new HashMap<Player, PlayerInventoryChest>();
|
||||
public static HashMap<Player, String> openInvHistory = new HashMap<Player, String>();
|
||||
public OpenInvPluginCommand(OpenInv plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean Offline = false;
|
||||
if(args.length > 0 && args[0].equalsIgnoreCase("?"))
|
||||
{
|
||||
OpenInv.ShowHelp((Player)sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player)sender;
|
||||
boolean Offline = false;
|
||||
|
||||
//History management
|
||||
OpenInvHistory history = theOpenInvHistory.get(player);
|
||||
String history = openInvHistory.get(player);
|
||||
|
||||
if(history == null)
|
||||
if(history == null || history == "")
|
||||
{
|
||||
history = new OpenInvHistory(player);
|
||||
theOpenInvHistory.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;
|
||||
history = player.getName();
|
||||
openInvHistory.put(player, history);
|
||||
}
|
||||
|
||||
//Target selecting
|
||||
|
@ -77,10 +55,11 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
|
||||
String name = "";
|
||||
|
||||
//Read from history if target is not named
|
||||
if (args.length < 1) {
|
||||
if(history.lastPlayer != null)
|
||||
if(history != null && history != "")
|
||||
{
|
||||
name = history.lastPlayer;
|
||||
name = history;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -95,16 +74,17 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
|
||||
target = this.plugin.getServer().getPlayer(name);
|
||||
|
||||
|
||||
if(target == null)
|
||||
{
|
||||
//Offline inv here...
|
||||
try{
|
||||
//See if the player has data files
|
||||
if(!this.plugin.getServer().getOfflinePlayer(name).hasPlayedBefore())
|
||||
{
|
||||
sender.sendMessage(ChatColor.RED + "Player not found!");
|
||||
return true;
|
||||
}
|
||||
//Create an entity to load the player data
|
||||
MinecraftServer server = ((CraftServer)this.plugin.getServer()).getServer();
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), name, new ItemInWorldManager(server.getWorldServer(0)));
|
||||
target = (entity == null) ? null : (Player) entity.getBukkitEntity();
|
||||
|
@ -112,8 +92,6 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
{
|
||||
Offline = true;
|
||||
target.loadData();
|
||||
EntityPlayer entityplayer = ((CraftPlayer)target).getHandle();
|
||||
entityplayer.inventory = new PlayerInventoryChest(entityplayer.inventory, entityplayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -125,57 +103,48 @@ public class OpenInvPluginCommand implements CommandExecutor {
|
|||
{
|
||||
sender.sendMessage("Error while retrieving offline player data!");
|
||||
e.printStackTrace();
|
||||
//sender.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found!");
|
||||
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
|
||||
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!");
|
||||
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()){
|
||||
sender.sendMessage(ChatColor.RED + target.getDisplayName() + " is not in your world!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//The actual openinv
|
||||
history.lastPlayer = target.getName();
|
||||
//Record the target
|
||||
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();
|
||||
|
||||
// Get the EntityPlayer from the Target
|
||||
//Get the EntityPlayer from the Target
|
||||
EntityPlayer entitytarget = ((CraftPlayer) target).getHandle();
|
||||
|
||||
if(!(entitytarget.inventory instanceof PlayerInventoryChest))
|
||||
//Create the inventory
|
||||
PlayerInventoryChest inv = new PlayerInventoryChest(entitytarget.inventory, entitytarget);
|
||||
|
||||
//Save data into the inventory for tracking
|
||||
inv.Opener = player;
|
||||
inv.Target = target;
|
||||
|
||||
//Saves offline openinv
|
||||
if(Offline)
|
||||
{
|
||||
OpenInv.ReplaceInv((CraftPlayer) target);
|
||||
inv.Offline = true;
|
||||
offlineInv.put(target, inv);
|
||||
}
|
||||
|
||||
if(entitytarget.inventory instanceof PlayerInventoryChest)
|
||||
{
|
||||
((PlayerInventoryChest)entitytarget.inventory).Opener = player;
|
||||
((PlayerInventoryChest)entitytarget.inventory).Target = target;
|
||||
|
||||
if(Offline)
|
||||
{
|
||||
((PlayerInventoryChest)entitytarget.inventory).Offline = true;
|
||||
offlineInv.put((PlayerInventoryChest) entitytarget.inventory, target);
|
||||
}
|
||||
}
|
||||
|
||||
entityplayer.a(entitytarget.inventory);
|
||||
//Open the inventory
|
||||
entityplayer.a(inv);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class SearchInvPluginCommand implements CommandExecutor {
|
|||
}
|
||||
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -5,46 +5,207 @@ import org.bukkit.entity.Player;
|
|||
import lishid.openinv.commands.OpenInvPluginCommand;
|
||||
import net.minecraft.server.EntityHuman;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.IInventory;
|
||||
import net.minecraft.server.ItemStack;
|
||||
import net.minecraft.server.PlayerInventory;
|
||||
|
||||
public class PlayerInventoryChest extends PlayerInventory
|
||||
public class PlayerInventoryChest implements IInventory
|
||||
{
|
||||
public boolean Offline = false;
|
||||
public Player Opener;
|
||||
public boolean Offline = false;
|
||||
public Player Opener;
|
||||
EntityPlayer player;
|
||||
public Player Target;
|
||||
private ItemStack[] items = new ItemStack[36];
|
||||
private ItemStack[] armor = new ItemStack[4];
|
||||
private ItemStack[] extra = new ItemStack[5];
|
||||
|
||||
public Player Target;
|
||||
public PlayerInventoryChest(PlayerInventory inventory, EntityPlayer entityplayer) {
|
||||
super(entityplayer);
|
||||
this.armor = inventory.armor;
|
||||
this.items = inventory.items;
|
||||
this.itemInHandIndex = inventory.itemInHandIndex;
|
||||
this.e = inventory.e;
|
||||
this.b(inventory.l());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if(this.d.name.length() > 16)
|
||||
return this.d.name.substring(0, 16);
|
||||
else
|
||||
return this.d.name;
|
||||
public PlayerInventoryChest(PlayerInventory inventory, EntityPlayer entityplayer)
|
||||
{
|
||||
player = entityplayer;
|
||||
this.items = inventory.items;
|
||||
this.armor = inventory.armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean a(EntityHuman entityhuman)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
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 void g() {
|
||||
try{
|
||||
Player player = OpenInvPluginCommand.offlineInv.get(this);
|
||||
if(player != null)
|
||||
{
|
||||
player.saveData();
|
||||
OpenInvPluginCommand.offlineInv.remove(this);
|
||||
}
|
||||
}catch(Exception e){}
|
||||
}
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean a(EntityHuman entityhuman)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void f()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,23 +1,34 @@
|
|||
name: OpenInv
|
||||
main: lishid.openinv.OpenInv
|
||||
version: 1.6.2
|
||||
version: 1.6.6
|
||||
author: lishid
|
||||
website: http://forums.bukkit.org/threads/15379/
|
||||
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:
|
||||
openinv:
|
||||
aliases: [oi, inv, open]
|
||||
description: Open a player's inventory
|
||||
usage: |
|
||||
/<command> <Player>
|
||||
/<command> - Open last person's inventory
|
||||
/<command> <Player> - Open a player's inventory
|
||||
searchinv:
|
||||
aliases: [si, search]
|
||||
description: Search and list players having a specific item
|
||||
usage: |
|
||||
/<command> <Item> [MinAmount] - Item can be the Item ID or the CraftBukkit Item Name, MinAmount is the minimum amount to be considered.
|
||||
toggleopeninv:
|
||||
description: Toggle the stick openinv
|
||||
aliases: [toi, toggleoi, toggleinv]
|
||||
description: Toggle item openinv function
|
||||
usage: |
|
||||
/<command> [check] - Checks whether stick openinv is enabled
|
||||
/<command> [Check] - Checks whether item openinv is enabled
|
||||
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: |
|
||||
/<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
|
Loading…
Reference in a new issue