2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2020-08-06 20:05:17 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
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;
|
2020-08-06 20:05:17 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.Groups;
|
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;
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:05:17 +00:00
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2020-08-06 20:05:17 +00:00
|
|
|
if (args[0].equalsIgnoreCase("off"))
|
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
|
|
|
{
|
2020-08-06 20:05:17 +00:00
|
|
|
msg("Supported mobs: " + getAllMobNames(), ChatColor.GREEN);
|
2012-11-24 01:22:52 +00:00
|
|
|
return true;
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 20:05:17 +00:00
|
|
|
for (EntityType loop : EntityType.values())
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2020-08-06 20:05:17 +00:00
|
|
|
if (loop != null && loop.name().equalsIgnoreCase(args[0]))
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2020-08-06 20:05:17 +00:00
|
|
|
type = loop;
|
2016-05-12 19:40:39 +00:00
|
|
|
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
|
|
|
{
|
2020-08-06 20:05:17 +00:00
|
|
|
msg("Unknown entity type: " + args[0], ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Groups.MOB_TYPES.contains(type))
|
|
|
|
{
|
|
|
|
msg(FUtil.formatName(type.name()) + " is an entity, however it is not a mob.", ChatColor.RED);
|
|
|
|
return true;
|
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]);
|
|
|
|
}
|
2020-08-06 20:05:17 +00:00
|
|
|
catch (NumberFormatException ex)
|
2012-11-24 01:22:52 +00:00
|
|
|
{
|
2020-08-06 20:05:17 +00:00
|
|
|
msg("The input provided is not a valid integer.");
|
|
|
|
return true;
|
2012-11-24 01:22:52 +00:00
|
|
|
}
|
|
|
|
}
|
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);
|
2020-08-06 20:05:17 +00:00
|
|
|
msg("MobThrower is enabled. Mob: " + 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);
|
2020-08-06 20:05:17 +00:00
|
|
|
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));
|
2011-10-19 00:37:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-08-06 20:05:17 +00:00
|
|
|
public static List<String> getAllMobNames()
|
|
|
|
{
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
for (EntityType entityType : Groups.MOB_TYPES)
|
|
|
|
{
|
|
|
|
names.add(entityType.name());
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
}
|