From 5b4ae5ba36a32cff0d28cbef8dfc496c7b118fc1 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 8 Aug 2018 11:08:20 +0300 Subject: [PATCH] Moved Player#getFirstPlayed call to asynchronous execution #659 --- .../system/listeners/bukkit/PlayerOnlineListener.java | 2 +- .../system/listeners/sponge/SpongePlayerListener.java | 2 +- .../processing/processors/player/RegisterProcessor.java | 9 +++++---- .../plan/system/database/databases/SQLiteTest.java | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index d3a6c850f..23d34756a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -97,7 +97,7 @@ public class PlayerOnlineListener implements Listener { SessionCache.getInstance().cacheSession(uuid, new Session(uuid, time, world, gm)); Processing.submit( - new RegisterProcessor(uuid, player.getFirstPlayed(), playerName, + new RegisterProcessor(uuid, player::getFirstPlayed, playerName, new IPUpdateProcessor(uuid, address, time), new NameProcessor(uuid, playerName, displayName), new PlayerPageUpdateProcessor(uuid) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java index d4805ed6a..a302f2bd2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java @@ -100,7 +100,7 @@ public class SpongePlayerListener { SessionCache.getInstance().cacheSession(uuid, new Session(uuid, time, world, gm)); Processing.submit( - new RegisterProcessor(uuid, time, playerName, + new RegisterProcessor(uuid, () -> time, playerName, new IPUpdateProcessor(uuid, address, time), new NameProcessor(uuid, playerName, displayName), new PlayerPageUpdateProcessor(uuid) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java index 58f39af63..2cc024848 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/processing/processors/player/RegisterProcessor.java @@ -10,6 +10,7 @@ import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plugin.utilities.Verify; import java.util.UUID; +import java.util.function.Supplier; /** * Registers the user to the database and marks first session if the user has no actions. @@ -19,11 +20,11 @@ import java.util.UUID; public class RegisterProcessor implements CriticalRunnable { private final UUID uuid; - private final long registered; + private final Supplier registered; private final String name; private final Runnable[] afterProcess; - public RegisterProcessor(UUID uuid, long registered, String name, Runnable... afterProcess) { + public RegisterProcessor(UUID uuid, Supplier registered, String name, Runnable... afterProcess) { this.uuid = uuid; this.registered = registered; this.name = name; @@ -36,10 +37,10 @@ public class RegisterProcessor implements CriticalRunnable { Verify.nullCheck(uuid, () -> new IllegalStateException("UUID was null")); try { if (!db.check().isPlayerRegistered(uuid)) { - db.save().registerNewUser(uuid, registered, name); + db.save().registerNewUser(uuid, registered.get(), name); } if (!db.check().isPlayerRegisteredOnThisServer(uuid)) { - db.save().registerNewUserOnThisServer(uuid, registered); + db.save().registerNewUserOnThisServer(uuid, registered.get()); } } finally { for (Runnable runnable : afterProcess) { diff --git a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java index 06078f5db..7026f96be 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java @@ -594,7 +594,7 @@ public class SQLiteTest { assertTrue(securityTable.getUsers().isEmpty()); } - private void saveAllData(SQLDB database) throws UnsupportedEncodingException, NoSuchAlgorithmException { + private void saveAllData(SQLDB database) throws NoSuchAlgorithmException { System.out.println("Saving all possible data to the Database.."); UserInfoTable userInfoTable = database.getUserInfoTable(); UsersTable usersTable = database.getUsersTable(); @@ -864,7 +864,7 @@ public class SQLiteTest { System.out.println("\n- Running RegisterProcessors -"); List processors = new ArrayList<>(); for (int i = 0; i < 200; i++) { - processors.add(new RegisterProcessor(playerUUID, 500L, "name")); + processors.add(new RegisterProcessor(playerUUID, () -> 500L, "name")); } for (RegisterProcessor processor : processors) { processor.run();