mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +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
@@ -39,7 +39,11 @@ import net.draycia.carbon.common.util.CloudUtils;
|
||||
import net.draycia.carbon.common.util.ListenerUtils;
|
||||
import net.draycia.carbon.common.util.PlayerUtils;
|
||||
import net.draycia.carbon.fabric.callback.ChatCallback;
|
||||
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
|
||||
import net.draycia.carbon.fabric.listeners.FabricChatListener;
|
||||
import net.draycia.carbon.fabric.listeners.FabricPlayerDeathListener;
|
||||
import net.draycia.carbon.fabric.listeners.FabricPlayerJoinListener;
|
||||
import net.draycia.carbon.fabric.listeners.FabricPlayerLeaveListener;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
@@ -87,6 +91,7 @@ public final class CarbonChatFabric implements ModInitializer, CarbonChat {
|
||||
// Platform Listeners
|
||||
this.registerChatListener();
|
||||
this.registerServerLifecycleListeners();
|
||||
this.registerPlayerStatusListeners();
|
||||
this.registerTickListeners();
|
||||
|
||||
// Listeners
|
||||
@@ -110,6 +115,12 @@ public final class CarbonChatFabric implements ModInitializer, CarbonChat {
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> this.minecraftServer = null);
|
||||
}
|
||||
|
||||
private void registerPlayerStatusListeners() {
|
||||
PlayerStatusMessageEvents.JOIN_MESSAGE.register(this.injector.getInstance(FabricPlayerJoinListener.class));
|
||||
PlayerStatusMessageEvents.QUIT_MESSAGE.register(this.injector.getInstance(FabricPlayerLeaveListener.class));
|
||||
PlayerStatusMessageEvents.DEATH_MESSAGE.register(this.injector.getInstance(FabricPlayerDeathListener.class));
|
||||
}
|
||||
|
||||
private void registerTickListeners() {
|
||||
final long saveDelay = 5 * 60 * 20; // 5 minutes
|
||||
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.fabric.listeners;
|
||||
|
||||
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.common.config.PrimaryConfig;
|
||||
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class FabricPlayerDeathListener implements PlayerStatusMessageEvents.MessageEventListener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final PrimaryConfig primaryConfig;
|
||||
|
||||
@Inject
|
||||
public FabricPlayerDeathListener(
|
||||
final CarbonChat carbonChat,
|
||||
final PrimaryConfig primaryConfig
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.primaryConfig = primaryConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(final PlayerStatusMessageEvents.MessageEvent 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().getUUID()).join();
|
||||
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CarbonPlayer player = result.player();
|
||||
|
||||
if (!player.muteEntries().isEmpty()) {
|
||||
event.disableMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.fabric.listeners;
|
||||
|
||||
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.common.config.PrimaryConfig;
|
||||
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class FabricPlayerJoinListener implements PlayerStatusMessageEvents.MessageEventListener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final PrimaryConfig primaryConfig;
|
||||
|
||||
@Inject
|
||||
public FabricPlayerJoinListener(
|
||||
final CarbonChat carbonChat,
|
||||
final PrimaryConfig primaryConfig
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.primaryConfig = primaryConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(final PlayerStatusMessageEvents.MessageEvent event) {
|
||||
final ComponentPlayerResult<CarbonPlayer> result =
|
||||
this.carbonChat.server().player(event.player().getUUID()).join();
|
||||
final @Nullable CarbonPlayer player = result.player();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't show join messages when muted
|
||||
if (this.primaryConfig.hideMutedJoinLeaveQuit() && !player.muteEntries().isEmpty()) {
|
||||
event.disableMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.fabric.listeners;
|
||||
|
||||
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.fabric.callback.PlayerStatusMessageEvents;
|
||||
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class FabricPlayerLeaveListener implements PlayerStatusMessageEvents.MessageEventListener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final PrimaryConfig primaryConfig;
|
||||
private final UserManager<CarbonPlayerCommon> userManager;
|
||||
|
||||
@Inject
|
||||
public FabricPlayerLeaveListener(
|
||||
final CarbonChat carbonChat,
|
||||
final PrimaryConfig primaryConfig,
|
||||
final UserManager<CarbonPlayerCommon> userManager
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.primaryConfig = primaryConfig;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(final PlayerStatusMessageEvents.MessageEvent event) {
|
||||
final ComponentPlayerResult<CarbonPlayer> result =
|
||||
this.carbonChat.server().player(event.player().getUUID()).join();
|
||||
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CarbonPlayer player = result.player();
|
||||
|
||||
if (this.primaryConfig.hideMutedJoinLeaveQuit()) {
|
||||
if (!player.muteEntries().isEmpty()) {
|
||||
event.disableMessage();
|
||||
}
|
||||
}
|
||||
|
||||
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerFabric) player);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user