Further improve item name shortening for alias system (#425)

This will correctly shorten dashes and ignore the case when comparing
 name starts
This commit is contained in:
Phoenix616 2021-03-27 21:07:18 +01:00
parent 76e3f5b3c8
commit 0c51af6b45
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
2 changed files with 4 additions and 4 deletions

View File

@ -252,7 +252,7 @@ public class MaterialUtil {
if (width <= maxWidth) {
return itemName;
}
String[] itemParts = itemName.split(" ");
String[] itemParts = itemName.split("[ \\-]");
itemName = String.join("", itemParts);
width = getMinecraftStringWidth(itemName);
if (width <= maxWidth) {

View File

@ -71,14 +71,14 @@ public class ItemAliasModule implements Listener {
public void onItemParse(ItemParseEvent event) {
String code = aliases.inverse().get(event.getItemString());
if (code == null) {
String[] typeParts = event.getItemString().replaceAll("(?<!^)([A-Z1-9])", "_$1").toUpperCase(Locale.ROOT).split("[ _]");
String[] typeParts = event.getItemString().replaceAll("(?<!^)([A-Z1-9])", "_$1").toUpperCase(Locale.ROOT).split("[ _\\-]");
int length = Short.MAX_VALUE;
for (Map.Entry<String, String> entry : aliases.entrySet()) {
if (entry.getValue().length() < length && entry.getValue().startsWith(event.getItemString())) {
if (entry.getValue().length() < length && entry.getValue().toUpperCase(Locale.ROOT).startsWith(event.getItemString().toUpperCase(Locale.ROOT))) {
length = (short) entry.getValue().length();
code = entry.getKey();
} else if (typeParts.length > 1) {
String[] nameParts = entry.getValue().toUpperCase(Locale.ROOT).split("[ _]");
String[] nameParts = entry.getValue().toUpperCase(Locale.ROOT).split("[ _\\-]");
if (typeParts.length == nameParts.length) {
boolean matched = true;
for (int i = 0; i < nameParts.length; i++) {