2016-03-02 19:28:01 +00:00
package me.totalfreedom.totalfreedommod.command ;
2011-10-19 00:37:00 +00:00
2019-01-29 04:57:41 +00:00
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.List ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.player.FPlayer ;
2016-03-06 15:56:15 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.util.FUtil ;
2017-10-13 18:35:11 +00:00
import org.bukkit.ChatColor ;
2011-10-19 00:37:00 +00:00
import org.bukkit.GameMode ;
import org.bukkit.Location ;
import org.bukkit.Material ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2016-03-06 15:56:15 +00:00
@CommandPermissions ( level = Rank . SUPER_ADMIN , source = SourceType . BOTH )
2020-05-29 10:14:21 +00:00
@CommandParameters ( description = " Place a cage around someone with certain blocks, or someone's player head. " , usage = " /<command> <purge | <partialname> [head | block] [playername | blockname] " )
2015-10-19 17:43:46 +00:00
public class Command_cage extends FreedomCommand
2011-10-19 00:37:00 +00:00
{
2018-07-31 06:41:56 +00:00
2018-01-01 03:43:10 +00:00
public boolean run ( final CommandSender sender , final Player playerSender , final Command cmd , final String commandLabel , final String [ ] args , final boolean senderIsConsole )
{
if ( args . length = = 0 )
{
2012-11-23 03:48:28 +00:00
return false ;
}
2020-05-29 10:14:21 +00:00
2018-01-01 03:43:10 +00:00
String skullName = null ;
if ( " purge " . equals ( args [ 0 ] ) )
{
2015-10-19 17:43:46 +00:00
FUtil . adminAction ( sender . getName ( ) , " Uncaging all players " , true ) ;
2018-01-01 03:43:10 +00:00
for ( Player player : server . getOnlinePlayers ( ) )
{
final FPlayer fPlayer = plugin . pl . getPlayer ( player ) ;
fPlayer . getCageData ( ) . setCaged ( false ) ;
2013-09-26 00:33:44 +00:00
}
return true ;
}
2020-05-29 10:14:21 +00:00
2018-01-01 03:43:10 +00:00
Player player = getPlayer ( args [ 0 ] ) ;
if ( player = = null )
{
2015-10-19 17:43:46 +00:00
sender . sendMessage ( FreedomCommand . PLAYER_NOT_FOUND ) ;
2012-11-23 03:48:28 +00:00
return true ;
}
2020-05-29 10:14:21 +00:00
2018-01-01 03:43:10 +00:00
final FPlayer fPlayer = plugin . pl . getPlayer ( player ) ;
2020-05-29 10:14:21 +00:00
2013-08-25 23:08:53 +00:00
Material outerMaterial = Material . GLASS ;
Material innerMaterial = Material . AIR ;
2018-01-01 03:43:10 +00:00
if ( args . length > = 2 & & args [ 1 ] ! = null )
{
2017-10-13 18:35:11 +00:00
final String s = args [ 1 ] ;
2018-01-01 03:43:10 +00:00
switch ( s )
{
2020-03-30 23:43:57 +00:00
case " head " :
2018-01-01 03:43:10 +00:00
{
2018-07-25 02:08:29 +00:00
outerMaterial = Material . PLAYER_HEAD ;
2018-01-01 03:43:10 +00:00
if ( args . length > = 3 )
{
skullName = args [ 2 ] ;
}
2018-07-25 02:08:29 +00:00
else
{
outerMaterial = Material . SKELETON_SKULL ;
}
2017-10-13 18:35:11 +00:00
break ;
2013-08-25 23:08:53 +00:00
}
2018-01-01 03:43:10 +00:00
case " block " :
{
if ( Material . matchMaterial ( args [ 2 ] ) ! = null )
{
2017-10-13 18:35:11 +00:00
outerMaterial = Material . matchMaterial ( args [ 2 ] ) ;
break ;
}
sender . sendMessage ( ChatColor . RED + " Invalid block! " ) ;
break ;
2011-10-19 00:37:00 +00:00
}
}
2012-11-23 03:48:28 +00:00
}
2018-07-25 02:44:00 +00:00
2018-01-01 03:43:10 +00:00
Location location = player . getLocation ( ) . clone ( ) . add ( 0 . 0 , 1 . 0 , 0 . 0 ) ;
2020-05-29 10:14:21 +00:00
2018-01-01 03:43:10 +00:00
if ( skullName ! = null )
{
fPlayer . getCageData ( ) . cage ( location , outerMaterial , innerMaterial , skullName ) ;
}
else
{
fPlayer . getCageData ( ) . cage ( location , outerMaterial , innerMaterial ) ;
}
2020-05-29 10:14:21 +00:00
2018-01-01 03:43:10 +00:00
player . setGameMode ( GameMode . SURVIVAL ) ;
2020-05-29 10:14:21 +00:00
2018-07-25 02:47:04 +00:00
if ( outerMaterial = = Material . PLAYER_HEAD )
2018-01-01 03:43:10 +00:00
{
FUtil . adminAction ( sender . getName ( ) , " Caging " + player . getName ( ) + " in " + skullName , true ) ;
2013-08-25 23:08:53 +00:00
}
2018-01-01 03:43:10 +00:00
else
{
FUtil . adminAction ( sender . getName ( ) , " Caging " + player . getName ( ) , true ) ;
2013-08-25 23:08:53 +00:00
}
2011-10-19 00:37:00 +00:00
return true ;
}
2019-01-29 04:57:41 +00:00
@Override
public List < String > getTabCompleteOptions ( CommandSender sender , Command command , String alias , String [ ] args )
{
if ( ! plugin . al . isAdmin ( sender ) )
{
return null ;
}
if ( args . length = = 1 )
{
List < String > arguments = new ArrayList < > ( ) ;
arguments . add ( " purge " ) ;
arguments . addAll ( FUtil . getPlayerList ( ) ) ;
return arguments ;
}
else if ( args . length = = 2 )
{
if ( ! args [ 0 ] . equals ( " purge " ) )
{
2020-05-29 10:14:21 +00:00
return Arrays . asList ( " head " , " block " ) ;
2019-01-29 04:57:41 +00:00
}
}
else if ( args . length = = 3 )
{
if ( args [ 1 ] . equals ( " block " ) )
{
return FUtil . getAllMaterialNames ( ) ;
}
2020-03-30 23:43:57 +00:00
else if ( args [ 1 ] . equals ( " head " ) )
2019-01-29 04:57:41 +00:00
{
return FUtil . getPlayerList ( ) ;
}
}
return Collections . emptyList ( ) ;
}
2011-10-19 00:37:00 +00:00
}