mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-24 12:16:36 +01:00
Simplified tag handling
This commit is contained in:
parent
5bc28b3e05
commit
5859958ec2
@ -7,6 +7,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -34,8 +35,6 @@ import net.coreprotect.utility.Util;
|
|||||||
public class CommandHandler implements CommandExecutor {
|
public class CommandHandler implements CommandExecutor {
|
||||||
private static CommandHandler instance;
|
private static CommandHandler instance;
|
||||||
private static ConcurrentHashMap<String, Boolean> versionAlert = new ConcurrentHashMap<>();
|
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() {
|
public static CommandHandler getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@ -278,17 +277,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
if (argument.contains(",")) {
|
if (argument.contains(",")) {
|
||||||
String[] i2 = argument.split(",");
|
String[] i2 = argument.split(",");
|
||||||
for (String i3 : i2) {
|
for (String i3 : i2) {
|
||||||
if (i3.equals("#natural")) {
|
if (!checkTags(i3, excluded)) {
|
||||||
for (Material block : naturalBlocks) {
|
|
||||||
excluded.put(block, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (i3.equals("#shulker_box")) {
|
|
||||||
for (Material block : shulkerBlocks) {
|
|
||||||
excluded.put(block, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Material i3_material = Util.getType(i3);
|
Material i3_material = Util.getType(i3);
|
||||||
if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) {
|
if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) {
|
||||||
excluded.put(i3_material, false);
|
excluded.put(i3_material, false);
|
||||||
@ -312,17 +301,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (argument.equals("#natural")) {
|
if (!checkTags(argument, excluded)) {
|
||||||
for (Material block : naturalBlocks) {
|
|
||||||
excluded.put(block, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (argument.equals("#shulker_box")) {
|
|
||||||
for (Material block : shulkerBlocks) {
|
|
||||||
excluded.put(block, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Material iMaterial = Util.getType(argument);
|
Material iMaterial = Util.getType(argument);
|
||||||
if (iMaterial != null && (iMaterial.isBlock() || argAction.contains(4))) {
|
if (iMaterial != null && (iMaterial.isBlock() || argAction.contains(4))) {
|
||||||
excluded.put(iMaterial, false);
|
excluded.put(iMaterial, false);
|
||||||
@ -370,7 +349,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
String[] i2 = argument.split(",");
|
String[] i2 = argument.split(",");
|
||||||
for (String i3 : i2) {
|
for (String i3 : i2) {
|
||||||
boolean isBlock = false;
|
boolean isBlock = false;
|
||||||
if (i3.equals("#natural") || i3.equals("#shulker_box")) {
|
if (checkTags(i3)) {
|
||||||
isBlock = true;
|
isBlock = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -398,7 +377,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
boolean isBlock = false;
|
boolean isBlock = false;
|
||||||
if (argument.equals("#natural") || argument.equals("#shulker_box")) {
|
if (checkTags(argument)) {
|
||||||
isBlock = true;
|
isBlock = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -641,13 +620,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
if (argument.contains(",")) {
|
if (argument.contains(",")) {
|
||||||
String[] i2 = argument.split(",");
|
String[] i2 = argument.split(",");
|
||||||
for (String i3 : i2) {
|
for (String i3 : i2) {
|
||||||
if (i3.equals("#natural")) {
|
if (!checkTags(argument, restricted)) {
|
||||||
restricted.addAll(naturalBlocks);
|
|
||||||
}
|
|
||||||
else if (i3.equals("#shulker_box")) {
|
|
||||||
restricted.addAll(shulkerBlocks);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Material i3_material = Util.getType(i3);
|
Material i3_material = Util.getType(i3);
|
||||||
if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) {
|
if (i3_material != null && (i3_material.isBlock() || argAction.contains(4))) {
|
||||||
restricted.add(i3_material);
|
restricted.add(i3_material);
|
||||||
@ -676,13 +649,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (argument.equals("#natural")) {
|
if (!checkTags(argument, restricted)) {
|
||||||
restricted.addAll(naturalBlocks);
|
|
||||||
}
|
|
||||||
else if (argument.equals("#shulker_box")) {
|
|
||||||
restricted.addAll(shulkerBlocks);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Material material = Util.getType(argument);
|
Material material = Util.getType(argument);
|
||||||
if (material != null && (material.isBlock() || argAction.contains(4))) {
|
if (material != null && (material.isBlock() || argAction.contains(4))) {
|
||||||
restricted.add(material);
|
restricted.add(material);
|
||||||
@ -1154,6 +1121,48 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
return worldName;
|
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) {
|
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");
|
List<String> badUsers = Arrays.asList("n", "noisy", "v", "verbose", "#v", "#verbose", "#silent", "#preview", "#preview_cancel", "#count", "#sum");
|
||||||
String check = user.replaceAll("[\\s'\"]", "");
|
String check = user.replaceAll("[\\s'\"]", "");
|
||||||
|
Loading…
Reference in New Issue
Block a user