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

@@ -1,65 +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.bukkit.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.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class BukkitPlayerDeathListener implements Listener {
private final CarbonChat carbonChat;
private final ConfigFactory configFactory;
@Inject
public BukkitPlayerDeathListener(final CarbonChat carbonChat, final ConfigFactory configFactory) {
this.carbonChat = carbonChat;
this.configFactory = configFactory;
}
@EventHandler
public void onPlayerDeath(final PlayerDeathEvent 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.getEntity().getUniqueId()).join();
if (result.player() == null) {
return;
}
final CarbonPlayer player = result.player();
if (player.muted()) {
event.deathMessage(null);
}
}
}
@@ -21,78 +21,41 @@ package net.draycia.carbon.bukkit.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.bukkit.users.CarbonPlayerBukkit;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.util.PlayerUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
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 BukkitPlayerJoinListener implements Listener {
private final CarbonChat carbonChat;
private final ConfigFactory configFactory;
private final UserManager<CarbonPlayerCommon> userManager;
@Inject
public BukkitPlayerJoinListener(
final CarbonChat carbonChat,
final ConfigFactory configFactory,
final UserManager<CarbonPlayerCommon> userManager
) {
this.carbonChat = carbonChat;
this.configFactory = configFactory;
this.userManager = userManager;
}
@EventHandler(priority = EventPriority.LOWEST)
public void handleJoinMessages(final PlayerJoinEvent event) {
if (!this.configFactory.primaryConfig().hideMutedJoinLeaveQuit()) {
return;
}
final ComponentPlayerResult<CarbonPlayer> result =
this.carbonChat.server().player(event.getPlayer().getUniqueId()).join();
final @Nullable CarbonPlayer player = result.player();
if (player == null) {
return;
}
// Don't show join messages when muted
if (player.muted()) {
event.joinMessage(null);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(final PlayerQuitEvent event) {
final ComponentPlayerResult<CarbonPlayer> result =
this.carbonChat.server().player(event.getPlayer().getUniqueId()).join();
if (result.player() == null) {
return;
}
final CarbonPlayer player = result.player();
if (this.configFactory.primaryConfig().hideMutedJoinLeaveQuit()) {
if (player.muted()) {
event.quitMessage(null);
this.carbonChat.server().player(event.getPlayer().getUniqueId()).thenAccept(result -> {
if (result.player() == null) {
return;
}
}
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerBukkit) player);
PlayerUtils.saveAndInvalidatePlayer(this.carbonChat.server(), this.userManager, (CarbonPlayerBukkit) result.player());
});
}
}