mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-04 23:07:44 +01:00
[Development] Oups... ChatListener wasn't finished.
This commit is contained in:
parent
3d88aed041
commit
40bf2a171a
@ -35,6 +35,8 @@ import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
* This is the main class of NoCheatPlus. The commands, events listeners and tasks are registered here.
|
||||
*/
|
||||
public class NoCheatPlus extends JavaPlugin implements Listener {
|
||||
public static long time = System.currentTimeMillis();
|
||||
|
||||
private List<Listener> listeners;
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -8,6 +8,7 @@ import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckEvent;
|
||||
@ -56,12 +57,17 @@ public class Arrivals extends Check {
|
||||
public boolean check(final Player player) {
|
||||
final ChatConfig cc = ChatConfig.getConfig(player);
|
||||
|
||||
// If the server has just restarted or if the player is a regular one, do not check it.
|
||||
if (System.currentTimeMillis() - NoCheatPlus.time < 120000L
|
||||
|| System.currentTimeMillis() - player.getFirstPlayed() > cc.arrivalsJoinsLimit)
|
||||
return false;
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
// Remove the old data from the map holding the joins.
|
||||
final List<Long> toRemove = new ArrayList<Long>();
|
||||
for (final long time : joins.keySet())
|
||||
// If the data is too old or belong the checked player.
|
||||
// If the data is too old or belong to the checked player.
|
||||
if (System.currentTimeMillis() - time > cc.arrivalsTimeLimit && joins.get(time).equals(player.getName()))
|
||||
toRemove.add(time);
|
||||
for (final long time : toRemove)
|
||||
|
@ -62,6 +62,7 @@ public class ChatConfig {
|
||||
|
||||
public final boolean noPwnageCheck;
|
||||
public final int noPwnageLevel;
|
||||
public final String noPwnageKickMessage;
|
||||
|
||||
public final boolean noPwnageBannedCheck;
|
||||
public final long noPwnageBannedTimeout;
|
||||
@ -88,6 +89,7 @@ public class ChatConfig {
|
||||
public final int noPwnageMoveWeightMalus;
|
||||
|
||||
public final boolean noPwnageReloginCheck;
|
||||
public final String noPwnageReloginKickMessage;
|
||||
public final long noPwnageReloginTimeout;
|
||||
public final String noPwnageReloginWarningMessage;
|
||||
public final int noPwnageReloginWarningNumber;
|
||||
@ -110,6 +112,8 @@ public class ChatConfig {
|
||||
|
||||
public final ActionList noPwnageActions;
|
||||
|
||||
public final boolean protectPlugins;
|
||||
|
||||
/**
|
||||
* Instantiates a new chat configuration.
|
||||
*
|
||||
@ -128,6 +132,7 @@ public class ChatConfig {
|
||||
|
||||
noPwnageCheck = data.getBoolean(ConfPaths.CHAT_NOPWNAGE_CHECK);
|
||||
noPwnageLevel = data.getInt(ConfPaths.CHAT_NOPWNAGE_LEVEL);
|
||||
noPwnageKickMessage = data.getString(ConfPaths.CHAT_NOPWNAGE_KICKMESSAGE);
|
||||
|
||||
noPwnageBannedCheck = data.getBoolean(ConfPaths.CHAT_NOPWNAGE_BANNED_CHECK);
|
||||
noPwnageBannedTimeout = data.getLong(ConfPaths.CHAT_NOPWNAGE_BANNED_TIMEOUT);
|
||||
@ -154,6 +159,7 @@ public class ChatConfig {
|
||||
noPwnageMoveWeightMalus = data.getInt(ConfPaths.CHAT_NOPWNAGE_MOVE_WEIGHT_MALUS);
|
||||
|
||||
noPwnageReloginCheck = data.getBoolean(ConfPaths.CHAT_NOPWNAGE_RELOGIN_CHECK);
|
||||
noPwnageReloginKickMessage = data.getString(ConfPaths.CHAT_NOPWNAGE_RELOGIN_KICKMESSAGE);
|
||||
noPwnageReloginTimeout = data.getLong(ConfPaths.CHAT_NOPWNAGE_RELOGIN_TIMEOUT);
|
||||
noPwnageReloginWarningMessage = data.getString(ConfPaths.CHAT_NOPWNAGE_RELOGIN_WARNING_MESSAGE);
|
||||
noPwnageReloginWarningNumber = data.getInt(ConfPaths.CHAT_NOPWNAGE_RELOGIN_WARNING_NUMBER);
|
||||
@ -175,5 +181,7 @@ public class ChatConfig {
|
||||
noPwnageWarnPlayerMessage = data.getString(ConfPaths.CHAT_NOPWNAGE_WARN_PLAYER_MESSAGE);
|
||||
|
||||
noPwnageActions = data.getActionList(ConfPaths.CHAT_NOPWNAGE_ACTIONS, Permissions.CHAT_NOPWNAGE);
|
||||
|
||||
protectPlugins = data.getBoolean(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,17 @@
|
||||
package fr.neatmonster.nocheatplus.checks.chat;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
/*
|
||||
* MM'""""'YMM dP dP M""MMMMMMMM oo dP
|
||||
@ -15,5 +26,106 @@ import org.bukkit.event.Listener;
|
||||
* Central location to listen to events that are relevant for the chat checks.
|
||||
*/
|
||||
public class ChatListener implements Listener {
|
||||
private final Arrivals arrivals = new Arrivals();
|
||||
private final Color color = new Color();
|
||||
private final NoPwnage noPwnage = new NoPwnage();
|
||||
|
||||
/**
|
||||
* We listen to PlayerChat events for obvious reasons.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
*/
|
||||
@EventHandler(
|
||||
ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerChat(final PlayerChatEvent event) {
|
||||
/*
|
||||
* ____ _ ____ _ _
|
||||
* | _ \| | __ _ _ _ ___ _ __ / ___| |__ __ _| |_
|
||||
* | |_) | |/ _` | | | |/ _ \ '__| | | | '_ \ / _` | __|
|
||||
* | __/| | (_| | |_| | __/ | | |___| | | | (_| | |_
|
||||
* |_| |_|\__,_|\__, |\___|_| \____|_| |_|\__,_|\__|
|
||||
* |___/
|
||||
*/
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// First the color check.
|
||||
if (color.isEnabled(player))
|
||||
event.setMessage(color.check(player, event.getMessage()));
|
||||
|
||||
// Then the no pwnage check.
|
||||
if (noPwnage.isEnabled(player) && noPwnage.check(player))
|
||||
player.kickPlayer(Check.removeColors(ChatConfig.getConfig(player).noPwnageKickMessage));
|
||||
}
|
||||
|
||||
/**
|
||||
* We listen to PlayerCommandPreprocess events because commands can be used for spamming too.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.LOWEST)
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
/*
|
||||
* ____ _ ____ _
|
||||
* | _ \| | __ _ _ _ ___ _ __ / ___|___ _ __ ___ _ __ ___ __ _ _ __ __| |
|
||||
* | |_) | |/ _` | | | |/ _ \ '__| | | / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |
|
||||
* | __/| | (_| | |_| | __/ | | |__| (_) | | | | | | | | | | | (_| | | | | (_| |
|
||||
* |_| |_|\__,_|\__, |\___|_| \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|
|
||||
* |___/
|
||||
* ____
|
||||
* | _ \ _ __ ___ _ __ _ __ ___ ___ ___ ___ ___
|
||||
* | |_) | '__/ _ \ '_ \| '__/ _ \ / __/ _ \/ __/ __|
|
||||
* | __/| | | __/ |_) | | | (_) | (_| __/\__ \__ \
|
||||
* |_| |_| \___| .__/|_| \___/ \___\___||___/___/
|
||||
* |_|
|
||||
*/
|
||||
final Player player = event.getPlayer();
|
||||
final String command = event.getMessage().split(" ")[0].substring(1).toLowerCase();
|
||||
|
||||
// Protect some commands to prevent players for seeing which plugins are installed.
|
||||
if (ChatConfig.getConfig(player).protectPlugins
|
||||
&& (command.equals("plugins") || command.equals("pl") || command.equals("?"))
|
||||
&& !player.hasPermission(Permissions.ADMINISTRATION_PLUGINS)) {
|
||||
event.getPlayer().sendMessage(
|
||||
ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. "
|
||||
+ "Please contact the server administrators if you believe that this is in error.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// This type of event is derived from PlayerChatEvent, therefore just treat it like that.
|
||||
onPlayerChat(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* We listen to this type of events to prevent spambots from login to the server.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.LOWEST)
|
||||
public void onPlayerLogin(final PlayerLoginEvent event) {
|
||||
/*
|
||||
* ____ _ _ _
|
||||
* | _ \| | __ _ _ _ ___ _ __ | | ___ (_)_ __
|
||||
* | |_) | |/ _` | | | |/ _ \ '__| _ | |/ _ \| | '_ \
|
||||
* | __/| | (_| | |_| | __/ | | |_| | (_) | | | | |
|
||||
* |_| |_|\__,_|\__, |\___|_| \___/ \___/|_|_| |_|
|
||||
* |___/
|
||||
*/
|
||||
final Player player = event.getPlayer();
|
||||
final ChatConfig cc = ChatConfig.getConfig(player);
|
||||
|
||||
// First the arrivals check, if enabled of course.
|
||||
if (arrivals.isEnabled(player) && arrivals.check(player))
|
||||
// The player failed the check, disallow the login.
|
||||
event.disallow(Result.KICK_OTHER, cc.arrivalsMessage);
|
||||
|
||||
// Then the no pwnage check, if the login isn't already disallowed.
|
||||
if (event.getResult() != Result.KICK_OTHER && noPwnage.isEnabled(player) && noPwnage.check(player))
|
||||
event.disallow(Result.KICK_OTHER, cc.noPwnageReloginKickMessage);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.Random;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
@ -126,7 +127,7 @@ public class NoPwnage extends Check {
|
||||
|
||||
if (!data.noPwnageHasFilledCaptcha) {
|
||||
final String message = event.getMessage();
|
||||
final boolean isCommand = message.startsWith("/");
|
||||
final boolean isCommand = event instanceof PlayerCommandPreprocessEvent;
|
||||
final long now = System.currentTimeMillis();
|
||||
|
||||
if (cc.noPwnageCaptchaCheck && data.noPwnageHasStartedCaptcha) {
|
||||
|
@ -121,6 +121,7 @@ public abstract class ConfPaths {
|
||||
private static final String CHAT_NOPWNAGE = CHAT + "nopwnage.";
|
||||
public static final String CHAT_NOPWNAGE_CHECK = CHAT_NOPWNAGE + "active";
|
||||
public static final String CHAT_NOPWNAGE_LEVEL = CHAT_NOPWNAGE + "level";
|
||||
public static final String CHAT_NOPWNAGE_KICKMESSAGE = CHAT_NOPWNAGE + "kickmessage";
|
||||
|
||||
private static final String CHAT_NOPWNAGE_BANNED = CHAT_NOPWNAGE + "banned.";
|
||||
public static final String CHAT_NOPWNAGE_BANNED_CHECK = CHAT_NOPWNAGE_BANNED + "active";
|
||||
@ -153,6 +154,7 @@ public abstract class ConfPaths {
|
||||
|
||||
private static final String CHAT_NOPWNAGE_RELOGIN = CHAT_NOPWNAGE + "relogin.";
|
||||
public static final String CHAT_NOPWNAGE_RELOGIN_CHECK = CHAT_NOPWNAGE_RELOGIN + "active";
|
||||
public static final String CHAT_NOPWNAGE_RELOGIN_KICKMESSAGE = CHAT_NOPWNAGE_RELOGIN + "kickmessage";
|
||||
public static final String CHAT_NOPWNAGE_RELOGIN_TIMEOUT = CHAT_NOPWNAGE_RELOGIN + "timeout";
|
||||
|
||||
private static final String CHAT_NOPWNAGE_RELOGIN_WARNING = CHAT_NOPWNAGE_RELOGIN + "warning.";
|
||||
|
@ -111,6 +111,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
|
||||
set(ConfPaths.CHAT_NOPWNAGE_CHECK, true);
|
||||
set(ConfPaths.CHAT_NOPWNAGE_LEVEL, 800);
|
||||
set(ConfPaths.CHAT_NOPWNAGE_KICKMESSAGE, "You're not allowed to spam this server!");
|
||||
|
||||
set(ConfPaths.CHAT_NOPWNAGE_BANNED_CHECK, true);
|
||||
set(ConfPaths.CHAT_NOPWNAGE_BANNED_TIMEOUT, 5000L);
|
||||
@ -144,6 +145,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.CHAT_NOPWNAGE_RELOGIN_WARNING_MESSAGE,
|
||||
"&cYou relogged really fast! If you keep doing that, you're going to be banned.");
|
||||
set(ConfPaths.CHAT_NOPWNAGE_RELOGIN_WARNING_NUMBER, 1);
|
||||
set(ConfPaths.CHAT_NOPWNAGE_RELOGIN_KICKMESSAGE, "Please try again later!");
|
||||
set(ConfPaths.CHAT_NOPWNAGE_RELOGIN_WARNING_TIMEOUT, 60000L);
|
||||
|
||||
set(ConfPaths.CHAT_NOPWNAGE_REPEAT_CHECK, true);
|
||||
|
@ -24,6 +24,7 @@ public class Permissions {
|
||||
*/
|
||||
private static final String ADMINISTRATION = NOCHEATPLUS + ".admin";
|
||||
public static final String ADMINISTRATION_NOTIFY = ADMINISTRATION + ".notify";
|
||||
public static final String ADMINISTRATION_PLUGINS = ADMINISTRATION + ".plugins";
|
||||
public static final String ADMINISTRATION_RELOAD = ADMINISTRATION + ".reload";
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user