Fix SQLite table creation statement and add legacy SQLite uuids as a provider

This commit is contained in:
Alexander Söderberg 2020-05-24 04:48:19 +02:00
parent d19df3b6eb
commit cc168d5ae9
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
2 changed files with 11 additions and 4 deletions

View File

@ -256,7 +256,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
impromptuPipeline.registerService(offlinePlayerUUIDService); impromptuPipeline.registerService(offlinePlayerUUIDService);
backgroundPipeline.registerService(offlinePlayerUUIDService); backgroundPipeline.registerService(offlinePlayerUUIDService);
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService(); final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
final SQLiteUUIDService legacyUUIDSerivce = new SQLiteUUIDService("usercache.db");
final LuckPermsUUIDService luckPermsUUIDService; final LuckPermsUUIDService luckPermsUUIDService;
if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) { if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
@ -288,6 +289,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
impromptuPipeline.registerConsumer(sqLiteUUIDService); impromptuPipeline.registerConsumer(sqLiteUUIDService);
backgroundPipeline.registerConsumer(sqLiteUUIDService); backgroundPipeline.registerConsumer(sqLiteUUIDService);
impromptuPipeline.registerService(legacyUUIDSerivce);
backgroundPipeline.registerService(legacyUUIDSerivce);
// Plugin providers // Plugin providers
if (luckPermsUUIDService != null) { if (luckPermsUUIDService != null) {
impromptuPipeline.registerService(luckPermsUUIDService); impromptuPipeline.registerService(luckPermsUUIDService);
@ -307,6 +311,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
backgroundPipeline.registerService(sqLiteUUIDService); backgroundPipeline.registerService(sqLiteUUIDService);
impromptuPipeline.registerConsumer(sqLiteUUIDService); impromptuPipeline.registerConsumer(sqLiteUUIDService);
backgroundPipeline.registerConsumer(sqLiteUUIDService); backgroundPipeline.registerConsumer(sqLiteUUIDService);
impromptuPipeline.registerService(legacyUUIDSerivce);
backgroundPipeline.registerService(legacyUUIDSerivce);
} }
impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE); impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE);

View File

@ -49,9 +49,9 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
private final SQLite sqlite; private final SQLite sqlite;
public SQLiteUUIDService() { public SQLiteUUIDService(final String fileName) {
this.sqlite = this.sqlite =
new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db")); new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), fileName));
try { try {
this.sqlite.openConnection(); this.sqlite.openConnection();
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
@ -59,7 +59,7 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
} }
try (PreparedStatement stmt = getConnection().prepareStatement( try (PreparedStatement stmt = getConnection().prepareStatement(
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid, username))")) { "CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid))")) {
stmt.execute(); stmt.execute();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();