mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Change punishment from kicking to muting on spam (FS-97) (#45)
This commit is contained in:
parent
2cdf1e66a6
commit
b9f7ab3ec3
@ -1,7 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import me.totalfreedom.totalfreedommod.util.FSync;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
@ -11,10 +10,12 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AntiSpam extends FreedomService
|
||||
{
|
||||
|
||||
@ -22,7 +23,7 @@ public class AntiSpam extends FreedomService
|
||||
public static final int TICKS_PER_CYCLE = 2 * 10;
|
||||
//
|
||||
public BukkitTask cycleTask = null;
|
||||
List<Player> markedForDeath = new ArrayList<>();
|
||||
private Map<Player, Integer> muteCounts = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
@ -67,23 +68,26 @@ public class AntiSpam extends FreedomService
|
||||
return;
|
||||
}
|
||||
|
||||
String message = event.getMessage().trim();
|
||||
|
||||
final FPlayer playerdata = plugin.pl.getPlayerSync(player);
|
||||
int count = muteCounts.getOrDefault(player, 0);
|
||||
int minutes = ConfigEntry.ANTISPAM_MINUTES.getInteger();
|
||||
|
||||
// Check for spam
|
||||
if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE)
|
||||
if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE && !playerdata.isMuted())
|
||||
{
|
||||
if (!markedForDeath.contains(player))
|
||||
{
|
||||
markedForDeath.add(player);
|
||||
FSync.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
|
||||
FSync.autoEject(player, "Kicked for spamming chat.");
|
||||
count++;
|
||||
muteCounts.put(player, count);
|
||||
|
||||
playerdata.resetMsgCount();
|
||||
int time = count * minutes;
|
||||
playerdata.setMuted(true, time);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
FSync.bcastMsg(String.format("%s has automatically been muted for %d minutes for spamming chat.",
|
||||
player.getName(),
|
||||
time),
|
||||
ChatColor.RED);
|
||||
|
||||
playerdata.resetMsgCount();
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else if (playerdata.incrementAndGetMsgCount() > MSG_PER_CYCLE / 2)
|
||||
{
|
||||
@ -122,10 +126,4 @@ public class AntiSpam extends FreedomService
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerKick(PlayerKickEvent event)
|
||||
{
|
||||
markedForDeath.remove(event.getPlayer());
|
||||
}
|
||||
}
|
@ -163,7 +163,8 @@ public enum ConfigEntry
|
||||
MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"),
|
||||
AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"),
|
||||
TOGGLE_CHAT(Boolean.class, "toggle_chat"),
|
||||
DEVELOPER_MODE(Boolean.class, "developer_mode");
|
||||
DEVELOPER_MODE(Boolean.class, "developer_mode"),
|
||||
ANTISPAM_MINUTES(Integer.class, "antispam_minutes");
|
||||
//
|
||||
private final Class<?> type;
|
||||
private final String configName;
|
||||
|
@ -289,7 +289,7 @@ public class FPlayer
|
||||
return unmuteTask != null;
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted)
|
||||
public void setMuted(boolean muted, int minutes)
|
||||
{
|
||||
FUtil.cancel(unmuteTask);
|
||||
plugin.mu.MUTED_PLAYERS.remove(getPlayer().getName());
|
||||
@ -324,7 +324,12 @@ public class FPlayer
|
||||
plugin.mu.MUTED_PLAYERS.remove(getName());
|
||||
}
|
||||
}
|
||||
}.runTaskLater(plugin, AUTO_PURGE_TICKS);
|
||||
}.runTaskLater(plugin, minutes * (60L * 20L));
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted)
|
||||
{
|
||||
setMuted(muted, 5);
|
||||
}
|
||||
|
||||
public BukkitTask getLockupScheduleID()
|
||||
|
@ -738,3 +738,6 @@ blocked_chatcodes: '&0,&k,&m,&n'
|
||||
|
||||
# Enables certain things like debug logs and console bypasses
|
||||
developer_mode: false
|
||||
|
||||
# AntiSpam Time (minutes)
|
||||
antispam_minutes: 2
|
||||
|
Loading…
Reference in New Issue
Block a user