mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Resolves #33
This commit is contained in:
parent
f97649083a
commit
b39ba8ed86
@ -1,22 +1,65 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
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.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
public class MuteListener extends PlexListener
|
public class MuteListener extends PlexListener
|
||||||
{
|
{
|
||||||
|
List<String> commands = plugin.commands.getStringList("block_on_mute");
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onChat(AsyncChatEvent event)
|
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.getPlayer().sendMessage(PlexUtils.messageComponent("muted"));
|
||||||
event.setCancelled(true);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,3 +53,11 @@ commands:
|
|||||||
- "m:e:worldborder:<gray>The worldborder does not need to be changed. This command is disabled."
|
- "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: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
|
Loading…
Reference in New Issue
Block a user