2012-11-03 19:03:38 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
|
|
|
|
2014-04-11 15:24:44 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.Config.TFM_ConfigEntry;
|
2012-11-03 19:03:38 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_ProtectedArea;
|
2013-08-15 21:36:55 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
2013-12-01 11:13:39 +00:00
|
|
|
import net.minecraft.util.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;
|
|
|
|
|
2013-03-19 22:05:20 +00:00
|
|
|
@CommandPermissions(level = AdminLevel.SUPER, 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>>")
|
2012-11-03 19:03:38 +00:00
|
|
|
public class Command_protectarea extends TFM_Command
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2013-08-18 19:27:17 +00:00
|
|
|
if (!TFM_ConfigEntry.PROTECTED_AREAS_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"))
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Protected Areas: " + StringUtils.join(TFM_ProtectedArea.getProtectedAreaLabels(), ", "));
|
2012-11-03 19:03:38 +00:00
|
|
|
}
|
|
|
|
else if (args[0].equalsIgnoreCase("clear"))
|
|
|
|
{
|
|
|
|
TFM_ProtectedArea.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)
|
|
|
|
{
|
2013-08-15 21:36:55 +00:00
|
|
|
if (TFM_Util.isRemoveCommand(args[0]))
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
|
|
|
TFM_ProtectedArea.removeProtectedArea(args[1]);
|
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Area removed. Protected Areas: " + StringUtils.join(TFM_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)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radius > TFM_ProtectedArea.MAX_RADIUS || radius < 0.0D)
|
|
|
|
{
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Invalid radius. Radius must be a positive value less than " + TFM_ProtectedArea.MAX_RADIUS + ".");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
TFM_ProtectedArea.addProtectedArea(args[1], sender_p.getLocation(), radius);
|
|
|
|
|
2013-01-07 14:56:53 +00:00
|
|
|
playerMsg("Area added. Protected Areas: " + StringUtils.join(TFM_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
|
|
|
}
|
|
|
|
}
|