2012-09-19 02:21:25 +00:00
package me.StevenLawson.TotalFreedomMod.Commands ;
import java.util.ArrayList ;
import java.util.List ;
2012-09-20 01:43:12 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_Util ;
2012-09-19 02:21:25 +00:00
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod ;
import org.apache.commons.lang.StringUtils ;
import org.bukkit.ChatColor ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2012-09-20 01:43:12 +00:00
import org.bukkit.potion.PotionEffect ;
import org.bukkit.potion.PotionEffectType ;
2012-09-19 02:21:25 +00:00
public class Command_potion extends TFM_Command
{
@Override
public boolean run ( CommandSender sender , Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
if ( senderIsConsole )
{
sender . sendMessage ( TotalFreedomMod . NOT_FROM_CONSOLE ) ;
return true ;
}
if ( ! sender . isOp ( ) )
{
sender . sendMessage ( TotalFreedomMod . MSG_NO_PERMS ) ;
return true ;
}
2012-09-20 01:43:12 +00:00
if ( args . length = = 1 | | args . length = = 2 )
2012-09-19 02:21:25 +00:00
{
2012-09-20 01:43:12 +00:00
if ( args [ 0 ] . equalsIgnoreCase ( " list " ) )
{
List < String > potionEffectTypeNames = new ArrayList < String > ( ) ;
for ( PotionEffectType potion_effect_type : PotionEffectType . values ( ) )
{
if ( potion_effect_type ! = null )
{
potionEffectTypeNames . add ( potion_effect_type . getName ( ) ) ;
}
}
sender . sendMessage ( ChatColor . AQUA + " Potion effect types: " + StringUtils . join ( potionEffectTypeNames , " , " ) ) ;
}
else if ( args [ 0 ] . equalsIgnoreCase ( " clear " ) )
{
Player target = sender_p ;
2012-09-19 02:21:25 +00:00
2012-09-20 01:43:12 +00:00
if ( args . length = = 2 )
{
try
{
target = getPlayer ( args [ 1 ] ) ;
}
catch ( CantFindPlayerException ex )
{
sender . sendMessage ( ex . getMessage ( ) ) ;
return true ;
}
}
if ( ! target . equals ( sender_p ) & & ! TFM_Util . isUserSuperadmin ( sender ) )
{
sender . sendMessage ( " Only superadmins can clear potion effects from other players. " ) ;
return true ;
}
2012-09-20 03:17:10 +00:00
for ( PotionEffect potion_effect : target . getActivePotionEffects ( ) )
2012-09-20 01:43:12 +00:00
{
target . removePotionEffect ( potion_effect . getType ( ) ) ;
}
sender . sendMessage ( ChatColor . AQUA + " Cleared all active potion effects " + ( ! target . equals ( sender_p ) ? " from player " + target . getName ( ) + " . " : " from yourself. " ) ) ;
}
else
2012-09-19 02:21:25 +00:00
{
2012-09-20 01:43:12 +00:00
return false ;
2012-09-19 02:21:25 +00:00
}
}
2012-09-20 01:43:12 +00:00
else if ( args . length = = 4 | | args . length = = 5 )
{
if ( args [ 0 ] . equalsIgnoreCase ( " add " ) )
{
Player target = sender_p ;
if ( args . length = = 5 )
{
try
{
target = getPlayer ( args [ 4 ] ) ;
}
catch ( CantFindPlayerException ex )
{
sender . sendMessage ( ex . getMessage ( ) ) ;
return true ;
}
}
2012-09-19 02:21:25 +00:00
2012-09-20 01:43:12 +00:00
if ( ! target . equals ( sender_p ) & & ! TFM_Util . isUserSuperadmin ( sender ) )
{
sender . sendMessage ( " Only superadmins can apply potion effects to other players. " ) ;
return true ;
}
PotionEffectType potion_effect_type = PotionEffectType . getByName ( args [ 1 ] ) ;
if ( potion_effect_type = = null )
{
sender . sendMessage ( ChatColor . AQUA + " Invalid potion effect type. " ) ;
return true ;
}
int duration ;
try
{
duration = Integer . parseInt ( args [ 2 ] ) ;
}
catch ( NumberFormatException ex )
{
sender . sendMessage ( ChatColor . AQUA + " Invalid potion duration. " ) ;
return true ;
}
int amplifier ;
try
{
amplifier = Integer . parseInt ( args [ 3 ] ) ;
}
catch ( NumberFormatException ex )
{
sender . sendMessage ( ChatColor . AQUA + " Invalid potion amplifier. " ) ;
return true ;
}
PotionEffect new_effect = potion_effect_type . createEffect ( duration , amplifier ) ;
target . addPotionEffect ( new_effect , true ) ;
sender . sendMessage ( ChatColor . AQUA
+ " Added potion effect: " + new_effect . getType ( ) . getName ( )
+ " , Duration: " + new_effect . getDuration ( )
+ " , Amplifier: " + new_effect . getAmplifier ( )
+ ( ! target . equals ( sender_p ) ? " to player " + target . getName ( ) + " . " : " to yourself. " ) ) ;
return true ;
}
else
{
return false ;
}
}
else
{
return false ;
}
2012-09-19 02:21:25 +00:00
return true ;
}
}