2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2016-05-12 19:40:39 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2014-11-29 19:16:00 +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
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2014-05-05 13:31:12 +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>")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_tossmob extends FreedomCommand
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.TOSSMOB_ENABLED.getBoolean())
|
2011-11-29 05:41:47 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Tossmob is currently disabled.");
|
2011-11-29 05:41:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
FPlayer playerData = plugin.pl.getPlayer(playerSender);
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
EntityType type = null;
|
2012-11-24 01:22:52 +00:00
|
|
|
if (args.length >= 1)
|
|
|
|
{
|
2014-05-05 13:31:12 +00:00
|
|
|
if ("off".equals(args[0]))
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2012-11-24 01:22:52 +00:00
|
|
|
playerData.disableMobThrower();
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
for (EntityType loop : EntityType.values())
|
|
|
|
{
|
|
|
|
if (loop.isAlive())
|
|
|
|
{
|
|
|
|
sb.append(" ").append(DepreciationAggregator.getName_EntityType(loop));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msg("Supported mobs: " + sb.toString().trim(), ChatColor.GREEN);
|
2012-11-24 01:22:52 +00:00
|
|
|
return true;
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
for (EntityType loopType : EntityType.values())
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
if (DepreciationAggregator.getName_EntityType(loopType).toLowerCase().equalsIgnoreCase(args[0]))
|
|
|
|
{
|
|
|
|
type = loopType;
|
|
|
|
break;
|
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
2016-05-12 19:40:39 +00:00
|
|
|
|
|
|
|
if (type == null)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +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);
|
2016-05-12 19:40:39 +00:00
|
|
|
type = 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
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
playerData.enableMobThrower(type, speed);
|
|
|
|
msg("MobThrower is enabled. Creature: " + type + " - Speed: " + speed + ".", ChatColor.GREEN);
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
|
|
|
|
msg("Type '/tossmob off' to disable. -By Madgeek1450", ChatColor.GREEN);
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.BONE, 1));
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|