From 4d0499a61ea0d01f3d30bab06da6f89d2e26f0a0 Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 30 Mar 2017 18:34:45 +0100 Subject: [PATCH] Avoid parsing UUID in sponge world calculator --- .../luckperms/sponge/LPSpongePlugin.java | 2 +- .../sponge/contexts/WorldCalculator.java | 26 +++++++------------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index bf86b2f0..9c85f304 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -265,7 +265,7 @@ public class LPSpongePlugin implements LuckPermsPlugin { contextManager = new ContextManager<>(); contextManager.registerCalculator(new ServerCalculator<>(configuration)); - contextManager.registerCalculator(new WorldCalculator(this)); + contextManager.registerCalculator(new WorldCalculator()); // register the PermissionService with Sponge getLog().info("Registering PermissionService..."); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java index a3910f45..d4f75be4 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/WorldCalculator.java @@ -26,46 +26,38 @@ import lombok.RequiredArgsConstructor; import me.lucko.luckperms.api.context.ContextCalculator; 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.service.context.Context; import org.spongepowered.api.service.permission.Subject; import java.util.Map; -import java.util.Optional; -import java.util.UUID; @RequiredArgsConstructor public class WorldCalculator implements ContextCalculator { - private final LPSpongePlugin plugin; @Override public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) { - UUID uuid = Util.parseUuid(subject.getIdentifier()); - if (uuid == null) { + CommandSource source = subject.getCommandSource().orElse(null); + if (source == null || !(source instanceof Player)) { return accumulator; } - Optional p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(uuid)); - if (!p.isPresent()) { - return accumulator; - } - - accumulator.add(Context.WORLD_KEY, p.get().getWorld().getName()); + Player p = ((Player) source); + accumulator.add(Context.WORLD_KEY, p.getWorld().getName()); return accumulator; } @Override public boolean isContextApplicable(Subject subject, Map.Entry context) { - UUID uuid = Util.parseUuid(subject.getIdentifier()); - if (uuid == null) { + CommandSource source = subject.getCommandSource().orElse(null); + if (source == null || !(source instanceof Player)) { return false; } - Optional p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(uuid)); - return p.map(player -> context.getKey().equals(Context.WORLD_KEY) && player.getWorld().getName().equals(context.getValue())).orElse(false); + Player p = ((Player) source); + return context.getKey().equals(Context.WORLD_KEY) && p.getWorld().getName().equals(context.getValue()); } }