diff --git a/api/src/main/java/me/lucko/luckperms/api/Contexts.java b/api/src/main/java/me/lucko/luckperms/api/Contexts.java index 5bf64b77..ae272883 100644 --- a/api/src/main/java/me/lucko/luckperms/api/Contexts.java +++ b/api/src/main/java/me/lucko/luckperms/api/Contexts.java @@ -192,9 +192,7 @@ public class Contexts { if (o == this) return true; if (!(o instanceof Contexts)) return false; final Contexts other = (Contexts) o; - final Object this$context = this.getContexts(); - final Object other$context = other.getContexts(); - return (this$context == null ? other$context == null : this$context.equals(other$context)) && + return (this.getContexts() == null ? other.getContexts() == null : this.getContexts().equals(other.getContexts())) && this.isOp() == other.isOp() && this.isIncludeGlobal() == other.isIncludeGlobal() && this.isIncludeGlobalWorld() == other.isIncludeGlobalWorld() && @@ -212,8 +210,8 @@ public class Contexts { public int hashCode() { final int PRIME = 59; int result = 1; - final Object $context = this.getContexts(); - result = result * PRIME + ($context == null ? 43 : $context.hashCode()); + final Object contexts = this.getContexts(); + result = result * PRIME + (contexts == null ? 43 : contexts.hashCode()); result = result * PRIME + (this.isOp() ? 79 : 97); result = result * PRIME + (this.isIncludeGlobal() ? 79 : 97); result = result * PRIME + (this.isIncludeGlobalWorld() ? 79 : 97); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index b74decb4..a252c92c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -591,16 +591,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { return map; } - @SuppressWarnings("deprecation") - @Override - public UUID getUuidFromUsername(String playerName) { - try { - return getServer().getOfflinePlayer(playerName).getUniqueId(); - } catch (Exception e) { - return null; - } - } - private void registerPermissions(PermissionDefault def) { PluginManager pm = getServer().getPluginManager(); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index 50616c4e..f753bf4e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -41,6 +41,8 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.utils.Predicates; import me.lucko.luckperms.common.utils.ProgressLogger; +import org.bukkit.Bukkit; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Collections; @@ -130,11 +132,16 @@ public class MigrationBPermissions extends SubCommand { AtomicInteger userCount = new AtomicInteger(0); for (Calculable user : world.getAll(CalculableType.USER)) { // There is no mention of UUIDs in the API. I assume that name = uuid. idk? - UUID uuid; + UUID uuid = null; try { uuid = UUID.fromString(user.getName()); } catch (IllegalArgumentException e) { - uuid = plugin.getUuidFromUsername(user.getName()); + try { + //noinspection deprecation + uuid = Bukkit.getOfflinePlayer(user.getName()).getUniqueId(); + } catch (Exception ex) { + e.printStackTrace(); + } } if (uuid == null) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index c7958d80..e949b96b 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -195,7 +195,11 @@ public class MigrationPermissionsEx extends SubCommand { } catch (IllegalArgumentException e) { u = ni.nameToUUID(user.getIdentifier()); if (u == null) { - u = plugin.getUuidFromUsername(user.getIdentifier()); + try { + u = Bukkit.getOfflinePlayer(user.getIdentifier()).getUniqueId(); + } catch (Exception ex) { + e.printStackTrace(); + } } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java index 94abaa49..bd43ae68 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java @@ -23,6 +23,8 @@ package me.lucko.luckperms.bungee; import me.lucko.luckperms.api.Contexts; +import me.lucko.luckperms.api.caching.UserData; +import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.core.UuidCache; @@ -37,6 +39,7 @@ import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.PermissionCheckEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.api.event.ServerConnectEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventPriority; @@ -68,7 +71,8 @@ public class BungeeListener extends AbstractListener implements Listener { return; } - if (user.getUserData() == null) { + UserData userData = user.getUserData(); + if (userData == null) { plugin.getLog().warn("Player " + player.getName() + " does not have any user data setup."); return; } @@ -83,7 +87,7 @@ public class BungeeListener extends AbstractListener implements Listener { false ); - e.setHasPermission(user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission()).asBoolean()); + e.setHasPermission(userData.getPermissionData(contexts).getPermissionValue(e.getPermission()).asBoolean()); } @EventHandler(priority = EventPriority.LOWEST) @@ -163,4 +167,38 @@ public class BungeeListener extends AbstractListener implements Listener { public void onPlayerQuit(PlayerDisconnectEvent e) { onLeave(e.getPlayer().getUniqueId()); } + + // We don't preprocess all servers, so we may have to do it here. + @EventHandler(priority = EventPriority.LOWEST) + public void onServerSwitch(ServerConnectEvent e) { + String serverName = e.getTarget().getName(); + UUID uuid = e.getPlayer().getUniqueId(); + + plugin.doAsync(() -> { + MutableContextSet set = MutableContextSet.create(); + set.add("server", plugin.getConfiguration().get(ConfigKeys.SERVER)); + set.add("world", serverName); + + User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(uuid)); + if (user == null) { + return; + } + UserData userData = user.getUserData(); + if (userData == null) { + return; + } + + Contexts contexts = new Contexts( + set.makeImmutable(), + plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS), + plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS), + true, + plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS), + plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS), + false + ); + + userData.preCalculate(contexts); + }); + } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index f64d22c8..186b70a9 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -28,7 +28,6 @@ import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Logger; import me.lucko.luckperms.api.PlatformType; import me.lucko.luckperms.api.context.ContextSet; -import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.bungee.messaging.BungeeMessagingService; import me.lucko.luckperms.common.api.ApiHandler; import me.lucko.luckperms.common.api.ApiProvider; @@ -67,7 +66,6 @@ import me.lucko.luckperms.common.treeview.PermissionVault; import me.lucko.luckperms.common.utils.BufferedRequest; import me.lucko.luckperms.common.utils.LoggerImpl; -import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Plugin; @@ -329,17 +327,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { Set c = new HashSet<>(); c.add(ContextSet.empty()); c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.SERVER))); - c.addAll(getProxy().getServers().values().stream() - .map(ServerInfo::getName) - .map(s -> { - MutableContextSet set = MutableContextSet.create(); - set.add("server", getConfiguration().get(ConfigKeys.SERVER)); - set.add("world", s); - return set.makeImmutable(); - }) - .collect(Collectors.toList()) - ); - return c.stream() .map(set -> new Contexts( set, @@ -352,9 +339,4 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { )) .collect(Collectors.toSet()); } - - @Override - public UUID getUuidFromUsername(String playerName) { - return null; // Not needed on Bungee - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/caching/holder/GetAllNodesRequest.java b/common/src/main/java/me/lucko/luckperms/common/caching/holder/GetAllNodesRequest.java index 7675f32c..73fa654c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/caching/holder/GetAllNodesRequest.java +++ b/common/src/main/java/me/lucko/luckperms/common/caching/holder/GetAllNodesRequest.java @@ -27,7 +27,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; -import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import me.lucko.luckperms.common.utils.ExtractedContexts; @@ -37,7 +37,7 @@ import me.lucko.luckperms.common.utils.ExtractedContexts; @AllArgsConstructor(staticName = "of") public class GetAllNodesRequest { - private final ImmutableList excludedGroups; + private final ImmutableSet excludedGroups; private final ExtractedContexts contexts; } diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index 6b396d68..5c599edb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -29,7 +29,6 @@ import lombok.RequiredArgsConstructor; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; @@ -61,6 +60,7 @@ import me.lucko.luckperms.exceptions.ObjectAlreadyHasException; import me.lucko.luckperms.exceptions.ObjectLacksException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -257,7 +257,7 @@ public abstract class PermissionHolder { private SortedSet getAllNodesCacheApply(GetAllNodesRequest getAllNodesHolder) { // Expand the holder. - List excludedGroups = new ArrayList<>(getAllNodesHolder.getExcludedGroups()); + Set excludedGroups = new HashSet<>(getAllNodesHolder.getExcludedGroups()); ExtractedContexts contexts = getAllNodesHolder.getContexts(); // Don't register users, as they cannot be inherited. @@ -436,8 +436,8 @@ public abstract class PermissionHolder { * @param contexts context to decide if groups should be applied * @return a set of nodes */ - public SortedSet getAllNodes(List excludedGroups, ExtractedContexts contexts) { - return getAllNodesCache.getUnchecked(GetAllNodesRequest.of(excludedGroups == null ? ImmutableList.of() : ImmutableList.copyOf(excludedGroups), contexts)); + public SortedSet getAllNodes(Collection excludedGroups, ExtractedContexts contexts) { + return getAllNodesCache.getUnchecked(GetAllNodesRequest.of(excludedGroups == null ? ImmutableSet.of() : ImmutableSet.copyOf(excludedGroups), contexts)); } /** diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java index 8d092e6a..137c4226 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java @@ -345,14 +345,6 @@ public interface LuckPermsPlugin { */ Set getIgnoringLogs(); - /** - * Gets the UUID of a player. Used as a backup for migration - * - * @param playerName the players name - * @return a uuid if found, or null if not - */ - UUID getUuidFromUsername(String playerName); - /** * Gets the update task buffer of the platform, used for scheduling and running update tasks. * diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java b/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java index 6182b62e..c7176a09 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ExtractedContexts.java @@ -22,6 +22,7 @@ package me.lucko.luckperms.common.utils; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -31,6 +32,7 @@ import me.lucko.luckperms.api.context.ImmutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet; @Getter +@EqualsAndHashCode @ToString public class ExtractedContexts { public static ExtractedContexts generate(Contexts contexts) { 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 7619602f..9c930e5a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -442,11 +442,6 @@ public class LPSpongePlugin implements LuckPermsPlugin { return Collections.emptySet(); } - @Override - public UUID getUuidFromUsername(String playerName) { - return game.getServer().getPlayer(playerName).map(Player::getUniqueId).orElse(null); - } - @Override public List getExtraCommands() { return Collections.singletonList(new SpongeMainCommand(this));