Cache the name for getDisguisePerm

This commit is contained in:
libraryaddict 2023-11-01 15:33:22 +13:00
parent beb3fec8ab
commit 73eacb41f6
2 changed files with 15 additions and 3 deletions

View File

@ -361,15 +361,17 @@ public class DisguiseParser {
}
public static DisguisePerm getDisguisePerm(String name) {
name = name.replaceAll("[ |_]", "").toLowerCase();
for (DisguisePerm perm : getDisguisePerms()) {
if (!perm.toReadable().replaceAll("[ |_]", "").equalsIgnoreCase(name.replaceAll("[ |_]", ""))) {
if (!perm.getRegexedName().equals(name)) {
continue;
}
return perm;
}
if (name.equalsIgnoreCase("p")) {
if (name.equals("p")) {
return getDisguisePerm(DisguiseType.PLAYER.toReadable());
}

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities.parser;
import lombok.Getter;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import org.bukkit.entity.EntityType;
@ -12,14 +13,23 @@ import java.util.Objects;
public class DisguisePerm {
private final DisguiseType disguiseType;
private String permName;
@Getter
private String regexedName;
private boolean customDisguise;
private DisguisePerm() {
regexedName = toReadable().replaceAll("[ |_]", "").toLowerCase();
}
public DisguisePerm(DisguiseType disguiseType) {
this();
this.disguiseType = disguiseType;
}
public DisguisePerm(DisguiseType disguiseType, String disguisePerm) {
this.disguiseType = disguiseType;
this(disguiseType);
permName = disguisePerm;
customDisguise = true;
}