mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Remove hide-muted-player-join-messages
This commit is contained in:
11 files changed
+22
-385
No files matched your search
@@ -40,7 +40,6 @@ 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.sponge.listeners.SpongeChatListener;
|
||||
import net.draycia.carbon.sponge.listeners.SpongePlayerDeathListener;
|
||||
import net.draycia.carbon.sponge.listeners.SpongePlayerJoinListener;
|
||||
import net.draycia.carbon.sponge.listeners.SpongeReloadListener;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -64,7 +63,7 @@ import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
public final class CarbonChatSponge implements CarbonChat {
|
||||
|
||||
private static final Set<Class<?>> LISTENER_CLASSES = Set.of(SpongeChatListener.class,
|
||||
SpongePlayerDeathListener.class, SpongePlayerJoinListener.class, SpongeReloadListener.class);
|
||||
SpongePlayerJoinListener.class, SpongeReloadListener.class);
|
||||
|
||||
private static final int BSTATS_PLUGIN_ID = 11279;
|
||||
|
||||
|
||||
-66
@@ -1,66 +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.sponge.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 org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.entity.DestructEntityEvent;
|
||||
import org.spongepowered.api.event.filter.cause.First;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class SpongePlayerDeathListener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final ConfigFactory configFactory;
|
||||
|
||||
@Inject
|
||||
public SpongePlayerDeathListener(final CarbonChat carbonChat, final ConfigFactory configFactory) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.configFactory = configFactory;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerDeath(final DestructEntityEvent.Death event, final @First Player player) {
|
||||
// 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(player.uniqueId()).join();
|
||||
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CarbonPlayer carbonPlayer = result.player();
|
||||
|
||||
if (carbonPlayer.muted()) {
|
||||
event.setMessageCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+5
-41
@@ -21,16 +21,11 @@ package net.draycia.carbon.sponge.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.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;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.network.ServerSideConnectionEvent;
|
||||
@@ -39,57 +34,26 @@ import org.spongepowered.api.event.network.ServerSideConnectionEvent;
|
||||
public class SpongePlayerJoinListener {
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final ConfigFactory configFactory;
|
||||
private final UserManager<CarbonPlayerCommon> userManager;
|
||||
|
||||
@Inject
|
||||
public SpongePlayerJoinListener(
|
||||
final CarbonChat carbonChat,
|
||||
final ConfigFactory configFactory,
|
||||
final UserManager<CarbonPlayerCommon> userManager
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.configFactory = configFactory;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerLogin(final ServerSideConnectionEvent.Join event) {
|
||||
if (!this.configFactory.primaryConfig().hideMutedJoinLeaveQuit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ComponentPlayerResult<CarbonPlayer> result = this.carbonChat.server().player(event.player().uniqueId()).join();
|
||||
final @Nullable CarbonPlayer player = result.player();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't show join messages when muted
|
||||
if (player.muted()) {
|
||||
event.setMessageCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPlayerQuit(final ServerSideConnectionEvent.Disconnect event) {
|
||||
final ComponentPlayerResult<CarbonPlayer> result =
|
||||
this.carbonChat.server().player(event.player().uniqueId()).join();
|
||||
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CarbonPlayer player = result.player();
|
||||
|
||||
if (this.configFactory.primaryConfig().hideMutedJoinLeaveQuit()) {
|
||||
if (player.muted()) {
|
||||
event.setAudience(Audience.empty());
|
||||
this.carbonChat.server().player(event.player().uniqueId()).thenAccept(result -> {
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerSponge) player);
|
||||
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerSponge) result.player());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user