2015-11-15 23:32:04 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
2018-03-18 08:32:50 +00:00
|
|
|
import java.util.ArrayList;
|
2015-11-15 23:32:04 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FSync;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
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;
|
2018-03-18 08:32:50 +00:00
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
2015-11-15 23:32:04 +00:00
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class Muter extends FreedomService
|
2015-11-15 23:32:04 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
public static final List<String> MUTE_COMMANDS = Arrays.asList(StringUtils.split("say,me,msg,tell,reply,mail", ","));
|
2020-07-01 01:51:06 +00:00
|
|
|
public final List<String> MUTED_PLAYERS = new ArrayList<>();
|
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);
|
2018-03-18 08:32:50 +00:00
|
|
|
MUTED_PLAYERS.remove(player.getName());
|
2015-11-15 23:32:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-23 11:18:03 +00:00
|
|
|
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "You are muted.");
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MUTE_COMMANDS.contains(cmdName))
|
|
|
|
{
|
|
|
|
player.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 08:32:50 +00:00
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event)
|
|
|
|
{
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
FPlayer playerdata = plugin.pl.getPlayer(player);
|
|
|
|
|
|
|
|
if (MUTED_PLAYERS.contains(player.getName()))
|
|
|
|
{
|
|
|
|
playerdata.setMuted(true);
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|