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);
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);

View file

@ -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;
}

View file

@ -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);
}