2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2012-11-03 19:03:38 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.ProtectArea;
|
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;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(
|
|
|
|
description = "Protect areas so that only superadmins can directly modify blocks in those areas. WorldEdit and other such plugins might bypass this.",
|
|
|
|
usage = "/<command> <list | clear | remove <label> | add <label> <radius>>")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_protectarea extends FreedomCommand
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
2014-12-21 09:23:50 +00:00
|
|
|
|
2012-11-03 19:03:38 +00:00
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Protected areas are currently disabled in the TotalFreedomMod configuration.");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
if (args[0].equalsIgnoreCase("list"))
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
playerMsg("Protected Areas: " + StringUtils.join(plugin.pa.getProtectedAreaLabels(), ", "));
|
2012-11-03 19:03:38 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("clear"))
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.pa.clearProtectedAreas();
|
2012-11-24 01:22:52 +00:00
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("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
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.pa.removeProtectedArea(args[1]);
|
2012-11-03 19:03:38 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
playerMsg("Area removed. Protected Areas: " + StringUtils.join(plugin.pa.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)
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("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)
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Invalid radius.");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
if (radius > ProtectArea.MAX_RADIUS || radius < 0.0D)
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
playerMsg("Invalid radius. Radius must be a positive value less than " + ProtectArea.MAX_RADIUS + ".");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.pa.addProtectedArea(args[1], sender_p.getLocation(), radius);
|
2012-11-03 19:03:38 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
playerMsg("Area added. Protected Areas: " + StringUtils.join(plugin.pa.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
|
|
|
}
|
|
|
|
}
|