2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FSync;
|
2022-11-21 05:57:31 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2016-05-12 19:40:39 +00:00
|
|
|
import org.bukkit.command.Command;
|
2015-11-15 23:32:04 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class Muter extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
@EventHandler(priority = EventPriority.HIGHEST)
|
2015-11-15 23:32:04 +00:00
|
|
|
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
|
|
|
|
{
|
2018-03-18 08:32:50 +00:00
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
FPlayer fPlayer = plugin.pl.getPlayerSync(player);
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
if (!fPlayer.isMuted())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isAdminSync(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
fPlayer.setMuted(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-21 05:57:31 +00:00
|
|
|
player.sendMessage(Component.text("You are muted.", NamedTextColor.RED));
|
2015-11-15 23:32:04 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
FPlayer fPlayer = plugin.pl.getPlayer(event.getPlayer());
|
|
|
|
|
|
|
|
// Block commands if player is muted
|
|
|
|
if (!fPlayer.isMuted())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
String message = event.getMessage();
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isAdmin(player))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
|
|
|
fPlayer.setMuted(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
String cmdName = message.split(" ")[0].toLowerCase();
|
|
|
|
if (cmdName.startsWith("/"))
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
cmdName = cmdName.substring(1);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
Command command = server.getPluginCommand(cmdName);
|
|
|
|
if (command != null)
|
|
|
|
{
|
|
|
|
cmdName = command.getName().toLowerCase();
|
|
|
|
}
|
|
|
|
|
2021-05-09 15:42:31 +00:00
|
|
|
if (ConfigEntry.MUTED_BLOCKED_COMMANDS.getStringList().contains(cmdName))
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2022-11-21 05:57:31 +00:00
|
|
|
player.sendMessage(Component.text("That command is blocked while you are muted.", NamedTextColor.RED));
|
2016-05-12 19:40:39 +00:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Should this go here?
|
2015-11-15 23:32:04 +00:00
|
|
|
if (ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean())
|
|
|
|
{
|
2016-05-12 19:40:39 +00:00
|
|
|
FLog.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), message), true);
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|