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:
@@ -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
|
||||
|
||||
+10
-9
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
+1
-3
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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 {
|
||||
String name = this.plugin.getStorage().noBuffer().getName(u).join();
|
||||
if (name == null) {
|
||||
this.plugin.getEventFactory().handleUserFirstLogin(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();
|
||||
}
|
||||
// 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);
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user