2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
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
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
|
2012-11-03 19:03:38 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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"))
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Invalid radius. Radius must be a positive value less than " + ProtectArea.MAX_RADIUS + ".");
|
2012-11-03 19:03:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
plugin.pa.addProtectedArea(args[1], playerSender.getLocation(), radius);
|
2012-11-03 19:03:38 +00:00
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("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
|
|
|
}
|
|
|
|
}
|