mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Save and invalidate player on quit on all platforms
This commit is contained in:
1 parent
15c994bdbd
commit
20e384522e
9 files changed
+306
-36
No files matched your search
+17
-10
@@ -23,7 +23,12 @@ import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.util.PlayerUtils;
|
||||
import net.draycia.carbon.sponge.users.CarbonPlayerSponge;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -35,14 +40,17 @@ public class SpongePlayerJoinListener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final PrimaryConfig primaryConfig;
|
||||
private final UserManager<CarbonPlayerCommon> userManager;
|
||||
|
||||
@Inject
|
||||
public SpongePlayerJoinListener(
|
||||
final CarbonChat carbonChat,
|
||||
final PrimaryConfig primaryConfig
|
||||
final PrimaryConfig primaryConfig,
|
||||
final UserManager<CarbonPlayerCommon> userManager
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.primaryConfig = primaryConfig;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
@Listener
|
||||
@@ -62,12 +70,8 @@ public class SpongePlayerJoinListener {
|
||||
|
||||
@Listener
|
||||
public void onPlayerQuit(final ServerSideConnectionEvent.Disconnect event) {
|
||||
// Early exit in case "hide muted join / leave messages when muted" is disabled
|
||||
if (!this.primaryConfig.hideMutedJoinLeaveQuit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ComponentPlayerResult<CarbonPlayer> result = this.carbonChat.server().player(event.player().uniqueId()).join();
|
||||
final ComponentPlayerResult<CarbonPlayer> result =
|
||||
this.carbonChat.server().player(event.player().uniqueId()).join();
|
||||
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
@@ -75,10 +79,13 @@ public class SpongePlayerJoinListener {
|
||||
|
||||
final CarbonPlayer player = result.player();
|
||||
|
||||
// Don't show quit messages when muted
|
||||
if (!player.muteEntries().isEmpty()) {
|
||||
event.setMessage(null); // TODO: null? empty? it's not MessageCancellable, which is odd
|
||||
if (this.primaryConfig.hideMutedJoinLeaveQuit()) {
|
||||
if (!player.muteEntries().isEmpty()) {
|
||||
event.setAudience(Audience.empty());
|
||||
}
|
||||
}
|
||||
|
||||
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerSponge) player);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user