@@ -44,7 +44,7 @@ public static Set<Material> getMaterials(Set<String> inputSet) {
44
44
* This method returns a list of materials based on the input string. Various formats
45
45
* of material specifications are supported here:
46
46
*
47
- * <li>Material-Tag via "tag=" (see <a href="https://jd.papermc.io/paper/1.21.1/org/bukkit/Tag.html">PaperMC Java-Doc</a> and
47
+ * <li>Material-Tag starting with "#" or "tag=" (see <a href="https://jd.papermc.io/paper/1.21.1/org/bukkit/Tag.html">PaperMC Java-Doc</a> and
48
48
* <a href="https://minecraft.wiki/w/Tag">Minecraft-Wiki</a> for the tag lists)</li>
49
49
* <li>Regex via "r="</li>
50
50
* <li>MATERIAL names with wildcards via "*"</li>
@@ -63,17 +63,30 @@ public static Set<Material> getMaterials(String input) {
63
63
// Material-Tag Definition:
64
64
// - https://jd.papermc.io/paper/1.21/org/bukkit/Tag.html
65
65
// - https://minecraft.wiki/w/Tag
66
- if (input .startsWith ("tag=" )) {
67
- String nameSpace = NamespacedKey .MINECRAFT ;
68
- String tagName = input .substring (4 ).toLowerCase ();
66
+ if ((input .startsWith ("#" )) || (input .startsWith ("tag=" ))) {
67
+ String nameSpace = "" ;
68
+ String tagName = "" ;
69
+
70
+ if (input .startsWith ("#" )) {
71
+ tagName = input .substring (1 ).toLowerCase ();
72
+ } else if (input .startsWith ("tag=" )) {
73
+ tagName = input .substring (4 ).toLowerCase ();
74
+ }
75
+
69
76
String [] parts = tagName .split (":" );
70
- if (parts .length == 2 ) {
77
+ if (parts .length == 1 ) {
78
+ nameSpace = NamespacedKey .MINECRAFT ;
79
+ tagName = parts [0 ].toLowerCase ();
80
+ } else if (parts .length == 2 ) {
71
81
nameSpace = parts [0 ].toLowerCase ();
72
82
tagName = parts [1 ].toLowerCase ();
73
83
}
74
84
85
+ Tag <Material > tag ;
86
+
75
87
// Blocks:
76
- Tag <Material > tag = Bukkit .getTag (Tag .REGISTRY_BLOCKS , new NamespacedKey (nameSpace , tagName ), Material .class );
88
+ tag = Bukkit .getTag (Tag .REGISTRY_BLOCKS , new NamespacedKey (nameSpace , tagName ), Material .class );
89
+
77
90
// Items:
78
91
if (tag == null ) {
79
92
tag = Bukkit .getTag (Tag .REGISTRY_ITEMS , new NamespacedKey (nameSpace , tagName ), Material .class );
@@ -96,6 +109,7 @@ public static Set<Material> getMaterials(String input) {
96
109
// Regex Definition:
97
110
} else if (input .startsWith ("r=" ) || input .contains ("*" )) {
98
111
Pattern p = Pattern .compile (input .startsWith ("r=" ) ? input .substring (2 ) : input .replace ("*" , "(.*)" ));
112
+
99
113
for (Material material : Material .values ()) {
100
114
if (p .matcher (material .name ()).matches ()) {
101
115
materials .add (material );
0 commit comments