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:
parent
76e3f5b3c8
commit
0c51af6b45
|
@ -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) {
|
||||
|
|
|
@ -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++) {
|
||||
|
|
Loading…
Reference in New Issue