TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tossmob.java

92 lines
2.9 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2011-10-19 00:37:00 +00:00
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
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 = Rank.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>")
public class Command_tossmob extends FreedomCommand
2011-10-19 00:37:00 +00:00
{
2011-10-19 00:37:00 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
2011-10-19 00:37:00 +00:00
{
if (!ConfigEntry.TOSSMOB_ENABLED.getBoolean())
{
msg("Tossmob is currently disabled.");
return true;
}
FPlayer playerData = plugin.pl.getPlayer(playerSender);
2011-10-19 00:37:00 +00:00
EntityType creature = EntityType.PIG;
if (args.length >= 1)
{
if ("off".equals(args[0]))
2011-10-19 00:37:00 +00:00
{
playerData.disableMobThrower();
msg("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
{
msg("Supported mobs: " + StringUtils.join(FUtil.MOB_TYPES.keySet(), ", "), ChatColor.GREEN);
return true;
2011-10-19 00:37:00 +00:00
}
try
2011-10-19 00:37:00 +00:00
{
creature = FUtil.getEntityType(args[0]);
2011-10-19 00:37:00 +00:00
}
catch (Exception ex)
2011-10-19 00:37:00 +00:00
{
msg(args[0] + " is not a supported mob type. Using a pig instead.", ChatColor.RED);
msg("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);
msg("MobThrower is enabled. Creature: " + creature + " - Speed: " + speed + ".", ChatColor.GREEN);
msg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
msg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
playerSender.setItemInHand(new ItemStack(Material.BONE, 1));
2011-10-19 00:37:00 +00:00
return true;
}
}