From 7b97130af7307f5ab405595536fc77bb91059d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 24 May 2020 05:00:36 +0200 Subject: [PATCH] Add option to disable legacy cache, also add an option to return "Unknown" when a request cannot be fulfilled (old behaviour) This should fix issues where lowercase offline mode UUIDs don't have access to their old cache. --- .../com/plotsquared/bukkit/BukkitMain.java | 20 ++++++++++++++----- .../core/configuration/Settings.java | 4 ++++ .../plotsquared/core/uuid/UUIDPipeline.java | 9 ++++++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index d5e582e8c..84e474319 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -257,7 +257,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain backgroundPipeline.registerService(offlinePlayerUUIDService); final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db"); - final SQLiteUUIDService legacyUUIDSerivce = new SQLiteUUIDService("usercache.db"); + + final SQLiteUUIDService legacyUUIDService; + if (Settings.UUID.LEGACY_DATABASE_SUPPORT && MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db").exists()) { + legacyUUIDService = new SQLiteUUIDService("usercache.db"); + } else { + legacyUUIDService = null; + } final LuckPermsUUIDService luckPermsUUIDService; if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) { @@ -289,8 +295,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain impromptuPipeline.registerConsumer(sqLiteUUIDService); backgroundPipeline.registerConsumer(sqLiteUUIDService); - impromptuPipeline.registerService(legacyUUIDSerivce); - backgroundPipeline.registerService(legacyUUIDSerivce); + if (legacyUUIDService != null) { + impromptuPipeline.registerService(legacyUUIDService); + backgroundPipeline.registerService(legacyUUIDService); + } // Plugin providers if (luckPermsUUIDService != null) { @@ -312,8 +320,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain impromptuPipeline.registerConsumer(sqLiteUUIDService); backgroundPipeline.registerConsumer(sqLiteUUIDService); - impromptuPipeline.registerService(legacyUUIDSerivce); - backgroundPipeline.registerService(legacyUUIDSerivce); + if (legacyUUIDService != null) { + impromptuPipeline.registerService(legacyUUIDService); + backgroundPipeline.registerService(legacyUUIDService); + } } impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 0c2e30be9..e5bbd3180 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -248,6 +248,10 @@ public class Settings extends Config { public static long NON_BLOCKING_TIMEOUT = 3000L; @Comment("Timeout (in milliseconds) for blocking UUID requests (events)") public static long BLOCKING_TIMEOUT = 10L; + @Comment("Whether or not PlotSquared should read from the legacy database") + public static boolean LEGACY_DATABASE_SUPPORT = true; + @Comment("Whether or not PlotSquared should return Unknown if it fails to fulfill a request") + public static boolean UNKNOWN_AS_DEFAULT = true; } diff --git a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java index 3518fa5f8..8c8baa06d 100644 --- a/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java +++ b/Core/src/main/java/com/plotsquared/core/uuid/UUIDPipeline.java @@ -324,7 +324,14 @@ public class UUIDPipeline { PlotSquared.log("Failed to find all usernames"); } - throw new ServiceError("End of pipeline"); + if (Settings.UUID.UNKNOWN_AS_DEFAULT) { + for (final UUID uuid : remainingRequests) { + mappings.add(new UUIDMapping(uuid, Captions.UNKNOWN.getTranslated())); + } + return mappings; + } else { + throw new ServiceError("End of pipeline"); + } }, this.executor); }