diff --git a/src/main/java/net/coreprotect/command/CommandHandler.java b/src/main/java/net/coreprotect/command/CommandHandler.java index 923d0ac..7876adb 100755 --- a/src/main/java/net/coreprotect/command/CommandHandler.java +++ b/src/main/java/net/coreprotect/command/CommandHandler.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -34,8 +35,6 @@ import net.coreprotect.utility.Util; public class CommandHandler implements CommandExecutor { private static CommandHandler instance; private static ConcurrentHashMap versionAlert = new ConcurrentHashMap<>(); - protected static Set naturalBlocks = BlockGroup.NATURAL_BLOCKS; - protected static Set shulkerBlocks = BlockGroup.SHULKER_BOXES; public static CommandHandler getInstance() { if (instance == null) { @@ -278,17 +277,7 @@ public class CommandHandler implements CommandExecutor { if (argument.contains(",")) { String[] i2 = argument.split(","); for (String i3 : i2) { - if (i3.equals("#natural")) { - for (Material block : naturalBlocks) { - excluded.put(block, false); - } - } - else if (i3.equals("#shulker_box")) { - for (Material block : shulkerBlocks) { - excluded.put(block, false); - } - } - else { + if (!checkTags(i3, excluded)) { Material i3_material = Util.getType(i3); if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) { excluded.put(i3_material, false); @@ -312,17 +301,7 @@ public class CommandHandler implements CommandExecutor { } } else { - if (argument.equals("#natural")) { - for (Material block : naturalBlocks) { - excluded.put(block, false); - } - } - else if (argument.equals("#shulker_box")) { - for (Material block : shulkerBlocks) { - excluded.put(block, false); - } - } - else { + if (!checkTags(argument, excluded)) { Material iMaterial = Util.getType(argument); if (iMaterial != null && (iMaterial.isBlock() || argAction.contains(4))) { excluded.put(iMaterial, false); @@ -370,7 +349,7 @@ public class CommandHandler implements CommandExecutor { String[] i2 = argument.split(","); for (String i3 : i2) { boolean isBlock = false; - if (i3.equals("#natural") || i3.equals("#shulker_box")) { + if (checkTags(i3)) { isBlock = true; } else { @@ -398,7 +377,7 @@ public class CommandHandler implements CommandExecutor { } else { boolean isBlock = false; - if (argument.equals("#natural") || argument.equals("#shulker_box")) { + if (checkTags(argument)) { isBlock = true; } else { @@ -641,13 +620,7 @@ public class CommandHandler implements CommandExecutor { if (argument.contains(",")) { String[] i2 = argument.split(","); for (String i3 : i2) { - if (i3.equals("#natural")) { - restricted.addAll(naturalBlocks); - } - else if (i3.equals("#shulker_box")) { - restricted.addAll(shulkerBlocks); - } - else { + if (!checkTags(argument, restricted)) { Material i3_material = Util.getType(i3); if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) { restricted.add(i3_material); @@ -676,13 +649,7 @@ public class CommandHandler implements CommandExecutor { } } else { - if (argument.equals("#natural")) { - restricted.addAll(naturalBlocks); - } - else if (argument.equals("#shulker_box")) { - restricted.addAll(shulkerBlocks); - } - else { + if (!checkTags(argument, restricted)) { Material material = Util.getType(argument); if (material != null && (material.isBlock() || argAction.contains(4))) { restricted.add(material); @@ -1154,6 +1121,48 @@ public class CommandHandler implements CommandExecutor { return worldName; } + private static Map> getTags() { + Map> tagMap = new HashMap<>(); + tagMap.put("#natural", BlockGroup.NATURAL_BLOCKS); + tagMap.put("#shulker_box", BlockGroup.SHULKER_BOXES); + return tagMap; + } + + protected static boolean checkTags(String argument) { + return getTags().containsKey(argument); + } + + protected static boolean checkTags(String argument, Map list) { + for (Entry> entry : getTags().entrySet()) { + String tag = entry.getKey(); + Set materials = entry.getValue(); + + if (argument.equals(tag)) { + for (Material block : materials) { + list.put(block, false); + } + + return true; + } + } + + return false; + } + + protected static boolean checkTags(String argument, List list) { + for (Entry> entry : getTags().entrySet()) { + String tag = entry.getKey(); + Set materials = entry.getValue(); + + if (argument.equals(tag)) { + list.addAll(materials); + return true; + } + } + + return false; + } + private static void validUserCheck(List users, String user) { List badUsers = Arrays.asList("n", "noisy", "v", "verbose", "#v", "#verbose", "#silent", "#preview", "#preview_cancel", "#count", "#sum"); String check = user.replaceAll("[\\s'\"]", "");