Skip to content

Commit

Permalink
Simplified tag handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed May 13, 2024
1 parent 5bc28b3 commit 5859958
Showing 1 changed file with 49 additions and 40 deletions.
89 changes: 49 additions & 40 deletions src/main/java/net/coreprotect/command/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;

Expand Down Expand Up @@ -34,8 +35,6 @@
public class CommandHandler implements CommandExecutor {
private static CommandHandler instance;
private static ConcurrentHashMap<String, Boolean> versionAlert = new ConcurrentHashMap<>();
protected static Set<Material> naturalBlocks = BlockGroup.NATURAL_BLOCKS;
protected static Set<Material> shulkerBlocks = BlockGroup.SHULKER_BOXES;

public static CommandHandler getInstance() {
if (instance == null) {
Expand Down Expand Up @@ -278,17 +277,7 @@ else if (next == 5 || argument.startsWith("e:") || argument.startsWith("exclude:
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);
Expand All @@ -312,17 +301,7 @@ else if (i3_material != null) {
}
}
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);
Expand Down Expand Up @@ -370,7 +349,7 @@ else if (next == 5 || argument.startsWith("e:") || argument.startsWith("exclude:
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 {
Expand Down Expand Up @@ -398,7 +377,7 @@ else if (next == 5 || argument.startsWith("e:") || argument.startsWith("exclude:
}
else {
boolean isBlock = false;
if (argument.equals("#natural") || argument.equals("#shulker_box")) {
if (checkTags(argument)) {
isBlock = true;
}
else {
Expand Down Expand Up @@ -641,13 +620,7 @@ else if (next == 4 || argument.startsWith("i:") || argument.startsWith("include:
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);
Expand Down Expand Up @@ -676,13 +649,7 @@ else if (i3_material != null) {
}
}
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);
Expand Down Expand Up @@ -1154,6 +1121,48 @@ else if (argument.startsWith("#")) {
return worldName;
}

private static Map<String, Set<Material>> getTags() {
Map<String, Set<Material>> 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<Object, Boolean> list) {
for (Entry<String, Set<Material>> entry : getTags().entrySet()) {
String tag = entry.getKey();
Set<Material> 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<Object> list) {
for (Entry<String, Set<Material>> entry : getTags().entrySet()) {
String tag = entry.getKey();
Set<Material> materials = entry.getValue();

if (argument.equals(tag)) {
list.addAll(materials);
return true;
}
}

return false;
}

private static void validUserCheck(List<String> users, String user) {
List<String> badUsers = Arrays.asList("n", "noisy", "v", "verbose", "#v", "#verbose", "#silent", "#preview", "#preview_cancel", "#count", "#sum");
String check = user.replaceAll("[\\s'\"]", "");
Expand Down

0 comments on commit 5859958

Please sign in to comment.