2011-10-19 00:37:00 +00:00
package me.StevenLawson.TotalFreedomMod.Commands ;
2013-08-18 19:52:32 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry ;
2013-01-21 18:58:42 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData ;
2011-10-24 02:43:52 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_Util ;
2013-09-04 12:35:12 +00:00
import org.apache.commons.lang3.StringUtils ;
2011-10-19 00:37:00 +00:00
import org.bukkit.ChatColor ;
2011-10-21 17:02:07 +00:00
import org.bukkit.Material ;
2011-10-19 00:37:00 +00:00
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
2012-03-03 04:29:54 +00:00
import org.bukkit.entity.EntityType ;
2011-10-19 00:37:00 +00:00
import org.bukkit.entity.Player ;
2011-10-21 17:02:07 +00:00
import org.bukkit.inventory.ItemStack ;
2011-10-19 00:37:00 +00:00
2013-03-19 22:05:20 +00:00
@CommandPermissions ( level = AdminLevel . OP , source = SourceType . ONLY_IN_GAME )
2013-04-10 02:05:24 +00:00
@CommandParameters ( description = " Throw a mob in the direction you are facing when you left click with a stick. " , usage = " /<command> <mobtype [speed] | off | list> " )
2011-10-19 00:37:00 +00:00
public class Command_tossmob extends TFM_Command
{
@Override
public boolean run ( CommandSender sender , Player sender_p , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
2013-08-18 19:52:32 +00:00
if ( ! TFM_ConfigEntry . TOSSMOB_ENABLED . getBoolean ( ) )
2011-11-29 05:41:47 +00:00
{
2013-01-07 14:56:53 +00:00
playerMsg ( " Tossmob is currently disabled. " ) ;
2011-11-29 05:41:47 +00:00
return true ;
}
2013-01-21 18:58:42 +00:00
TFM_PlayerData playerData = TFM_PlayerData . getPlayerData ( sender_p ) ;
2011-10-19 00:37:00 +00:00
2012-11-24 01:22:52 +00:00
EntityType creature = EntityType . PIG ;
if ( args . length > = 1 )
{
if ( TFM_Util . isStopCommand ( args [ 0 ] ) )
2011-10-19 00:37:00 +00:00
{
2012-11-24 01:22:52 +00:00
playerData . disableMobThrower ( ) ;
2013-01-07 14:56:53 +00:00
playerMsg ( " MobThrower is disabled. " , ChatColor . GREEN ) ;
2012-11-24 01:22:52 +00:00
return true ;
2011-10-19 00:37:00 +00:00
}
2012-11-24 01:22:52 +00:00
if ( args [ 0 ] . equalsIgnoreCase ( " list " ) )
2011-10-19 00:37:00 +00:00
{
2013-01-07 14:56:53 +00:00
playerMsg ( " Supported mobs: " + StringUtils . join ( TFM_Util . mobtypes . keySet ( ) , " , " ) , ChatColor . GREEN ) ;
2012-11-24 01:22:52 +00:00
return true ;
2011-10-19 00:37:00 +00:00
}
2012-11-24 01:22:52 +00:00
try
2011-10-19 00:37:00 +00:00
{
2012-11-24 01:22:52 +00:00
creature = TFM_Util . getEntityType ( args [ 0 ] ) ;
2011-10-19 00:37:00 +00:00
}
2013-08-14 13:28:19 +00:00
catch ( Exception ex )
2011-10-19 00:37:00 +00:00
{
2013-01-07 14:56:53 +00:00
playerMsg ( args [ 0 ] + " is not a supported mob type. Using a pig instead. " , ChatColor . RED ) ;
playerMsg ( " By the way, you can type /tossmob list to see all possible mobs. " , ChatColor . RED ) ;
2012-11-24 01:22:52 +00:00
creature = EntityType . PIG ;
2011-10-19 00:37:00 +00:00
}
2012-11-24 01:22:52 +00:00
}
2011-10-19 00:37:00 +00:00
2012-11-24 01:22:52 +00:00
double speed = 1 . 0 ;
if ( args . length > = 2 )
{
try
{
speed = Double . parseDouble ( args [ 1 ] ) ;
}
catch ( NumberFormatException nfex )
{
}
}
2011-10-24 02:43:52 +00:00
2012-11-24 01:22:52 +00:00
if ( speed < 1 . 0 )
{
speed = 1 . 0 ;
2011-10-19 00:37:00 +00:00
}
2012-11-24 01:22:52 +00:00
else if ( speed > 5 . 0 )
2011-10-19 00:37:00 +00:00
{
2012-11-24 01:22:52 +00:00
speed = 5 . 0 ;
2011-10-19 00:37:00 +00:00
}
2012-11-24 01:22:52 +00:00
playerData . enableMobThrower ( creature , speed ) ;
2013-01-07 14:56:53 +00:00
playerMsg ( " MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + " . " , ChatColor . GREEN ) ;
playerMsg ( " Left click while holding a stick to throw mobs! " , ChatColor . GREEN ) ;
playerMsg ( " Type '/tossmob off' to disable. -By Madgeek1450 " , ChatColor . GREEN ) ;
2012-11-24 01:22:52 +00:00
sender_p . setItemInHand ( new ItemStack ( Material . STICK , 1 ) ) ;
2011-10-19 00:37:00 +00:00
return true ;
}
}