Allow use of multiple blocks in /ro. Closes #87

This commit is contained in:
unknown 2014-04-23 17:00:44 +02:00
parent 802d02d653
commit 518537413b
2 changed files with 45 additions and 19 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Wed Apr 23 16:35:40 CEST 2014 #Wed Apr 23 16:58:03 CEST 2014
build.number=794 build.number=795

View File

@ -1,6 +1,9 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -19,22 +22,32 @@ public class Command_ro extends TFM_Command
return false; return false;
} }
Material from_material = Material.matchMaterial(args[0]); final List<Material> materials = new ArrayList<Material>();
if (from_material == null)
for (String materialName : (args[0].contains(",") ? args[0].split(",") : new String[]
{
args[0]
}))
{
Material fromMaterial = Material.matchMaterial(materialName);
if (fromMaterial == null)
{ {
try try
{ {
from_material = Material.getMaterial(Integer.parseInt(args[0])); fromMaterial = Material.getMaterial(Integer.parseInt(materialName));
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
} }
}
if (from_material == null) if (fromMaterial == null)
{ {
playerMsg("Invalid block: " + args[0], ChatColor.RED); playerMsg("Invalid block: " + materialName, ChatColor.RED);
return true; return true;
} }
materials.add(fromMaterial);
} }
int radius = 20; int radius = 20;
@ -51,7 +64,7 @@ public class Command_ro extends TFM_Command
} }
} }
Player targetPlayer = null; final Player targetPlayer;
if (args.length == 3) if (args.length == 3)
{ {
try try
@ -64,24 +77,37 @@ public class Command_ro extends TFM_Command
return true; return true;
} }
} }
else
{
targetPlayer = null;
}
final String names = StringUtils.join(materials, ", ");
int affected = 0; int affected = 0;
if (targetPlayer == null) if (targetPlayer == null)
{ {
TFM_Util.adminAction(sender.getName(), "Removing all " + from_material.name() + " within " + radius + " blocks of all players. Brace for lag...", senderIsConsole); TFM_Util.adminAction(sender.getName(), "Removing all " + names + " within " + radius + " blocks of all players... Brace for lag!", false);
for (Material material : materials)
{
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
affected += TFM_Util.replaceBlocks(player.getLocation(), from_material, Material.AIR, radius); affected += TFM_Util.replaceBlocks(player.getLocation(), material, Material.AIR, radius);
}
} }
} }
else else
{ {
TFM_Util.adminAction(sender.getName(), "Removing all " + from_material.name() + " within " + radius + " blocks of " + targetPlayer.getName() + ".", senderIsConsole); for (Material material : materials)
affected += TFM_Util.replaceBlocks(targetPlayer.getLocation(), from_material, Material.AIR, radius); {
TFM_Util.adminAction(sender.getName(), "Removing all " + names + " within " + radius + " blocks of " + targetPlayer.getName(), false);
affected += TFM_Util.replaceBlocks(targetPlayer.getLocation(), material, Material.AIR, radius);
}
} }
TFM_Util.adminAction(sender.getName(), "Remove complete. " + affected + " blocks removed.", senderIsConsole); TFM_Util.adminAction(sender.getName(), "Remove complete! " + affected + " blocks removed.", false);
return true; return true;
} }