summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-08-29 19:26:58 +1000
committermd_5 <git@md-5.net>2018-08-29 19:26:58 +1000
commit3d50da5752316cd9a6de6869d707ef5c247d82c3 (patch)
treec9ba564884c81cd987290830232483bc675df9af /src/main
parent9ca2772d4f0b92029844ee0a1bf69ba1d6e73366 (diff)
downloadbukkit-3d50da5752316cd9a6de6869d707ef5c247d82c3.tar
bukkit-3d50da5752316cd9a6de6869d707ef5c247d82c3.tar.gz
bukkit-3d50da5752316cd9a6de6869d707ef5c247d82c3.tar.lz
bukkit-3d50da5752316cd9a6de6869d707ef5c247d82c3.tar.xz
bukkit-3d50da5752316cd9a6de6869d707ef5c247d82c3.zip
Make matchMaterial accept the minecraft: namespace
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/Material.java19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
index 90a01e03..83f8eca1 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -2781,9 +2781,9 @@ public enum Material implements Keyed {
/**
* Attempts to match the Material with the given name.
* <p>
- * This is a match lookup; names will be converted to uppercase, then
- * stripped of special characters in an attempt to format it like the
- * enum.
+ * This is a match lookup; names will be stripped of the "minecraft:"
+ * namespace, converted to uppercase, then stripped of special characters in
+ * an attempt to format it like the enum.
*
* @param name Name of the material to get
* @return Material if found, or null
@@ -2795,9 +2795,9 @@ public enum Material implements Keyed {
/**
* Attempts to match the Material with the given name.
* <p>
- * This is a match lookup; names will be converted to uppercase, then
- * stripped of special characters in an attempt to format it like the
- * enum.
+ * This is a match lookup; names will be stripped of the "minecraft:"
+ * namespace, converted to uppercase, then stripped of special characters in
+ * an attempt to format it like the enum.
*
* @param name Name of the material to get
* @param legacyName whether this is a legacy name
@@ -2806,7 +2806,12 @@ public enum Material implements Keyed {
public static Material matchMaterial(final String name, boolean legacyName) {
Validate.notNull(name, "Name cannot be null");
- String filtered = name.toUpperCase(java.util.Locale.ENGLISH);
+ String filtered = name;
+ if (filtered.startsWith(NamespacedKey.MINECRAFT + ":")) {
+ filtered = filtered.substring((NamespacedKey.MINECRAFT + ":").length());
+ }
+
+ filtered = filtered.toUpperCase(java.util.Locale.ENGLISH);
filtered = filtered.replaceAll("\\s+", "_").replaceAll("\\W", "");
return getMaterial(filtered, legacyName);