2022-03-20 12:35:43 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.commands;
|
2012-11-03 19:03:38 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.world.ProtectedArea;
|
2014-11-29 19:16:00 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2012-11-03 19:03:38 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
|
2013-03-19 22:05:20 +00:00
|
|
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
2022-03-20 12:35:43 +00:00
|
|
|
public class Command_protectarea extends FreedomCommand {
|
2014-12-21 09:23:50 +00:00
|
|
|
|
2012-11-03 19:03:38 +00:00
|
|
|
@Override
|
2022-03-20 12:35:43 +00:00
|
|
|
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
|
|
|
if (!ConfigurationEntry.PROTECTAREA_ENABLED.getBoolean()) {
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Protected areas are currently disabled in the TotalFreedomMod configuration.");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
if (args.length == 1) {
|
2012-11-03 19:03:38 +00:00
|
|
|
if (args[0].equalsIgnoreCase("list"))
|
|
|
|
{
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Protected Areas: " + StringUtils.join(ProtectedArea.getProtectedAreaLabels(), ", "));
|
2012-11-03 19:03:38 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("clear"))
|
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
ProtectedArea.clearProtectedAreas();
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Protected Areas Cleared.");
|
2012-11-03 19:03:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (args.length == 2)
|
|
|
|
{
|
2014-05-05 13:31:12 +00:00
|
|
|
if ("remove".equals(args[0]))
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
2022-03-20 12:35:43 +00:00
|
|
|
ProtectedArea.removeProtectedArea(args[1]);
|
2012-11-03 19:03:38 +00:00
|
|
|
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Area removed. Protected Areas: " + StringUtils.join(ProtectedArea.getProtectedAreaLabels(), ", "));
|
2012-11-03 19:03:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (args.length == 3)
|
|
|
|
{
|
|
|
|
if (args[0].equalsIgnoreCase("add"))
|
|
|
|
{
|
|
|
|
if (senderIsConsole)
|
|
|
|
{
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "You must be in-game to set a protected area.");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Double radius;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
radius = Double.parseDouble(args[2]);
|
|
|
|
}
|
|
|
|
catch (NumberFormatException nfex)
|
|
|
|
{
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Invalid radius.");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
if (radius > ProtectedArea.MAX_RADIUS || radius < 0.0D)
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Invalid radius. Radius must be a positive value less than " + ProtectedArea.MAX_RADIUS + ".");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
ProtectedArea.addProtectedArea(args[1], sender_p.getLocation(), radius);
|
2012-11-03 19:03:38 +00:00
|
|
|
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Area added. Protected Areas: " + StringUtils.join(ProtectedArea.getProtectedAreaLabels(), ", "));
|
2012-11-03 19:03:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-03 19:03:38 +00:00
|
|
|
}
|
|
|
|
}
|