Remove hide-muted-player-join-messages

This commit is contained in:
Draycia committed 2021-12-10 14:10:49 -08:00
1 parent 9a3416c57b
commit 2e392c2ed9
11 files changed
+22 -385

No files matched your search

@@ -41,8 +41,6 @@ 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;
@@ -119,9 +117,7 @@ public final class CarbonChatFabric implements ModInitializer, CarbonChat {
}
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() {
@@ -1,63 +0,0 @@
/*
* 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.ConfigFactory;
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 ConfigFactory configFactory;
@Inject
public FabricPlayerDeathListener(final CarbonChat carbonChat, final ConfigFactory configFactory) {
this.carbonChat = carbonChat;
this.configFactory = configFactory;
}
@Override
public void onMessage(final PlayerStatusMessageEvents.MessageEvent event) {
// Early exit in case "hide muted join / leave messages when muted" is disabled
if (!this.configFactory.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.muted()) {
event.disableMessage();
}
}
}
@@ -1,64 +0,0 @@
/*
* 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.ConfigFactory;
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 ConfigFactory configFactory;
@Inject
public FabricPlayerJoinListener(final CarbonChat carbonChat, final ConfigFactory configFactory) {
this.carbonChat = carbonChat;
this.configFactory = configFactory;
}
@Override
public void onMessage(final PlayerStatusMessageEvents.MessageEvent event) {
if (!this.configFactory.primaryConfig().hideMutedJoinLeaveQuit()) {
return;
}
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 (player.muted()) {
event.disableMessage();
}
}
}
@@ -21,10 +21,7 @@ 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.ConfigFactory;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.util.PlayerUtils;
import net.draycia.carbon.fabric.callback.PlayerStatusMessageEvents;
@@ -36,38 +33,26 @@ import org.checkerframework.framework.qual.DefaultQualifier;
public class FabricPlayerLeaveListener implements PlayerStatusMessageEvents.MessageEventListener {
private final CarbonChat carbonChat;
private final ConfigFactory configFactory;
private final UserManager<CarbonPlayerCommon> userManager;
@Inject
public FabricPlayerLeaveListener(
final CarbonChat carbonChat,
final ConfigFactory configFactory,
final UserManager<CarbonPlayerCommon> userManager
) {
this.carbonChat = carbonChat;
this.configFactory = configFactory;
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.configFactory.primaryConfig().hideMutedJoinLeaveQuit()) {
if (player.muted()) {
event.disableMessage();
this.carbonChat.server().player(event.player().getUUID()).thenAccept(result -> {
if (result.player() == null) {
return;
}
}
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerFabric) player);
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerFabric) result.player());
});
}
}