Fix /invsee (#79)

This commit is contained in:
Telesphoreo 2018-06-28 11:13:18 -07:00 committed by Seth
parent 650f732dd4
commit bd44173a14

View File

@ -12,7 +12,6 @@ import org.bukkit.inventory.ItemStack;
@CommandParameters(description = "Look into another player's inventory, optionally take items out.", usage = "/<command> <player> [offhand | armor]", aliases = "inv,insee") @CommandParameters(description = "Look into another player's inventory, optionally take items out.", usage = "/<command> <player> [offhand | armor]", aliases = "inv,insee")
public class Command_invsee extends FreedomCommand public class Command_invsee extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
@ -38,11 +37,16 @@ public class Command_invsee extends FreedomCommand
if (plugin.al.isAdmin(player) && !plugin.al.isAdmin(playerSender)) if (plugin.al.isAdmin(player) && !plugin.al.isAdmin(playerSender))
{ {
msg("You can't spy on admins!"); msg("You cannot spy on administrators.");
return true; return true;
} }
if(args.length >= 2)
Inventory inv;
if (plugin.al.isAdmin(player))
{
if (args.length > 1)
{ {
if (args[1].equals("offhand")) if (args[1].equals("offhand"))
{ {
@ -57,7 +61,7 @@ public class Command_invsee extends FreedomCommand
playerSender.openInventory(inventory); playerSender.openInventory(inventory);
return true; return true;
} }
if (args[1].equals("armor")) else if (args[1].equals("armor"))
{ {
Inventory inventory = server.createInventory(null, 9, player.getName() + "'s armor"); Inventory inventory = server.createInventory(null, 9, player.getName() + "'s armor");
inventory.setContents(player.getInventory().getArmorContents()); inventory.setContents(player.getInventory().getArmorContents());
@ -65,11 +69,44 @@ public class Command_invsee extends FreedomCommand
return true; return true;
} }
} }
inv = player.getInventory();
playerSender.closeInventory();
playerSender.openInventory(inv);
return true;
}
if (!plugin.al.isAdmin(player))
{
if (args.length > 1)
{
if (args[1].equals("offhand"))
{
ItemStack offhand = player.getInventory().getItemInOffHand();
if (offhand == null)
{
msg("That player has nothing in their offhand.");
return true;
}
Inventory inventory = server.createInventory(null, 9, player.getName() + "'s offhand");
inventory.setItem(1, offhand);
playerSender.openInventory(inventory);
return true;
}
else if (args[1].equals("armor"))
{
Inventory inventory = server.createInventory(null, 9, player.getName() + "'s armor");
inventory.setContents(player.getInventory().getArmorContents());
playerSender.openInventory(inventory);
return true;
}
}
inv = player.getInventory();
playerSender.closeInventory(); playerSender.closeInventory();
FPlayer fPlayer = plugin.pl.getPlayer(playerSender); FPlayer fPlayer = plugin.pl.getPlayer(playerSender);
fPlayer.setInvSee(true); fPlayer.setInvSee(true);
Inventory playerInv = player.getInventory(); playerSender.openInventory(inv);
playerSender.openInventory(playerInv); return true;
}
return true; return true;
} }
} }