Fixed muting server
This commit is contained in:
parent
321255eaa1
commit
c1a51dc803
|
|
@ -3,7 +3,9 @@ package com.alttd.chat.commands;
|
|||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -16,19 +18,28 @@ public class MuteServer implements CommandExecutor {
|
|||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = ((Player) sender).getUniqueId();
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!Utility.hasPermission(uuid, Config.SERVERMUTEPERMISSION)) {
|
||||
sender.sendMessage(MiniMessage.get().parse("<red>You don't have permission to use this command.</red>"));
|
||||
return;
|
||||
}
|
||||
|
||||
ChatPlugin.getInstance().toggleServerMuted();
|
||||
sender.sendMessage(MiniMessage.get().parse("You have " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>muted</green>" : "<red>unmuted</red>") + " chat for this server.")); // TODO load from config and minimessage
|
||||
|
||||
Component component;
|
||||
if (ChatPlugin.getInstance().serverMuted()) {
|
||||
component = MiniMessage.get().parse(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
|
||||
} else {
|
||||
component = MiniMessage.get().parse(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <green>un-muted</green><white> chat.");
|
||||
}
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.sendMessage(component));
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -77,13 +77,14 @@ public class ChatHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Database.get().isPlayerMuted(player.getUniqueId(), null) || ChatPlugin.getInstance().serverMuted()) {
|
||||
if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
|
||||
MiniMessage miniMessage = MiniMessage.get();
|
||||
Component blockedNotification = miniMessage.parse("<red>[GC Muted] "
|
||||
+ Utility.getDisplayName(player.getUniqueId(), player.getName())
|
||||
+ " tried to say: "
|
||||
+ message + "</red>");
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
Component blockedNotification = miniMessage.parse("<red>[GC Muted] "
|
||||
+ Utility.getDisplayName(player.getUniqueId(), player.getName())
|
||||
+ " tried to say: "
|
||||
+ message + "</red>");
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.alttd.chat.listeners;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.handler.ChatHandler;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
|
|
@ -9,11 +10,13 @@ import com.alttd.chat.util.GalaxyUtility;
|
|||
import com.alttd.chat.util.Utility;
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import litebans.api.Database;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
|
@ -26,6 +29,25 @@ public class ChatListener implements Listener, ChatRenderer {
|
|||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncChatEvent event) {
|
||||
|
||||
if (ChatPlugin.getInstance().serverMuted() && !event.getPlayer().hasPermission("chat.bypass-server-muted")) {
|
||||
event.setCancelled(true);
|
||||
|
||||
Player player = event.getPlayer();
|
||||
MiniMessage miniMessage = MiniMessage.get();
|
||||
Component blockedNotification = miniMessage.parse("<red>[Chat Muted] "
|
||||
+ Utility.getDisplayName(player.getUniqueId(), player.getName())
|
||||
+ " tried to say: "
|
||||
+ PlainComponentSerializer.plain().serialize(event.message()) + "</red>");
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);//TODO make configurable (along with all the messages)
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user