mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Initial work on user rewrite
Only JSONUserManager and Paper platform work currently
This commit is contained in:
22 files changed
+456
-305
No files matched your search
@@ -128,7 +128,7 @@ public final class CarbonChatFabric implements ModInitializer, CarbonChat {
|
||||
|
||||
private void registerServerLifecycleListeners() {
|
||||
ServerLifecycleEvents.SERVER_STARTING.register(server -> this.minecraftServer = server);
|
||||
ServerLifecycleEvents.SERVER_STOPPING.register($ -> PlayerUtils.saveLoggedInPlayers(this.carbonServerFabric, this.userManager).forEach(CompletableFuture::join));
|
||||
ServerLifecycleEvents.SERVER_STOPPING.register($ -> PlayerUtils.saveLoggedInPlayers(this.carbonServerFabric, this.userManager, this.logger).forEach(CompletableFuture::join));
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> this.minecraftServer = null);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public final class CarbonChatFabric implements ModInitializer, CarbonChat {
|
||||
|
||||
ServerTickEvents.END_SERVER_TICK.register(server -> {
|
||||
if (server.getTickCount() != 0 && server.getTickCount() % saveDelay == 0) {
|
||||
PlayerUtils.saveLoggedInPlayers(this.carbonServerFabric, this.userManager);
|
||||
PlayerUtils.saveLoggedInPlayers(this.carbonServerFabric, this.userManager, this.logger);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.SaveOnChange;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -33,7 +34,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class FabricUserManager implements UserManager<CarbonPlayerFabric>, SaveOnChange {
|
||||
public class FabricUserManager implements UserManagerInternal<CarbonPlayerFabric>, SaveOnChange {
|
||||
|
||||
protected final UserManager<CarbonPlayerCommon> proxiedUserManager;
|
||||
private final CarbonChatFabric carbonChatFabric;
|
||||
@@ -45,35 +46,30 @@ public class FabricUserManager implements UserManager<CarbonPlayerFabric>, SaveO
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerFabric>> carbonPlayer(final UUID uuid) {
|
||||
return this.proxiedUserManager.carbonPlayer(uuid).thenApply(result -> {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
return this.proxiedUserManager.carbonPlayer(uuid).thenApply(this::wrapResult);
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerFabric(result.player(), this.carbonChatFabric), result.reason());
|
||||
});
|
||||
@Override
|
||||
public CompletableFuture<CarbonPlayerFabric> user(UUID uuid) {
|
||||
return this.proxiedUserManager.user(uuid).thenApply(result -> new CarbonPlayerFabric(result, this.carbonChatFabric));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerFabric>> savePlayer(final CarbonPlayerFabric player) {
|
||||
return this.proxiedUserManager.savePlayer(player.carbonPlayerCommon()).thenApply(result -> {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerFabric(result.player(), this.carbonChatFabric), result.reason());
|
||||
});
|
||||
return this.proxiedUserManager.savePlayer(player.carbonPlayerCommon()).thenApply(this::wrapResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerFabric>> saveAndInvalidatePlayer(final CarbonPlayerFabric player) {
|
||||
return this.proxiedUserManager.saveAndInvalidatePlayer(player.carbonPlayerCommon()).thenApply(result -> {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
return this.proxiedUserManager.saveAndInvalidatePlayer(player.carbonPlayerCommon()).thenApply(this::wrapResult);
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerFabric(result.player(), this.carbonChatFabric), result.reason());
|
||||
});
|
||||
private ComponentPlayerResult<CarbonPlayerFabric> wrapResult(final ComponentPlayerResult<CarbonPlayerCommon> result) {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerFabric(result.player(), this.carbonChatFabric), result.reason());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,4 +170,18 @@ public class FabricUserManager implements UserManager<CarbonPlayerFabric>, SaveO
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
((UserManagerInternal<?>) this.proxiedUserManager).shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> save(CarbonPlayerFabric player) {
|
||||
return ((UserManagerInternal<CarbonPlayerCommon>) this.proxiedUserManager).save(player.carbonPlayerCommon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> loggedOut(final UUID uuid) {
|
||||
return ((UserManagerInternal<?>) this.proxiedUserManager).loggedOut(uuid);
|
||||
}
|
||||
}
|
||||
+3
@@ -48,6 +48,8 @@ public class FabricPlayerLeaveListener implements ServerPlayConnectionEvents.Dis
|
||||
|
||||
@Override
|
||||
public void onPlayDisconnect(final ServerGamePacketListenerImpl handler, final MinecraftServer server) {
|
||||
// todo
|
||||
/*
|
||||
this.carbonChat.server().userManager().carbonPlayer(handler.getPlayer().getUUID()).thenAccept(result -> {
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
@@ -55,6 +57,7 @@ public class FabricPlayerLeaveListener implements ServerPlayConnectionEvents.Dis
|
||||
|
||||
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerFabric) result.player());
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user