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.
This commit is contained in:
Alexander Söderberg 2020-05-24 05:00:36 +02:00
parent cc168d5ae9
commit 7b97130af7
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
3 changed files with 27 additions and 6 deletions

View File

@ -257,7 +257,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
backgroundPipeline.registerService(offlinePlayerUUIDService); backgroundPipeline.registerService(offlinePlayerUUIDService);
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db"); 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; final LuckPermsUUIDService luckPermsUUIDService;
if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) { if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
@ -289,8 +295,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
impromptuPipeline.registerConsumer(sqLiteUUIDService); impromptuPipeline.registerConsumer(sqLiteUUIDService);
backgroundPipeline.registerConsumer(sqLiteUUIDService); backgroundPipeline.registerConsumer(sqLiteUUIDService);
impromptuPipeline.registerService(legacyUUIDSerivce); if (legacyUUIDService != null) {
backgroundPipeline.registerService(legacyUUIDSerivce); impromptuPipeline.registerService(legacyUUIDService);
backgroundPipeline.registerService(legacyUUIDService);
}
// Plugin providers // Plugin providers
if (luckPermsUUIDService != null) { if (luckPermsUUIDService != null) {
@ -312,8 +320,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
impromptuPipeline.registerConsumer(sqLiteUUIDService); impromptuPipeline.registerConsumer(sqLiteUUIDService);
backgroundPipeline.registerConsumer(sqLiteUUIDService); backgroundPipeline.registerConsumer(sqLiteUUIDService);
impromptuPipeline.registerService(legacyUUIDSerivce); if (legacyUUIDService != null) {
backgroundPipeline.registerService(legacyUUIDSerivce); impromptuPipeline.registerService(legacyUUIDService);
backgroundPipeline.registerService(legacyUUIDService);
}
} }
impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE); impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE);

View File

@ -248,6 +248,10 @@ public class Settings extends Config {
public static long NON_BLOCKING_TIMEOUT = 3000L; public static long NON_BLOCKING_TIMEOUT = 3000L;
@Comment("Timeout (in milliseconds) for blocking UUID requests (events)") @Comment("Timeout (in milliseconds) for blocking UUID requests (events)")
public static long BLOCKING_TIMEOUT = 10L; 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;
} }

View File

@ -324,7 +324,14 @@ public class UUIDPipeline {
PlotSquared.log("Failed to find all usernames"); PlotSquared.log("Failed to find all usernames");
} }
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"); throw new ServiceError("End of pipeline");
}
}, this.executor); }, this.executor);
} }