This commit is contained in:
Telesphoreo 2022-05-19 20:34:43 -05:00
parent f97649083a
commit b39ba8ed86
2 changed files with 54 additions and 3 deletions

View file

@ -1,22 +1,65 @@
package dev.plex.listener.impl;
import dev.plex.cache.DataUtils;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import io.papermc.paper.event.player.AsyncChatEvent;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class MuteListener extends PlexListener
{
List<String> commands = plugin.commands.getStringList("block_on_mute");
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncChatEvent event)
{
if (DataUtils.getPlayer(event.getPlayer().getUniqueId()).isMuted())
if (plugin.getPlayerCache().getPlexPlayer(event.getPlayer().getUniqueId()).isMuted())
{
event.getPlayer().sendMessage(PlexUtils.messageComponent("muted"));
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onCommand(PlayerCommandPreprocessEvent event)
{
if (plugin.getPlayerCache().getPlexPlayer(event.getPlayer().getUniqueId()).isMuted())
{
String message = event.getMessage();
// Don't check the arguments
message = message.replaceAll("\\s.*", "").replaceFirst("/", "");
PlexLog.debug("message: " + message);
// Check regular command
if (commands.contains(message.toLowerCase()))
{
PlexLog.debug("Matches command");
event.getPlayer().sendMessage(PlexUtils.messageComponent("muted"));
event.setCancelled(true);
return;
}
for (String command : commands)
{
Command cmd = Bukkit.getCommandMap().getCommand(command);
if (cmd == null)
{
PlexLog.debug("Null command");
return;
}
if (cmd.getAliases().contains(message.toLowerCase()))
{
PlexLog.debug("Matches alias");
event.getPlayer().sendMessage(PlexUtils.messageComponent("muted"));
event.setCancelled(true);
return;
}
}
}
}
}

View file

@ -52,4 +52,12 @@ commands:
- "m:e:weather:_"
- "m:e:worldborder:<gray>The worldborder does not need to be changed. This command is disabled."
- "r:a:^(co|core|coreprotect) (rb|rollback|l|lookup|rl|reload):_"
- "r:e:^[A-z]*:[A-z]*::<gray>Plugin specific commands are disabled."
- "r:e:^[A-z]*:[A-z]*::<gray>Plugin specific commands are disabled."
# These commands will be blocked when a player is muted
block_on_mute:
- me
- say
- msg
- reply
- mail