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