mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-18 02:51:19 +01:00
Fix shortened item aliases not working (Fixes #425)
This commit is contained in:
parent
a3c5ec618a
commit
b93361cd07
@ -15,6 +15,7 @@ import org.bukkit.event.Listener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
@ -69,6 +70,31 @@ public class ItemAliasModule implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
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("[ _]");
|
||||
int length = Short.MAX_VALUE;
|
||||
for (Map.Entry<String, String> entry : aliases.entrySet()) {
|
||||
if (entry.getValue().length() < length && entry.getValue().startsWith(event.getItemString())) {
|
||||
length = (short) entry.getValue().length();
|
||||
code = entry.getKey();
|
||||
} else if (typeParts.length > 1) {
|
||||
String[] nameParts = entry.getValue().split("[ _]");
|
||||
if (typeParts.length == nameParts.length) {
|
||||
boolean matched = true;
|
||||
for (int i = 0; i < nameParts.length; i++) {
|
||||
if (!nameParts[i].startsWith(typeParts[i])) {
|
||||
matched = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (matched) {
|
||||
code = entry.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (code != null) {
|
||||
event.setItem(MaterialUtil.getItem(code));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user