mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-06 19:09:31 +01:00
Use faster wildcard parsing method
This commit is contained in:
parent
51732fa660
commit
4874f9d051
@ -26,27 +26,32 @@ import me.lucko.luckperms.api.Tristate;
|
|||||||
import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class WildcardProcessor implements PermissionProcessor {
|
public class WildcardProcessor implements PermissionProcessor {
|
||||||
|
private static final Pattern SPLIT = Pattern.compile("\\.");
|
||||||
private Map<String, Boolean> map = null;
|
private Map<String, Boolean> map = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate hasPermission(String permission) {
|
public Tristate hasPermission(String s) {
|
||||||
String node = permission;
|
if (s.startsWith(".") || !s.contains(".")) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
String[] parts = SPLIT.split(s);
|
||||||
int endIndex = node.lastIndexOf('.');
|
StringBuilder sb = new StringBuilder();
|
||||||
if (endIndex == -1) {
|
|
||||||
break;
|
for (int i = parts.length - 2; i >= 0; i--) {
|
||||||
|
for (int i1 = 0; i1 <= i; i1++) {
|
||||||
|
sb.append(parts[i1]).append(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
node = node.substring(0, endIndex);
|
Boolean b = map.get(sb.append("*").toString());
|
||||||
if (!node.isEmpty()) {
|
if (b != null) {
|
||||||
Boolean b = map.get(node + ".*");
|
return Tristate.fromBoolean(b);
|
||||||
if (b != null) {
|
|
||||||
return Tristate.fromBoolean(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.setLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean b = map.get("'*'");
|
Boolean b = map.get("'*'");
|
||||||
|
@ -70,6 +70,7 @@ import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
|
|||||||
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
||||||
import org.spongepowered.api.plugin.Dependency;
|
import org.spongepowered.api.plugin.Dependency;
|
||||||
import org.spongepowered.api.plugin.Plugin;
|
import org.spongepowered.api.plugin.Plugin;
|
||||||
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.scheduler.AsynchronousExecutor;
|
import org.spongepowered.api.scheduler.AsynchronousExecutor;
|
||||||
import org.spongepowered.api.scheduler.Scheduler;
|
import org.spongepowered.api.scheduler.Scheduler;
|
||||||
import org.spongepowered.api.scheduler.SpongeExecutorService;
|
import org.spongepowered.api.scheduler.SpongeExecutorService;
|
||||||
@ -365,7 +366,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getPlugin(String name) {
|
public Object getPlugin(String name) {
|
||||||
return game.getPluginManager().getPlugin(name).get().getInstance().get();
|
return game.getPluginManager().getPlugin(name).map(PluginContainer::getInstance).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -375,11 +376,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(String playerName) {
|
public UUID getUUID(String playerName) {
|
||||||
try {
|
return game.getServer().getPlayer(playerName).map(Player::getUniqueId).orElse(null);
|
||||||
return game.getServer().getPlayer(playerName).get().getUniqueId();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,27 +26,32 @@ import me.lucko.luckperms.api.Tristate;
|
|||||||
import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class SpongeWildcardProcessor implements PermissionProcessor {
|
public class SpongeWildcardProcessor implements PermissionProcessor {
|
||||||
|
private static final Pattern SPLIT = Pattern.compile("\\.");
|
||||||
private Map<String, Boolean> map = null;
|
private Map<String, Boolean> map = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate hasPermission(String permission) {
|
public Tristate hasPermission(String s) {
|
||||||
String node = permission;
|
if (s.startsWith(".") || !s.contains(".")) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
String[] parts = SPLIT.split(s);
|
||||||
int endIndex = node.lastIndexOf('.');
|
StringBuilder sb = new StringBuilder();
|
||||||
if (endIndex == -1) {
|
|
||||||
break;
|
for (int i = parts.length - 2; i >= 0; i--) {
|
||||||
|
for (int i1 = 0; i1 <= i; i1++) {
|
||||||
|
sb.append(parts[i1]).append(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
node = node.substring(0, endIndex);
|
Boolean b = map.get(sb.deleteCharAt(sb.length() - 1).toString());
|
||||||
if (!node.isEmpty()) {
|
if (b != null) {
|
||||||
Boolean b = map.get(node);
|
return Tristate.fromBoolean(b);
|
||||||
if (b != null) {
|
|
||||||
return Tristate.fromBoolean(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.setLength(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Tristate.UNDEFINED;
|
return Tristate.UNDEFINED;
|
||||||
|
Loading…
Reference in New Issue
Block a user