2017-10-13 18:35:11 +00:00
package me.totalfreedom.totalfreedommod.command ;
import me.totalfreedom.totalfreedommod.player.FPlayer ;
import me.totalfreedom.totalfreedommod.rank.Rank ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
import org.bukkit.inventory.Inventory ;
2018-01-23 19:00:15 +00:00
import org.bukkit.inventory.ItemStack ;
2017-10-13 18:35:11 +00:00
@CommandPermissions ( level = Rank . OP , source = SourceType . ONLY_IN_GAME )
2020-03-30 23:43:57 +00:00
@CommandParameters ( description = " Look into another player's inventory, or optionally take items out. " , usage = " /<command> <player> [offhand | armor] " , aliases = " inv,insee " )
2017-10-13 18:35:11 +00:00
public class Command_invsee extends FreedomCommand
{
@Override
public boolean run ( CommandSender sender , Player playerSender , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
2018-01-23 19:00:15 +00:00
if ( args . length < 1 )
2017-10-13 18:35:11 +00:00
{
return false ;
}
2020-04-23 11:18:03 +00:00
Player player = getPlayer ( args [ 0 ] , true ) ;
2017-10-13 18:35:11 +00:00
2020-04-23 11:18:03 +00:00
if ( player = = null )
2017-10-13 18:35:11 +00:00
{
2020-04-23 11:18:03 +00:00
msg ( PLAYER_NOT_FOUND ) ;
2017-10-13 18:35:11 +00:00
return false ;
}
if ( playerSender = = player )
{
msg ( " You cannot invsee yourself. " ) ;
return true ;
}
if ( plugin . al . isAdmin ( player ) & & ! plugin . al . isAdmin ( playerSender ) )
{
2018-06-28 18:13:18 +00:00
msg ( " You cannot spy on administrators. " ) ;
2017-10-13 18:35:11 +00:00
return true ;
2018-01-23 19:00:15 +00:00
}
2018-06-28 18:13:18 +00:00
Inventory inv ;
if ( plugin . al . isAdmin ( player ) )
2018-01-23 19:00:15 +00:00
{
2018-06-28 18:13:18 +00:00
if ( args . length > 1 )
2018-01-23 19:00:15 +00:00
{
2018-06-28 18:13:18 +00:00
if ( args [ 1 ] . equals ( " offhand " ) )
2018-01-23 19:00:15 +00:00
{
2018-06-28 18:13:18 +00:00
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 ) ;
2018-01-23 19:00:15 +00:00
return true ;
}
}
2018-06-28 18:13:18 +00:00
inv = player . getInventory ( ) ;
playerSender . closeInventory ( ) ;
playerSender . openInventory ( inv ) ;
return true ;
}
if ( ! plugin . al . isAdmin ( player ) )
{
if ( args . length > 1 )
2018-01-23 19:00:15 +00:00
{
2018-06-28 18:13:18 +00:00
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 ;
}
2018-01-23 19:00:15 +00:00
}
2018-06-28 18:13:18 +00:00
inv = player . getInventory ( ) ;
playerSender . closeInventory ( ) ;
FPlayer fPlayer = plugin . pl . getPlayer ( playerSender ) ;
fPlayer . setInvSee ( true ) ;
playerSender . openInventory ( inv ) ;
return true ;
2018-01-23 19:00:15 +00:00
}
2017-10-13 18:35:11 +00:00
return true ;
}
}
2018-01-23 19:00:15 +00:00