Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class PluginConfig implements ChatSettings, TemplateRepository {
})
public String defaultFormat = "{displayname} » {message}";
@Description({ " ", "# Here you can set different formats for each rank.",
"# Remember! Rank name must be exactly the same as in you permission plugin configuration.",
"# Note: Rank name matching is case-insensitive (Elite, elite, ELITE will all match).",
"# If player have more than one rank remember to correctly setup rank weight configuration" })
public Map<String, String> format = new ImmutableMap.Builder<String, String>()
.put("default", "{member} &7$hoverName({displayname}) &8» <gradient:#d4d4d4:white>{message} ")
Expand All @@ -78,20 +78,31 @@ public class PluginConfig implements ChatSettings, TemplateRepository {
.put("{privateMessage}", "<gradient:#36ff39:#75ff75><i>Click to send private message</i></gradient>")
.build();

@Description({ " ", "# This section is made for experienced users" , "# It is used to shorten the text even more and keep the clean file!" })
@Description({ " ", "# This section is made for experienced users", "# It is used to shorten the text even more and keep the clean file!" })
public List<Template> templates = new ImmutableList.Builder<Template>()
.add(Template.of("hoverName", List.of("name"), "<hover:show_text:'<dark_gray>Name: <white>$name<br><br>{rankDescription}<br>{joinDate}<br>{health}<br>{lvl}<br><br>{privateMessage}'><click:suggest_command:'/msg {displayname} '>{displayname}</click></hover>"))
.build();


@Override
public boolean isReceiveUpdates() {
return this.receiveUpdates;
}

@Override
public String getRawFormat(String rank) {
return this.format.getOrDefault(rank, this.defaultFormat);
if (rank == null) {
return this.defaultFormat;
}

String normalizedRank = rank.toLowerCase();

for (Map.Entry<String, String> entry : this.format.entrySet()) {
if (entry.getKey().toLowerCase().equals(normalizedRank)) {
return entry.getValue();
}
}

return this.defaultFormat;
}
Comment on lines 92 to 106

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This implementation correctly provides case-insensitive matching, but it introduces a performance regression. The getRawFormat method now iterates through all configured formats for every call, resulting in an O(N) complexity. Since this method is likely called for every chat message, this can impact server performance.

A more efficient approach is to use a case-insensitive map for lookups. You can create a cached map that is built once and then reused for fast lookups.

First, add a transient field for the cache to the PluginConfig class:

private transient java.util.Map<String, String> lowerCaseFormatCache;

Then, update getRawFormat to use this lazy-initialized cache. This will build the cache on the first call and provide fast lookups for all subsequent calls.

Note: If your plugin supports configuration hot-reloading, ensure you invalidate this cache (by setting lowerCaseFormatCache = null;) when the configuration is reloaded to prevent serving stale data.

    public String getRawFormat(String rank) {
        if (this.lowerCaseFormatCache == null) {
            this.lowerCaseFormatCache = new java.util.TreeMap<>(String.CASE_INSENSITIVE_ORDER);
            this.lowerCaseFormatCache.putAll(this.format);
        }

        if (rank == null) {
            return this.defaultFormat;
        }

        return this.lowerCaseFormatCache.getOrDefault(rank, this.defaultFormat);
    }


@Override
Expand Down
Loading