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;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
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", ","));
|
2018-03-18 08:32:50 +00:00
|
|
|
public final List<String> MUTED_PLAYERS = new ArrayList();
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
public Muter(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-03-18 08:32:50 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSync.playerMsg(event.getPlayer(), ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes.");
|
|
|
|
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();
|
2015-11-15 23:32:04 +00:00
|
|
|
if (plugin.al.isAdmin(player))
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
}
|