mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 19:46:32 +01:00
Avoid parsing UUID in sponge world calculator
This commit is contained in:
parent
ae82807139
commit
4d0499a61e
@ -265,7 +265,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
contextManager = new ContextManager<>();
|
contextManager = new ContextManager<>();
|
||||||
contextManager.registerCalculator(new ServerCalculator<>(configuration));
|
contextManager.registerCalculator(new ServerCalculator<>(configuration));
|
||||||
contextManager.registerCalculator(new WorldCalculator(this));
|
contextManager.registerCalculator(new WorldCalculator());
|
||||||
|
|
||||||
// register the PermissionService with Sponge
|
// register the PermissionService with Sponge
|
||||||
getLog().info("Registering PermissionService...");
|
getLog().info("Registering PermissionService...");
|
||||||
|
@ -26,46 +26,38 @@ import lombok.RequiredArgsConstructor;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
import me.lucko.luckperms.common.commands.utils.Util;
|
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
|
||||||
|
|
||||||
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WorldCalculator implements ContextCalculator<Subject> {
|
public class WorldCalculator implements ContextCalculator<Subject> {
|
||||||
private final LPSpongePlugin plugin;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
||||||
UUID uuid = Util.parseUuid(subject.getIdentifier());
|
CommandSource source = subject.getCommandSource().orElse(null);
|
||||||
if (uuid == null) {
|
if (source == null || !(source instanceof Player)) {
|
||||||
return accumulator;
|
return accumulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Player> p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(uuid));
|
Player p = ((Player) source);
|
||||||
if (!p.isPresent()) {
|
accumulator.add(Context.WORLD_KEY, p.getWorld().getName());
|
||||||
return accumulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
accumulator.add(Context.WORLD_KEY, p.get().getWorld().getName());
|
|
||||||
return accumulator;
|
return accumulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isContextApplicable(Subject subject, Map.Entry<String, String> context) {
|
public boolean isContextApplicable(Subject subject, Map.Entry<String, String> context) {
|
||||||
UUID uuid = Util.parseUuid(subject.getIdentifier());
|
CommandSource source = subject.getCommandSource().orElse(null);
|
||||||
if (uuid == null) {
|
if (source == null || !(source instanceof Player)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Player> p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(uuid));
|
Player p = ((Player) source);
|
||||||
return p.map(player -> context.getKey().equals(Context.WORLD_KEY) && player.getWorld().getName().equals(context.getValue())).orElse(false);
|
return context.getKey().equals(Context.WORLD_KEY) && p.getWorld().getName().equals(context.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user