mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Shove login processing into an async task.
ez
This commit is contained in:
1 parent
c1ef5ff8ae
commit
cbd1d66f60
4 files changed
+23
-10
No files matched your search
@@ -4,20 +4,19 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public interface UserService<T extends PlayerUser> {
|
public interface UserService<T extends PlayerUser> {
|
||||||
|
|
||||||
@NonNull
|
@Nullable <C extends ConsoleUser> C consoleUser();
|
||||||
T wrap(UUID uuid);
|
|
||||||
|
|
||||||
@Nullable // Maybe NonNull?
|
@NonNull T wrap(@NonNull UUID uuid);
|
||||||
<C extends ConsoleUser> C consoleUser();
|
|
||||||
|
|
||||||
@Nullable
|
@NonNull CompletableFuture<T> wrapLater(@NonNull UUID uuid);
|
||||||
T wrapIfLoaded(@NonNull UUID uuid);
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable T wrapIfLoaded(@NonNull UUID uuid);
|
||||||
T refreshUser(@NonNull UUID uuid);
|
|
||||||
|
@Nullable T refreshUser(@NonNull UUID uuid);
|
||||||
|
|
||||||
void onDisable();
|
void onDisable();
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -104,18 +104,20 @@ public class BukkitChatListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
final PlayerUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
|
this.carbonChat.userService().wrapLater(event.getPlayer().getUniqueId()).thenAcceptAsync(user -> {
|
||||||
final UserEvent.Join joinEvent = new UserEvent.Join(user);
|
final UserEvent.Join joinEvent = new UserEvent.Join(user);
|
||||||
|
|
||||||
CarbonEvents.post(joinEvent);
|
CarbonEvents.post(joinEvent);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(final PlayerQuitEvent event) {
|
public void onPlayerLeave(final PlayerQuitEvent event) {
|
||||||
final PlayerUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
|
this.carbonChat.userService().wrapLater(event.getPlayer().getUniqueId()).thenAcceptAsync(user -> {
|
||||||
final UserEvent.Leave leaveEvent = new UserEvent.Leave(user);
|
final UserEvent.Leave leaveEvent = new UserEvent.Leave(user);
|
||||||
|
|
||||||
CarbonEvents.post(leaveEvent);
|
CarbonEvents.post(leaveEvent);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,7 @@ import java.lang.reflect.Type;
|
|||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -78,6 +79,11 @@ public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull CompletableFuture<T> wrapLater(final @NonNull UUID uuid) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.wrap(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable C consoleUser() {
|
public @Nullable C consoleUser() {
|
||||||
return this.consoleFactory.get();
|
return this.consoleFactory.get();
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.util.Map;
|
|||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -124,6 +125,11 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull CompletableFuture<T> wrapLater(final @NonNull UUID uuid) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> this.wrap(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable C consoleUser() {
|
public @Nullable C consoleUser() {
|
||||||
return this.consoleFactory.get();
|
return this.consoleFactory.get();
|
||||||
|
|||||||
Reference in new issue
Block a user