mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-28 02:21:30 +01:00
Move the antibot management
This commit is contained in:
parent
489708b206
commit
cc8401e841
101
src/main/java/fr/xephi/authme/AntiBot.java
Normal file
101
src/main/java/fr/xephi/authme/AntiBot.java
Normal file
@ -0,0 +1,101 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
/**
|
||||
* The AntiBot Service Management class.
|
||||
*/
|
||||
public class AntiBot {
|
||||
|
||||
public enum AntiBotStatus {
|
||||
ARMED,
|
||||
DISARMED,
|
||||
DELAYED,
|
||||
ACTIVATED
|
||||
}
|
||||
|
||||
private static AntiBotStatus antiBotStatus = AntiBotStatus.DISARMED;
|
||||
private static final AuthMe plugin = AuthMe.getInstance();
|
||||
private static final Messages messages = plugin.getMessages();
|
||||
private static final List<String> antibotPlayers = new ArrayList<>();
|
||||
|
||||
public static void setupAntiBotService() {
|
||||
if (!Settings.enableAntiBot) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
antiBotStatus = AntiBotStatus.ARMED;
|
||||
}
|
||||
}, 2400);
|
||||
}
|
||||
|
||||
public static void switchAntiBotStatus(boolean activated) {
|
||||
if(antiBotStatus == AntiBotStatus.DISARMED || antiBotStatus == AntiBotStatus.DELAYED) {
|
||||
return;
|
||||
}
|
||||
if(activated) {
|
||||
antiBotStatus = AntiBotStatus.ACTIVATED;
|
||||
} else {
|
||||
antiBotStatus = AntiBotStatus.ARMED;
|
||||
}
|
||||
}
|
||||
|
||||
public static AntiBotStatus getAntiBotStatus() {
|
||||
return antiBotStatus;
|
||||
}
|
||||
|
||||
public static void activateAntiBot() {
|
||||
antiBotStatus = AntiBotStatus.ACTIVATED;
|
||||
for (String s : messages.send("antibot_auto_enabled")) {
|
||||
Bukkit.broadcastMessage(s);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (antiBotStatus == AntiBotStatus.ACTIVATED) {
|
||||
antiBotStatus = AntiBotStatus.ARMED;
|
||||
antibotPlayers.clear();
|
||||
for (String s : messages.send("antibot_auto_disabled"))
|
||||
Bukkit.broadcastMessage(s.replace("%m", "" + Settings.antiBotDuration));
|
||||
}
|
||||
}
|
||||
}, Settings.antiBotDuration * 1200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method checkAntiBotMod.
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public static void checkAntiBot(final Player player) {
|
||||
if (antiBotStatus == AntiBotStatus.ACTIVATED || antiBotStatus == AntiBotStatus.DISARMED) {
|
||||
return;
|
||||
}
|
||||
if (plugin.getPermissionsManager().hasPermission(player, "authme.bypassantibot")) {
|
||||
return;
|
||||
}
|
||||
|
||||
antibotPlayers.add(player.getName().toLowerCase());
|
||||
if (antibotPlayers.size() > Settings.antiBotSensibility) {
|
||||
activateAntiBot();
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
antibotPlayers.remove(player.getName().toLowerCase());
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,7 @@ import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.OtherAccounts;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.Spawn;
|
||||
import fr.xephi.authme.AntiBot;
|
||||
import fr.xephi.authme.util.GeoLiteAPI;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import net.minelink.ctplus.CombatTagPlus;
|
||||
@ -82,30 +83,30 @@ public class AuthMe extends JavaPlugin {
|
||||
public DataSource database;
|
||||
public OtherAccounts otherAccounts;
|
||||
public Location essentialsSpawn;
|
||||
// Hooks TODO: move into modules
|
||||
|
||||
// Hooks TODO: Move into modules
|
||||
public Essentials ess;
|
||||
public MultiverseCore multiverse;
|
||||
public CombatTagPlus combatTagPlus;
|
||||
public AuthMeInventoryPacketAdapter inventoryProtector;
|
||||
// Random data maps and stuff
|
||||
// TODO: Create Manager for this
|
||||
|
||||
// Data maps and stuff
|
||||
// TODO: Move into a manager
|
||||
public final ConcurrentHashMap<String, BukkitTask> sessions = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, Integer> captcha = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, String> cap = new ConcurrentHashMap<>();
|
||||
public final ConcurrentHashMap<String, String> realIp = new ConcurrentHashMap<>();
|
||||
// AntiBot Status
|
||||
// TODO: Create Manager for this
|
||||
public boolean antiBotMod = false;
|
||||
public boolean delayedAntiBot = true;
|
||||
|
||||
// If cache is enabled, prevent any connection before the players data caching is completed.
|
||||
// TODO: Move somewhere
|
||||
private boolean canConnect = true;
|
||||
|
||||
private CommandHandler commandHandler = null;
|
||||
private PermissionsManager permsMan = null;
|
||||
private Settings settings;
|
||||
private Messages messages;
|
||||
private JsonCache playerBackup;
|
||||
private ModuleManager moduleManager;
|
||||
// If cache is enabled, prevent any connection before the players data caching is completed.
|
||||
// TODO: Move somewhere
|
||||
private boolean canConnect = true;
|
||||
|
||||
/**
|
||||
* Returns the plugin's instance.
|
||||
@ -229,7 +230,7 @@ public class AuthMe extends JavaPlugin {
|
||||
setupConsoleFilter();
|
||||
|
||||
// AntiBot delay
|
||||
setupAntiBotDelay();
|
||||
AntiBot.setupAntiBotService();
|
||||
|
||||
// Download and load GeoIp.dat file if absent
|
||||
GeoLiteAPI.isDataAvailable();
|
||||
@ -443,20 +444,6 @@ public class AuthMe extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the AntiBot delay.
|
||||
*/
|
||||
private void setupAntiBotDelay() {
|
||||
if (Settings.enableAntiBot) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delayedAntiBot = false;
|
||||
}
|
||||
}, 2400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the console filter.
|
||||
*/
|
||||
@ -836,15 +823,6 @@ public class AuthMe extends JavaPlugin {
|
||||
return player.getWorld().getSpawnLocation();
|
||||
}
|
||||
|
||||
public void switchAntiBotMod(boolean mode) {
|
||||
this.antiBotMod = mode;
|
||||
Settings.switchAntiBotMod(mode);
|
||||
}
|
||||
|
||||
public boolean getAntiBotModMode() {
|
||||
return this.antiBotMod;
|
||||
}
|
||||
|
||||
private void recallEmail() {
|
||||
if (!Settings.recallEmail)
|
||||
return;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.AntiBot;
|
||||
import fr.xephi.authme.command.CommandParts;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
@ -22,25 +22,26 @@ public class SwitchAntiBotCommand extends ExecutableCommand {
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the new state
|
||||
String newState = plugin.getAntiBotModMode() ? "OFF" : "ON";
|
||||
if (commandArguments.getCount() >= 1)
|
||||
String newState = null;
|
||||
if (commandArguments.getCount() == 1) {
|
||||
newState = commandArguments.get(0);
|
||||
} else if(commandArguments.getCount() == 0) {
|
||||
sender.sendMessage("[AuthMe] AntiBot status: " + AntiBot.getAntiBotStatus().name());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Enable the mod
|
||||
if (newState.equalsIgnoreCase("ON")) {
|
||||
plugin.switchAntiBotMod(true);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod enabled");
|
||||
AntiBot.switchAntiBotStatus(true);
|
||||
sender.sendMessage("[AuthMe] AntiBot Manual Ovverride: enabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Disable the mod
|
||||
if (newState.equalsIgnoreCase("OFF")) {
|
||||
plugin.switchAntiBotMod(false);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod disabled");
|
||||
AntiBot.switchAntiBotStatus(false);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod Manual Ovverride: disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@ package fr.xephi.authme.listener;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import fr.xephi.authme.AntiBot;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
@ -27,9 +29,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
@ -41,7 +41,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
public static final ConcurrentHashMap<String, Boolean> causeByAuthMe = new ConcurrentHashMap<>();
|
||||
public final AuthMe plugin;
|
||||
private final Messages m = Messages.getInstance();
|
||||
private final List<String> antibot = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constructor for AuthMePlayerListener.
|
||||
@ -206,44 +205,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method checkAntiBotMod.
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
private void checkAntiBotMod(final Player player) {
|
||||
if (plugin.delayedAntiBot || plugin.antiBotMod)
|
||||
return;
|
||||
if (plugin.getPermissionsManager().hasPermission(player, "authme.bypassantibot"))
|
||||
return;
|
||||
if (antibot.size() > Settings.antiBotSensibility) {
|
||||
plugin.switchAntiBotMod(true);
|
||||
for (String s : m.send("antibot_auto_enabled"))
|
||||
Bukkit.broadcastMessage(s);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.antiBotMod) {
|
||||
plugin.switchAntiBotMod(false);
|
||||
antibot.clear();
|
||||
for (String s : m.send("antibot_auto_disabled"))
|
||||
Bukkit.broadcastMessage(s.replace("%m", "" + Settings.antiBotDuration));
|
||||
}
|
||||
}
|
||||
}, Settings.antiBotDuration * 1200);
|
||||
return;
|
||||
}
|
||||
antibot.add(player.getName().toLowerCase());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
antibot.remove(player.getName().toLowerCase());
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method onPlayerJoin.
|
||||
*
|
||||
@ -402,7 +363,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
checkAntiBotMod(player);
|
||||
AntiBot.checkAntiBot(player);
|
||||
|
||||
if (Settings.bungee) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
Loading…
Reference in New Issue
Block a user