Remove the 'use-server-uuids' option and internal UuidCache system

The feature has stuck around since the early days - and solves a problem which really should never occur.
This commit is contained in:
Luck 2018-01-21 20:18:13 +00:00
parent 4c3e28ba85
commit 72d4e5cf7a
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
28 changed files with 52 additions and 304 deletions

View File

@ -202,8 +202,11 @@ public interface LuckPermsApi {
* mapping system.</p>
*
* @return the uuid cache
* @deprecated this feature is now handled internally - and the API returns a
* No-op implementation of this class.
*/
@Nonnull
@Deprecated
UuidCache getUuidCache();
/**

View File

@ -33,15 +33,10 @@ import javax.annotation.Nonnull;
* A UUID cache for online users, between external Mojang UUIDs, and internal
* LuckPerms UUIDs.
*
* <p>A user's internal LuckPerms UUID is always the same as their Mojang one,
* unless <code>use-server-uuids</code> is disabled.</p>
*
* <p>When this setting is disabled, this cache becomes active, and allows you
* to convert between 'internal' and 'server provided' uuids.</p>
*
* <p><strong>This is only effective for online players.
* Use {@link Storage#getUUID(String)} for offline players.</strong></p>
* @deprecated this feature is now handled internally - and the API returns a
* No-op implementation of this class.
*/
@Deprecated
public interface UuidCache {
/**
@ -56,6 +51,7 @@ public interface UuidCache {
* @return the corresponding internal UUID
*/
@Nonnull
@Deprecated
UUID getUUID(@Nonnull UUID mojangUuid);
/**
@ -67,6 +63,7 @@ public interface UuidCache {
* @return the corresponding external UUID
*/
@Nonnull
@Deprecated
UUID getExternalUUID(@Nonnull UUID internalUuid);
}

View File

@ -80,7 +80,6 @@ import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
import me.lucko.luckperms.common.tasks.UpdateTask;
import me.lucko.luckperms.common.treeview.PermissionVault;
import me.lucko.luckperms.common.utils.UuidCache;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import org.bukkit.command.PluginCommand;
@ -120,7 +119,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
private Storage storage;
private FileWatcher fileWatcher = null;
private InternalMessagingService messagingService = null;
private UuidCache uuidCache;
private LuckPermsApiProvider apiProvider;
private EventFactory eventFactory;
private Logger log;
@ -238,7 +236,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
// load internal managers
getLog().info("Loading internal permission managers...");
this.uuidCache = new UuidCache(this);
this.userManager = new StandardUserManager(this);
this.groupManager = new StandardGroupManager(this);
this.trackManager = new StandardTrackManager(this);
@ -318,7 +315,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
this.scheduler.doAsync(() -> {
try {
connectionListener.loadUser(player.getUniqueId(), player.getName());
User user = getUserManager().getIfLoaded(getUuidCache().getUUID(player.getUniqueId()));
User user = getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
this.scheduler.doSync(() -> {
try {
@ -363,7 +360,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
player.setOp(false);
}
final User user = getUserManager().getIfLoaded(getUuidCache().getUUID(player.getUniqueId()));
final User user = getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
user.getCachedData().invalidateCaches();
getUserManager().unload(user);
@ -496,7 +493,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
@Override
public Player getPlayer(User user) {
return getServer().getPlayer(this.uuidCache.getExternalUUID(user.getUuid()));
return getServer().getPlayer(user.getUuid());
}
@Override
@ -615,11 +612,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
return this.storage;
}
@Override
public UuidCache getUuidCache() {
return this.uuidCache;
}
@Override
public LuckPermsApiProvider getApiProvider() {
return this.apiProvider;

View File

@ -129,7 +129,7 @@ public class BukkitConnectionListener extends AbstractLoginListener implements L
this.plugin.getLog().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
}
final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
final User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
/* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
if (user == null) {

View File

@ -246,7 +246,7 @@ public class VaultChatHook extends AbstractVaultChat {
// utility methods for getting user and group instances
private User getUser(UUID uuid) {
return this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(uuid));
return this.plugin.getUserManager().getIfLoaded(uuid);
}
private Group getGroup(String name) {

View File

@ -287,7 +287,7 @@ public class VaultPermissionHook extends AbstractVaultPermission {
// utility methods for getting user and group instances
private User getUser(UUID uuid) {
return this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(uuid));
return this.plugin.getUserManager().getIfLoaded(uuid);
}
private Group getGroup(String name) {

View File

@ -38,34 +38,6 @@ apply-global-groups: true
# If users on this server should have global (non-world specific) groups applied
apply-global-world-groups: true
# If UUIDs should be pulled from the server, or looked up by username based upon previous
# connections.
#
# This option should be set to true in most cases. When set to false, in order to get a player's
# UUID, LuckPerms will:
#
# 1. Check if a player with the given username has joined before, if they have, use the UUID they
# used on their previous login.
# 2. Save and return the players "current" uuid.
#
# For offline mode (cracked) servers, a players UUID is generated based upon their username.
#
# IMPORTANT:
# If you are using BungeeCord proxy running in online mode, it is important that "online-mode=false"
# is set in server.properties, but "bungeecord: true" is set in the spigot.yml. You also need to set
# "ip_forward: true" in BungeeCord's config.yml.
#
# If for whatever reason you are not able to do this, and do not have ip-forward enabled, then you
# may need to set "use-server-uuids" to false.
#
# If your proxy is running in offline mode, you should still be setting up ip-forwarding as
# described above, but may also find that you need to set "bungee-online-mode" to false in
# paper.yml, if you are using Paper. (https://ci.destroystokyo.com/job/PaperSpigot/)
#
# This option only really exists for networks who for whatever reason cannot setup proper ip
# forwarding.
use-server-uuids: true
# If the servers own UUID cache/lookup facility should be used when there is no record for a player
# in the LuckPerms cache.
use-server-uuid-cache: false

View File

@ -74,7 +74,6 @@ import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
import me.lucko.luckperms.common.tasks.UpdateTask;
import me.lucko.luckperms.common.treeview.PermissionVault;
import me.lucko.luckperms.common.utils.UuidCache;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -106,7 +105,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
private Storage storage;
private FileWatcher fileWatcher = null;
private InternalMessagingService messagingService = null;
private UuidCache uuidCache;
private LuckPermsApiProvider apiProvider;
private EventFactory eventFactory;
private Logger log;
@ -183,7 +181,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
// load internal managers
getLog().info("Loading internal permission managers...");
this.uuidCache = new UuidCache(this);
this.userManager = new StandardUserManager(this);
this.groupManager = new StandardGroupManager(this);
this.trackManager = new StandardTrackManager(this);
@ -322,7 +319,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
@Override
public ProxiedPlayer getPlayer(User user) {
return getProxy().getPlayer(this.uuidCache.getExternalUUID(user.getUuid()));
return getProxy().getPlayer(user.getUuid());
}
@Override
@ -421,11 +418,6 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
return this.storage;
}
@Override
public UuidCache getUuidCache() {
return this.uuidCache;
}
@Override
public LuckPermsApiProvider getApiProvider() {
return this.apiProvider;

View File

@ -105,7 +105,7 @@ public class BungeeConnectionListener extends AbstractLoginListener implements L
@EventHandler
public void onPlayerPostLogin(PostLoginEvent e) {
final ProxiedPlayer player = e.getPlayer();
final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(e.getPlayer().getUniqueId()));
final User user = this.plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId());
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
this.plugin.getLog().info("Processing post-login for " + player.getUniqueId() + " - " + player.getName());

View File

@ -54,7 +54,7 @@ public class BungeePermissionCheckListener implements Listener {
ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user == null) {
e.setHasPermission(false);
return;
@ -77,7 +77,7 @@ public class BungeePermissionCheckListener implements Listener {
ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user == null) {
e.setResult(Tristate.UNDEFINED);
return;

View File

@ -38,34 +38,6 @@ apply-global-groups: true
# If users on this server should have global (non-world specific) groups applied
apply-global-world-groups: true
# If UUIDs should be pulled from the server, or looked up by username based upon previous
# connections.
#
# This option should be set to true in most cases. When set to false, in order to get a player's
# UUID, LuckPerms will:
#
# 1. Check if a player with the given username has joined before, if they have, use the UUID they
# used on their previous login.
# 2. Save and return the players "current" uuid.
#
# For offline mode (cracked) servers, a players UUID is generated based upon their username.
#
# IMPORTANT:
# If you are using BungeeCord proxy running in online mode, it is important that "online-mode=false"
# is set in server.properties, but "bungeecord: true" is set in the spigot.yml. You also need to set
# "ip_forward: true" in BungeeCord's config.yml.
#
# If for whatever reason you are not able to do this, and do not have ip-forward enabled, then you
# may need to set "use-server-uuids" to false.
#
# If your proxy is running in offline mode, you should still be setting up ip-forwarding as
# described above, but may also find that you need to set "bungee-online-mode" to false in
# paper.yml, if you are using Paper. (https://ci.destroystokyo.com/job/PaperSpigot/)
#
# This option only really exists for networks who for whatever reason cannot setup proper ip
# forwarding.
use-server-uuids: true
# If the servers own UUID cache/lookup facility should be used when there is no record for a player
# in the LuckPerms cache.
#

View File

@ -49,6 +49,7 @@ import me.lucko.luckperms.common.api.delegates.misc.ApiMessagingService;
import me.lucko.luckperms.common.api.delegates.misc.ApiMetaStackFactory;
import me.lucko.luckperms.common.api.delegates.misc.ApiNodeFactory;
import me.lucko.luckperms.common.api.delegates.misc.ApiPlatformInfo;
import me.lucko.luckperms.common.api.delegates.misc.NoopUuidCache;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.messaging.LuckPermsMessagingService;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -153,8 +154,9 @@ public class LuckPermsApiProvider implements LuckPermsApi {
@Nonnull
@Override
@Deprecated
public UuidCache getUuidCache() {
return this.plugin.getUuidCache().getDelegate();
return NoopUuidCache.INSTANCE;
}
@Override

View File

@ -27,29 +27,30 @@ package me.lucko.luckperms.common.api.delegates.misc;
import me.lucko.luckperms.api.UuidCache;
import java.util.Objects;
import java.util.UUID;
import javax.annotation.Nonnull;
public class ApiUuidCache implements UuidCache {
private final me.lucko.luckperms.common.utils.UuidCache handle;
@Deprecated
@SuppressWarnings({"DeprecatedIsStillUsed", "deprecation"})
public class NoopUuidCache implements UuidCache {
public static final NoopUuidCache INSTANCE = new NoopUuidCache();
private NoopUuidCache() {
public ApiUuidCache(me.lucko.luckperms.common.utils.UuidCache handle) {
this.handle = handle;
}
@Nonnull
@Override
@Deprecated
public UUID getUUID(@Nonnull UUID external) {
Objects.requireNonNull(external, "external");
return this.handle.getUUID(external);
return external;
}
@Nonnull
@Override
@Deprecated
public UUID getExternalUUID(@Nonnull UUID internal) {
Objects.requireNonNull(internal, "internal");
return this.handle.getExternalUUID(internal);
return internal;
}
}

View File

@ -77,7 +77,7 @@ public final class ArgumentPermissions {
if (target instanceof User) {
User targetUser = ((User) target);
if (plugin.getUuidCache().getExternalUUID(targetUser.getUuid()).equals(sender.getUuid())) {
if (targetUser.getUuid().equals(sender.getUuid())) {
// the sender is trying to edit themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.self");
if (ret != Tristate.UNDEFINED) {
@ -133,7 +133,7 @@ public final class ArgumentPermissions {
if (target instanceof User) {
User targetUser = ((User) target);
if (plugin.getUuidCache().getExternalUUID(targetUser.getUuid()).equals(sender.getUuid())) {
if (targetUser.getUuid().equals(sender.getUuid())) {
// the sender is trying to view themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view.self");
if (ret != Tristate.UNDEFINED) {

View File

@ -49,7 +49,7 @@ public class LogNotify extends SubCommand<Log> {
}
public static boolean isIgnoring(LuckPermsPlugin plugin, UUID uuid) {
User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(uuid));
User user = plugin.getUserManager().getIfLoaded(uuid);
if (user == null) {
return false;
}
@ -64,7 +64,7 @@ public class LogNotify extends SubCommand<Log> {
}
private static void setIgnoring(LuckPermsPlugin plugin, UUID uuid, boolean state) {
User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(uuid));
User user = plugin.getUserManager().getIfLoaded(uuid);
if (user == null) {
return;
}

View File

@ -59,7 +59,7 @@ public class UserInfo extends SubCommand<User> {
return CommandResult.NO_PERMISSION;
}
Message status = plugin.isPlayerOnline(plugin.getUuidCache().getExternalUUID(user.getUuid())) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message status = plugin.isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message.USER_INFO_GENERAL.send(sender,
user.getName().orElse("Unknown"),

View File

@ -118,14 +118,6 @@ public class ConfigKeys {
*/
public static final ConfigKey<Boolean> APPLYING_GLOBAL_WORLD_GROUPS = BooleanKey.of("apply-global-world-groups", true);
/**
* If the server provided uuids should be used. False if we should use the LP cache for existing users.
*/
public static final ConfigKey<Boolean> USE_SERVER_UUIDS = AbstractKey.of(c -> {
// backwards compatible with the old online-mode option
return c.contains("use-server-uuids") ? c.getBoolean("use-server-uuids", true) : c.getBoolean("online-mode", true);
});
/**
* # If the servers own UUID cache/lookup facility should be used when there is no record for a player in the LuckPerms cache.
*/

View File

@ -147,9 +147,7 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
@Override
public CompletableFuture<Void> updateAllUsers() {
return CompletableFuture.runAsync(
() -> this.plugin.getOnlinePlayers()
.map(u -> this.plugin.getUuidCache().getUUID(u))
.forEach(u -> this.plugin.getStorage().loadUser(u, null).join()),
() -> this.plugin.getOnlinePlayers().forEach(u -> this.plugin.getStorage().loadUser(u, null).join()),
this.plugin.getScheduler().async()
);
}

View File

@ -76,7 +76,7 @@ public class UserHousekeeper implements Runnable {
UUID uuid = identifier.getUuid();
// unload users which aren't online and who haven't been online (or tried to login) recently
if (this.recentlyUsed.contains(uuid) || this.recentlyUsedApi.contains(uuid) || this.plugin.isPlayerOnline(this.plugin.getUuidCache().getExternalUUID(uuid))) {
if (this.recentlyUsed.contains(uuid) || this.recentlyUsedApi.contains(uuid) || this.plugin.isPlayerOnline(uuid)) {
return;
}

View File

@ -63,7 +63,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
this.cachedData = new GroupCachedData(this);
getPlugin().getEventFactory().handleGroupCacheLoad(this, this.cachedData);
// invalidate out caches when data is updated
// invalidate our caches when data is updated
getStateListeners().add(this.refreshBuffer::request);
}

View File

@ -191,7 +191,7 @@ public abstract class PermissionHolder {
declareState();
}
protected void declareState() {
private void declareState() {
/* only declare state of groups. the state manager isn't really being used now the caches in this class
are gone, but it's useful for command output. */
if (this.getType().isGroup()) {
@ -255,20 +255,10 @@ public abstract class PermissionHolder {
return this.transientNodes;
}
/**
* Returns an immutable copy of this objects nodes
*
* @return an immutable copy of the multimap storing this objects nodes
*/
public ImmutableSetMultimap<ImmutableContextSet, Node> getEnduringNodes() {
return this.enduringNodes.immutable();
}
/**
* Returns an immutable copy of this objects transient nodes
*
* @return an immutable copy of the multimap storing this objects transient nodes
*/
public ImmutableSetMultimap<ImmutableContextSet, Node> getTransientNodes() {
return this.transientNodes.immutable();
}
@ -298,8 +288,8 @@ public abstract class PermissionHolder {
*
* @return a set containing the holders enduring and transient permissions
*/
public LinkedHashSet<Node> getOwnNodesSet() {
LinkedHashSet<Node> ret = new LinkedHashSet<>();
public Set<Node> getOwnNodesSet() {
Set<Node> ret = new LinkedHashSet<>();
this.transientNodes.copyTo(ret);
this.enduringNodes.copyTo(ret);
return ret;

View File

@ -51,7 +51,6 @@ import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.storage.Storage;
import me.lucko.luckperms.common.storage.dao.file.FileWatcher;
import me.lucko.luckperms.common.treeview.PermissionVault;
import me.lucko.luckperms.common.utils.UuidCache;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import java.io.File;
@ -128,13 +127,6 @@ public interface LuckPermsPlugin {
*/
Logger getLog();
/**
* Gets the UUID caching store for the platform
*
* @return the uuid cache
*/
UuidCache getUuidCache();
/**
* Gets the event factory
*

View File

@ -25,14 +25,12 @@
package me.lucko.luckperms.common.utils;
import me.lucko.luckperms.api.platform.PlatformType;
import me.lucko.luckperms.common.assignments.AssignmentRule;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* Abstract listener utility for handling new player connections
@ -40,14 +38,8 @@ import java.util.concurrent.CompletableFuture;
public abstract class AbstractLoginListener {
private final LuckPermsPlugin plugin;
// if we should #join the uuid save future.
// this is only really necessary on BungeeCord, as the data may be needed
// on the backend, depending on uuid config options
private final boolean joinUuidSave;
protected AbstractLoginListener(LuckPermsPlugin plugin) {
this.plugin = plugin;
this.joinUuidSave = plugin.getServerType() == PlatformType.BUNGEE;
}
public User loadUser(UUID u, String username) {
@ -56,34 +48,14 @@ public abstract class AbstractLoginListener {
// register with the housekeeper to avoid accidental unloads
this.plugin.getUserManager().getHouseKeeper().registerUsage(u);
final UuidCache cache = this.plugin.getUuidCache();
if (!this.plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUIDS)) {
UUID uuid = this.plugin.getStorage().noBuffer().getUUID(username).join();
if (uuid != null) {
cache.addToCache(u, uuid);
} else {
// No previous data for this player
this.plugin.getEventFactory().handleUserFirstLogin(u, username);
cache.addToCache(u, u);
CompletableFuture<Void> future = this.plugin.getStorage().noBuffer().saveUUIDData(u, username);
if (this.joinUuidSave) {
future.join();
}
}
} else {
// save uuid data.
String name = this.plugin.getStorage().noBuffer().getName(u).join();
if (name == null) {
this.plugin.getEventFactory().handleUserFirstLogin(u, username);
}
this.plugin.getStorage().noBuffer().saveUUIDData(u, username);
// Online mode, no cache needed. This is just for name -> uuid lookup.
CompletableFuture<Void> future = this.plugin.getStorage().noBuffer().saveUUIDData(u, username);
if (this.joinUuidSave) {
future.join();
}
}
User user = this.plugin.getStorage().noBuffer().loadUser(cache.getUUID(u), username).join();
User user = this.plugin.getStorage().noBuffer().loadUser(u, username).join();
if (user == null) {
throw new NullPointerException("User is null");
} else {

View File

@ -1,82 +0,0 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.utils;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import me.lucko.luckperms.common.api.delegates.misc.ApiUuidCache;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.UUID;
/**
* @see me.lucko.luckperms.api.UuidCache for docs
*/
public class UuidCache {
private final LuckPermsPlugin plugin;
// External UUID --> Internal UUID
private final BiMap<UUID, UUID> cache = Maps.synchronizedBiMap(HashBiMap.create());
private final ApiUuidCache delegate = new ApiUuidCache(this);
public UuidCache(LuckPermsPlugin plugin) {
this.plugin = plugin;
}
public UUID getUUID(UUID external) {
return inUse() ? external : this.cache.getOrDefault(external, external);
}
public UUID getExternalUUID(UUID internal) {
return inUse() ? internal : this.cache.inverse().getOrDefault(internal, internal);
}
public void addToCache(UUID external, UUID internal) {
if (inUse()) return;
this.cache.forcePut(external, internal);
}
public void clearCache(UUID external) {
if (inUse()) return;
this.cache.remove(external);
}
public int getSize() {
return inUse() ? 0 : this.cache.size();
}
private boolean inUse() {
return this.plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUIDS);
}
public ApiUuidCache getDelegate() {
return this.delegate;
}
}

View File

@ -66,7 +66,6 @@ import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
import me.lucko.luckperms.common.tasks.UpdateTask;
import me.lucko.luckperms.common.treeview.PermissionVault;
import me.lucko.luckperms.common.utils.UuidCache;
import me.lucko.luckperms.common.verbose.VerboseHandler;
import me.lucko.luckperms.sponge.calculators.SpongeCalculatorFactory;
import me.lucko.luckperms.sponge.commands.SpongeMainCommand;
@ -173,7 +172,6 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
private Storage storage;
private FileWatcher fileWatcher = null;
private InternalMessagingService messagingService = null;
private UuidCache uuidCache;
private LuckPermsApiProvider apiProvider;
private EventFactory eventFactory;
private me.lucko.luckperms.common.logging.Logger log;
@ -243,7 +241,6 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
// load internal managers
getLog().info("Loading internal permission managers...");
this.uuidCache = new UuidCache(this);
this.userManager = new SpongeUserManager(this);
this.groupManager = new SpongeGroupManager(this);
this.trackManager = new StandardTrackManager(this);
@ -410,7 +407,7 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
return null;
}
return this.game.getServer().getPlayer(this.uuidCache.getExternalUUID(user.getUuid())).orElse(null);
return this.game.getServer().getPlayer(user.getUuid()).orElse(null);
}
@Override
@ -580,11 +577,6 @@ public class LPSpongePlugin implements LuckPermsSpongePlugin {
return this.storage;
}
@Override
public UuidCache getUuidCache() {
return this.uuidCache;
}
@Override
public LuckPermsApiProvider getApiProvider() {
return this.apiProvider;

View File

@ -29,7 +29,6 @@ import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.locale.Message;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.utils.AbstractLoginListener;
import me.lucko.luckperms.common.utils.UuidCache;
import me.lucko.luckperms.sponge.LPSpongePlugin;
import org.spongepowered.api.event.Listener;
@ -126,7 +125,7 @@ public class SpongeConnectionListener extends AbstractLoginListener {
this.plugin.getLog().info("Processing login event for " + player.getUniqueId() + " - " + player.getName());
}
final User user = this.plugin.getUserManager().getIfLoaded(this.plugin.getUuidCache().getUUID(player.getUniqueId()));
final User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
/* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
if (user == null) {
@ -158,15 +157,6 @@ public class SpongeConnectionListener extends AbstractLoginListener {
@Listener(order = Order.POST)
public void onClientLeave(ClientConnectionEvent.Disconnect e) {
/* We don't actually remove the user instance here, as Sponge likes to keep performing checks
on players when they disconnect. The instance gets cleared up on a housekeeping task
after a period of inactivity. */
final UuidCache cache = this.plugin.getUuidCache();
// Unload the user from memory when they disconnect
cache.clearCache(e.getTargetEntity().getUniqueId());
// Register with the housekeeper, so the User's instance will stick
// around for a bit after they disconnect
this.plugin.getUserManager().getHouseKeeper().registerUsage(e.getTargetEntity().getUniqueId());

View File

@ -87,7 +87,7 @@ public class SpongeUser extends User {
@Override
public String getIdentifier() {
return this.plugin.getUuidCache().getExternalUUID(this.parent.getUuid()).toString();
return this.parent.getUuid().toString();
}
@Override
@ -97,7 +97,7 @@ public class SpongeUser extends User {
@Override
public Optional<CommandSource> getCommandSource() {
final UUID uuid = this.plugin.getUuidCache().getExternalUUID(this.parent.getUuid());
final UUID uuid = this.parent.getUuid();
return Sponge.getServer().getPlayer(uuid).map(Function.identity());
}

View File

@ -38,33 +38,6 @@ apply-global-groups=true
# If users on this server should have global (non-world specific) groups applied
apply-global-world-groups=true
# If UUIDs should be pulled from the server, or looked up by username based upon previous
# connections.
#
# This option should be set to true in most cases. When set to false, in order to get a player's
# UUID, LuckPerms will:
#
# 1. Check if a player with the given username has joined before, if they have, use the UUID they
# used on their previous login.
# 2. Save and return the players "current" uuid.
#
# For offline mode (cracked) servers, a players UUID is generated based upon their username.
#
# IMPORTANT:
# If you are using BungeeCord proxy running in online mode, it is important that "online-mode=false"
# is set in server.properties, but "bungeecord: true" is set in the spigot.yml. You also need to set
# "ip_forward: true" in BungeeCord's config.yml.
#
# If for whatever reason you are not able to do this, and do not have ip-forward enabled, then you
# may need to set "use-server-uuids" to false.
#
# If your proxy is running in offline mode, you should still be setting up ip-forwarding as
# described above.
#
# This option only really exists for networks who for whatever reason cannot setup proper ip
# forwarding.
use-server-uuids=true
# If the servers own UUID cache/lookup facility should be used when there is no record for a player
# in the LuckPerms cache.
use-server-uuid-cache=false