TFM-4.3-Reloaded/src/main/java/me/totalfreedom/totalfreedommod/commands/Command_protectarea.java
JeromSar a0058869c9 Added checkstyle plugin
Moved resources to correct folder
Fixed and improved build information, no longer tracking build.properties
2015-11-22 19:28:32 +01:00

105 lines
3.3 KiB
Java

package me.totalfreedom.totalfreedommod.commands;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.ProtectArea;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
@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>>")
public class Command_protectarea extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean())
{
playerMsg("Protected areas are currently disabled in the TotalFreedomMod configuration.");
return true;
}
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("list"))
{
playerMsg("Protected Areas: " + StringUtils.join(plugin.pa.getProtectedAreaLabels(), ", "));
}
else if (args[0].equalsIgnoreCase("clear"))
{
plugin.pa.clearProtectedAreas();
playerMsg("Protected Areas Cleared.");
}
else
{
return false;
}
return true;
}
else if (args.length == 2)
{
if ("remove".equals(args[0]))
{
plugin.pa.removeProtectedArea(args[1]);
playerMsg("Area removed. Protected Areas: " + StringUtils.join(plugin.pa.getProtectedAreaLabels(), ", "));
}
else
{
return false;
}
return true;
}
else if (args.length == 3)
{
if (args[0].equalsIgnoreCase("add"))
{
if (senderIsConsole)
{
playerMsg("You must be in-game to set a protected area.");
return true;
}
Double radius;
try
{
radius = Double.parseDouble(args[2]);
}
catch (NumberFormatException nfex)
{
playerMsg("Invalid radius.");
return true;
}
if (radius > ProtectArea.MAX_RADIUS || radius < 0.0D)
{
playerMsg("Invalid radius. Radius must be a positive value less than " + ProtectArea.MAX_RADIUS + ".");
return true;
}
plugin.pa.addProtectedArea(args[1], playerSender.getLocation(), radius);
playerMsg("Area added. Protected Areas: " + StringUtils.join(plugin.pa.getProtectedAreaLabels(), ", "));
}
else
{
return false;
}
return true;
}
else
{
return false;
}
}
}