TFM-4.3-Reloaded/src/me/StevenLawson/TotalFreedomMod/Commands/Command_tossmob.java

89 lines
2.9 KiB
Java
Raw Normal View History

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;
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
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
@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())
{
playerMsg("Tossmob is currently disabled.");
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
EntityType creature = EntityType.PIG;
if (args.length >= 1)
{
if (TFM_Util.isStopCommand(args[0]))
2011-10-19 00:37:00 +00:00
{
playerData.disableMobThrower();
playerMsg("MobThrower is disabled.", ChatColor.GREEN);
return true;
2011-10-19 00:37:00 +00:00
}
if (args[0].equalsIgnoreCase("list"))
2011-10-19 00:37:00 +00:00
{
playerMsg("Supported mobs: " + StringUtils.join(TFM_Util.mobtypes.keySet(), ", "), ChatColor.GREEN);
return true;
2011-10-19 00:37:00 +00:00
}
try
2011-10-19 00:37:00 +00:00
{
creature = TFM_Util.getEntityType(args[0]);
2011-10-19 00:37:00 +00:00
}
catch (Exception ex)
2011-10-19 00:37:00 +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);
creature = EntityType.PIG;
2011-10-19 00:37:00 +00:00
}
}
2011-10-19 00:37:00 +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
if (speed < 1.0)
{
speed = 1.0;
2011-10-19 00:37:00 +00:00
}
else if (speed > 5.0)
2011-10-19 00:37:00 +00:00
{
speed = 5.0;
2011-10-19 00:37:00 +00:00
}
playerData.enableMobThrower(creature, speed);
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);
sender_p.setItemInHand(new ItemStack(Material.STICK, 1));
2011-10-19 00:37:00 +00:00
return true;
}
}