mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-10-31 23:59:37 +01:00
Fix issues with spaces in shortened item names
This commit is contained in:
parent
d426492561
commit
17bd2a1fcb
@ -182,7 +182,7 @@ public class MaterialUtil {
|
||||
replacedName = replacedName.replaceAll(entry.getValue() + "(_|$)?", entry.getKey() + "$1");
|
||||
}
|
||||
|
||||
String formatted = name.replaceAll("(?<!^)([A-Z1-9])", "_$1").replace(' ', '_').toUpperCase(Locale.ROOT);
|
||||
String formatted = name.replaceAll("(?<!^)(?>\\s?)([A-Z1-9])", "_$1").replace(' ', '_').toUpperCase(Locale.ROOT);
|
||||
|
||||
Material material = MATERIAL_CACHE.get(formatted);
|
||||
if (material != null) {
|
||||
@ -467,7 +467,7 @@ public class MaterialUtil {
|
||||
return E.valueOf(values[0].getDeclaringClass(), name.toUpperCase(Locale.ROOT));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
E currentEnum = null;
|
||||
String[] typeParts = name.replaceAll("(?<!^)([A-Z1-9])", "_$1").toUpperCase(Locale.ROOT).split("[ _]");
|
||||
String[] typeParts = name.replaceAll("(?<!^)(?>\\s?)([A-Z1-9])", "_$1").toUpperCase(Locale.ROOT).split("[ _]");
|
||||
int length = Short.MAX_VALUE;
|
||||
name = name.toUpperCase(Locale.ROOT);
|
||||
for (E e : values) {
|
||||
|
@ -8,6 +8,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@ -49,4 +50,12 @@ public class MaterialTest {
|
||||
assertSame(shortenedName + " did not produce " + material, material, MaterialUtil.getMaterial(shortenedName));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCodesWithAndWithoutSpace() {
|
||||
assertNotNull(MaterialUtil.getMaterial("DiamonPicka"));
|
||||
assertNotNull(MaterialUtil.getMaterial("Diamon Picka"));
|
||||
assertNotNull(MaterialUtil.getMaterial("ExpBottle"));
|
||||
assertNotNull(MaterialUtil.getMaterial("Exp Bottle"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user