mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-23 10:45:23 +01:00
Merge upstream/master into ljacqu/enums
This commit is contained in:
commit
e4c82e04ff
@ -3,6 +3,7 @@
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value>
|
||||
<option name="AUTODETECT_INDENTS" value="false" />
|
||||
<option name="LINE_SEPARATOR" value=" " />
|
||||
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
|
||||
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
|
||||
|
100
src/main/java/fr/xephi/authme/AntiBot.java
Normal file
100
src/main/java/fr/xephi/authme/AntiBot.java
Normal file
@ -0,0 +1,100 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import fr.xephi.authme.settings.Messages;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The AntiBot Service Management class.
|
||||
*/
|
||||
public class AntiBot {
|
||||
|
||||
private static final AuthMe plugin = AuthMe.getInstance();
|
||||
private static final Messages messages = plugin.getMessages();
|
||||
private static final List<String> antibotPlayers = new ArrayList<>();
|
||||
private static AntiBotStatus antiBotStatus = AntiBotStatus.DISARMED;
|
||||
|
||||
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 overrideAntiBotStatus(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);
|
||||
}
|
||||
|
||||
public enum AntiBotStatus {
|
||||
ARMED,
|
||||
DISARMED,
|
||||
DELAYED,
|
||||
ACTIVATED
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package fr.xephi.authme;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import fr.xephi.authme.api.API;
|
||||
@ -68,7 +69,6 @@ public class AuthMe extends JavaPlugin {
|
||||
* Defines the current AuthMeReloaded version code.
|
||||
*/
|
||||
// TODO: Increase this number by one when an update is release
|
||||
// TODO: Increase the count via maven
|
||||
private static final int PLUGIN_VERSION_CODE = 100;
|
||||
|
||||
private static AuthMe plugin;
|
||||
@ -81,30 +81,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.
|
||||
@ -228,7 +228,7 @@ public class AuthMe extends JavaPlugin {
|
||||
setupConsoleFilter();
|
||||
|
||||
// AntiBot delay
|
||||
setupAntiBotDelay();
|
||||
AntiBot.setupAntiBotService();
|
||||
|
||||
// Download and load GeoIp.dat file if absent
|
||||
GeoLiteAPI.isDataAvailable();
|
||||
@ -442,20 +442,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.
|
||||
*/
|
||||
@ -687,13 +673,24 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Check the presence of the ProtocolLib plugin
|
||||
public void checkProtocolLib() {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
if (server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
||||
inventoryProtector.register();
|
||||
} else {
|
||||
if (!server.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it...");
|
||||
Settings.protectInventoryBeforeLogInEnabled = false;
|
||||
getSettings().set("settings.restrictions.ProtectInventoryBeforeLogIn", false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
if (inventoryProtector == null) {
|
||||
inventoryProtector = new AuthMeInventoryPacketAdapter(this);
|
||||
inventoryProtector.register();
|
||||
}
|
||||
} else {
|
||||
if (inventoryProtector != null) {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryProtector);
|
||||
inventoryProtector = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -824,15 +821,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.overrideAntiBotStatus(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.overrideAntiBotStatus(false);
|
||||
sender.sendMessage("[AuthMe] AntiBotMod Manual Ovverride: disabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -25,18 +25,6 @@ public class CaptchaCommand extends ExecutableCommand {
|
||||
*/
|
||||
@Override
|
||||
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Messages instance
|
||||
final Messages m = Messages.getInstance();
|
||||
|
||||
// Random string instance, for captcha generation (I think) -- timvisee
|
||||
RandomString randStr = new RandomString(Settings.captchaLength);
|
||||
|
||||
// Get the parameter values
|
||||
String captcha = commandArguments.get(0);
|
||||
|
||||
// Make sure the current command executor is a player
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
@ -46,6 +34,12 @@ public class CaptchaCommand extends ExecutableCommand {
|
||||
final Player player = (Player) sender;
|
||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||
|
||||
// Get the parameter values
|
||||
String captcha = commandArguments.get(0);
|
||||
|
||||
// Messages instance
|
||||
final Messages m = Messages.getInstance();
|
||||
|
||||
// Command logic
|
||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
|
||||
m.send(player, "logged_in");
|
||||
@ -57,6 +51,9 @@ public class CaptchaCommand extends ExecutableCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
if (!plugin.cap.containsKey(playerNameLowerCase)) {
|
||||
m.send(player, "usage_log");
|
||||
return true;
|
||||
@ -64,18 +61,16 @@ public class CaptchaCommand extends ExecutableCommand {
|
||||
|
||||
if (Settings.useCaptcha && !captcha.equals(plugin.cap.get(playerNameLowerCase))) {
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
plugin.cap.put(playerNameLowerCase, randStr.nextString());
|
||||
String randStr = new RandomString(Settings.captchaLength).nextString();
|
||||
plugin.cap.put(playerNameLowerCase, randStr);
|
||||
for (String s : m.send("wrong_captcha")) {
|
||||
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
plugin.captcha.remove(playerNameLowerCase);
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
plugin.captcha.remove(playerNameLowerCase);
|
||||
plugin.cap.remove(playerNameLowerCase);
|
||||
|
||||
// Show a status message
|
||||
m.send(player, "valid_captcha");
|
||||
|
@ -20,10 +20,10 @@ public class LoginCommand extends ExecutableCommand {
|
||||
// Get the necessary objects
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
final Player player = (Player) sender;
|
||||
final String playerPass = commandArguments.get(0);
|
||||
final String password = commandArguments.get(0);
|
||||
|
||||
// Log the player in
|
||||
plugin.getManagement().performLogin(player, playerPass, false);
|
||||
plugin.getManagement().performLogin(player, password, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,11 @@ import java.util.logging.Level;
|
||||
public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
||||
|
||||
private static final int PLAYER_INVENTORY = 0;
|
||||
//http://wiki.vg/Inventory#Inventory (0-4 crafting, 5-8 armor, 9-35 main inventory, 36-44 inventory)
|
||||
//+1 because an index starts with 0
|
||||
private static final int PLAYER_CRAFTING_SIZE = 5;
|
||||
// http://wiki.vg/Inventory#Inventory (0-4 crafting, 5-8 armor, 9-35 main inventory, 36-44 hotbar)
|
||||
// +1 because an index starts with 0
|
||||
private static final int CRAFTING_SIZE = 5;
|
||||
private static final int ARMOR_SIZE = 4;
|
||||
private static final int MAIN_SIZE = 27;
|
||||
private static final int HOTBAR_SIZE = 9;
|
||||
|
||||
/**
|
||||
@ -88,7 +90,7 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
||||
//we are sending our own inventory
|
||||
inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
|
||||
|
||||
ItemStack[] playerCrafting = new ItemStack[PLAYER_CRAFTING_SIZE];
|
||||
ItemStack[] playerCrafting = new ItemStack[CRAFTING_SIZE];
|
||||
Arrays.fill(playerCrafting, new ItemStack(Material.AIR));
|
||||
ItemStack[] armorContents = player.getInventory().getArmorContents();
|
||||
ItemStack[] mainInventory = player.getInventory().getContents();
|
||||
@ -120,4 +122,19 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
|
||||
plugin.getLogger().log(Level.WARNING, "Error during inventory recovery", invocationExc);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendBlankInventoryPacket(Player player) {
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
|
||||
inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
|
||||
int inventorySize = CRAFTING_SIZE + ARMOR_SIZE + MAIN_SIZE + HOTBAR_SIZE;
|
||||
ItemStack[] blankInventory = new ItemStack[inventorySize];
|
||||
Arrays.fill(blankInventory, new ItemStack(Material.AIR));
|
||||
inventoryPacket.getItemArrayModifier().write(0, blankInventory);
|
||||
try {
|
||||
protocolManager.sendServerPacket(player, inventoryPacket, false);
|
||||
} catch (InvocationTargetException invocationExc) {
|
||||
plugin.getLogger().log(Level.WARNING, "Error during sending blank inventory", invocationExc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,11 +29,8 @@ 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;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -42,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.
|
||||
@ -59,15 +57,16 @@ public class AuthMePlayerListener implements Listener {
|
||||
* @param event AsyncPlayerChatEvent
|
||||
*/
|
||||
private void handleChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (Settings.isChatAllowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.isChatAllowed)
|
||||
return;
|
||||
if (Utils.checkAuth(player))
|
||||
Player player = event.getPlayer();
|
||||
if (Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) {
|
||||
m.send(player, "login_msg");
|
||||
} else {
|
||||
@ -162,14 +161,19 @@ public class AuthMePlayerListener implements Listener {
|
||||
*
|
||||
* @param event PlayerMoveEvent
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
int radius = Settings.getMovementRadius;
|
||||
boolean allowMove = Settings.isMovementAllowed;
|
||||
if (Settings.noTeleport) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (allowMove && radius <= 0) {
|
||||
|
||||
if (Settings.isMovementAllowed && Settings.getMovementRadius <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getFrom().getBlockX() == event.getTo().getBlockX()
|
||||
&& event.getFrom().getBlockY() == event.getTo().getBlockY()
|
||||
&& event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -178,63 +182,29 @@ public class AuthMePlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowMove) {
|
||||
if (!Settings.isMovementAllowed) {
|
||||
if (event.getFrom().distance(event.getTo()) > 0) {
|
||||
event.setCancelled(true);
|
||||
event.setTo(event.getFrom());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.noTeleport) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location spawn = plugin.getSpawnLocation(player);
|
||||
if (spawn != null && spawn.getWorld() != null) {
|
||||
if (!event.getPlayer().getWorld().equals(spawn.getWorld())) {
|
||||
event.getPlayer().teleport(spawn);
|
||||
if (!player.getWorld().equals(spawn.getWorld())) {
|
||||
player.teleport(spawn);
|
||||
return;
|
||||
}
|
||||
if ((spawn.distance(player.getLocation()) > radius)) {
|
||||
event.getPlayer().teleport(spawn);
|
||||
if ((spawn.distance(player.getLocation()) > Settings.getMovementRadius)) {
|
||||
player.teleport(spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
@ -242,8 +212,9 @@ public class AuthMePlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (event.getPlayer() == null)
|
||||
if (event.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final String name = player.getName().toLowerCase();
|
||||
@ -251,7 +222,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
final boolean delay = Settings.delayJoinLeaveMessages && joinMsg != null;
|
||||
|
||||
// Remove the join message while the player isn't logging in
|
||||
if (Settings.delayJoinLeaveMessages && event.getJoinMessage() != null) {
|
||||
if (delay) {
|
||||
event.setJoinMessage(null);
|
||||
}
|
||||
|
||||
@ -260,9 +231,10 @@ public class AuthMePlayerListener implements Listener {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (delay)
|
||||
if (delay) {
|
||||
joinMessage.put(name, joinMsg);
|
||||
plugin.management.performJoin(player);
|
||||
}
|
||||
plugin.getManagement().performJoin(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -306,14 +278,25 @@ public class AuthMePlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player == null) {
|
||||
if (event.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String name = player.getName().toLowerCase();
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL) {
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
if (playersOnline > plugin.getServer().getMaxPlayers()) {
|
||||
event.allow();
|
||||
} else {
|
||||
Player pl = plugin.generateKickPlayer(Utils.getOnlinePlayers());
|
||||
if (pl != null) {
|
||||
pl.kickPlayer(m.send("kick_forvip")[0]);
|
||||
event.allow();
|
||||
} else {
|
||||
ConsoleLogger.info("The player " + event.getPlayer().getName() + " tryed to join, but the server was full");
|
||||
event.setKickMessage(m.send("kick_fullserver")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||
@ -323,18 +306,32 @@ public class AuthMePlayerListener implements Listener {
|
||||
// Get the permissions manager
|
||||
PermissionsManager permsMan = plugin.getPermissionsManager();
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, "authme.vip")) {
|
||||
event.setKickMessage(m.send("kick_fullserver")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String name = player.getName().toLowerCase();
|
||||
boolean isAuthAvailable = plugin.database.isAuthAvailable(name);
|
||||
|
||||
if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
|
||||
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (((code == null) || Settings.countriesBlacklist.contains(code))) {
|
||||
if (Settings.countriesBlacklist.contains(code)) {
|
||||
event.setKickMessage(m.send("country_banned")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
|
||||
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (((code == null) || !Settings.countries.contains(code))) {
|
||||
if (!Settings.countries.contains(code)) {
|
||||
event.setKickMessage(m.send("country_banned")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
@ -354,72 +351,24 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
int min = Settings.getMinNickLength;
|
||||
int max = Settings.getMaxNickLength;
|
||||
String regex = Settings.getNickRegex;
|
||||
|
||||
if (name.length() > max || name.length() < min) {
|
||||
if (name.length() > Settings.getMaxNickLength || name.length() < Settings.getMinNickLength) {
|
||||
event.setKickMessage(Arrays.toString(m.send("name_len")));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (!player.getName().matches(regex) || name.equalsIgnoreCase("Player")) {
|
||||
try {
|
||||
event.setKickMessage(m.send("regex")[0].replace("REG_EX", regex));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
} catch (Exception exc) {
|
||||
event.setKickMessage("allowed char : " + regex);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (PatternSyntaxException pse) {
|
||||
if (regex == null || regex.isEmpty()) {
|
||||
event.setKickMessage("Your nickname do not match");
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
event.setKickMessage(m.send("regex")[0].replace("REG_EX", regex));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
} catch (Exception exc) {
|
||||
event.setKickMessage("allowed char : " + regex);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
}
|
||||
|
||||
if (!Settings.nickPattern.matcher(player.getName()).matches() || name.equalsIgnoreCase("Player")) {
|
||||
event.setKickMessage(m.send("regex")[0].replace("REG_EX", Settings.getNickRegex));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) {
|
||||
checkAntiBotMod(player);
|
||||
if (Settings.bungee) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("IP");
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL)
|
||||
return;
|
||||
if (!permsMan.hasPermission(player, "authme.vip")) {
|
||||
event.setKickMessage(m.send("kick_fullserver")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
|
||||
return;
|
||||
}
|
||||
AntiBot.checkAntiBot(player);
|
||||
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
if (playersOnline > plugin.getServer().getMaxPlayers()) {
|
||||
event.allow();
|
||||
} else {
|
||||
final Player pl = plugin.generateKickPlayer(Utils.getOnlinePlayers());
|
||||
if (pl != null) {
|
||||
pl.kickPlayer(m.send("kick_forvip")[0]);
|
||||
event.allow();
|
||||
} else {
|
||||
ConsoleLogger.info("The player " + player.getName() + " tryed to join, but the server was full");
|
||||
event.setKickMessage(m.send("kick_fullserver")[0]);
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
|
||||
}
|
||||
if (Settings.bungee) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("IP");
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,8 +8,6 @@ import fr.xephi.authme.process.logout.AsynchronousLogout;
|
||||
import fr.xephi.authme.process.quit.AsynchronousQuit;
|
||||
import fr.xephi.authme.process.register.AsyncRegister;
|
||||
import fr.xephi.authme.process.unregister.AsynchronousUnregister;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
@ -19,7 +17,6 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
*/
|
||||
public class Management {
|
||||
|
||||
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
||||
private final AuthMe plugin;
|
||||
private final BukkitScheduler sched;
|
||||
|
||||
|
@ -98,18 +98,15 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||
|
||||
protected void restoreInventory() {
|
||||
RestoreInventoryEvent event = new RestoreInventoryEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
pm.callEvent(event);
|
||||
if (!event.isCancelled() && plugin.inventoryProtector != null) {
|
||||
plugin.inventoryProtector.sendInventoryPacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
protected void forceCommands() {
|
||||
for (String command : Settings.forceCommands) {
|
||||
try {
|
||||
player.performCommand(command.replace("%p", player.getName()));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
player.performCommand(command.replace("%p", player.getName()));
|
||||
}
|
||||
for (String command : Settings.forceCommandsAsConsole) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
|
||||
@ -154,7 +151,7 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
|
||||
|
||||
restoreFlyghtState();
|
||||
|
||||
if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) {
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
restoreInventory();
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,9 @@ public class AsynchronousLogout {
|
||||
|
||||
public void process() {
|
||||
preLogout();
|
||||
if (!canLogout)
|
||||
if (!canLogout) {
|
||||
return;
|
||||
}
|
||||
final Player p = player;
|
||||
BukkitScheduler scheduler = p.getServer().getScheduler();
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
@ -66,11 +67,11 @@ public class AsynchronousLogout {
|
||||
Utils.teleportToSpawn(p);
|
||||
}
|
||||
});
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name)) {
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
|
||||
|
||||
scheduler.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin));
|
||||
}
|
||||
}
|
||||
|
@ -43,14 +43,18 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.sessions.containsKey(name))
|
||||
if (plugin.sessions.containsKey(name)) {
|
||||
plugin.sessions.get(name).cancel();
|
||||
plugin.sessions.remove(name);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
plugin.sessions.remove(name);
|
||||
}
|
||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||
plugin.inventoryProtector.sendBlankInventoryPacket(player);
|
||||
}
|
||||
int timeOut = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = player.getServer().getScheduler();
|
||||
if (delay != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), timeOut);
|
||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||
}
|
||||
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval));
|
||||
|
@ -9,8 +9,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -43,6 +45,7 @@ public final class Settings extends YamlConfiguration {
|
||||
public static List<String> emailWhitelist;
|
||||
public static DataSourceType getDataSource;
|
||||
public static HashAlgorithm getPasswordHash;
|
||||
public static Pattern nickPattern;
|
||||
public static boolean useLogging = false;
|
||||
public static int purgeDelay = 60;
|
||||
// Due to compatibility issues with plugins like FactionsChat
|
||||
@ -141,6 +144,7 @@ public final class Settings extends YamlConfiguration {
|
||||
getMinNickLength = configFile.getInt("settings.restrictions.minNicknameLength", 3);
|
||||
getPasswordMinLen = configFile.getInt("settings.security.minPasswordLength", 4);
|
||||
getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*");
|
||||
nickPattern = Pattern.compile(getNickRegex);
|
||||
isAllowRestrictedIp = configFile.getBoolean("settings.restrictions.AllowRestrictedUser", false);
|
||||
getRestrictedIp = configFile.getStringList("settings.restrictions.AllowedRestrictedUser");
|
||||
isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false);
|
||||
@ -183,7 +187,10 @@ public final class Settings extends YamlConfiguration {
|
||||
getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName");
|
||||
getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", "");
|
||||
getEnablePasswordVerifier = configFile.getBoolean("settings.restrictions.enablePasswordVerifier", true);
|
||||
|
||||
protectInventoryBeforeLogInEnabled = configFile.getBoolean("settings.restrictions.ProtectInventoryBeforeLogIn", true);
|
||||
plugin.checkProtocolLib();
|
||||
|
||||
passwordMaxLength = configFile.getInt("settings.security.passwordMaxLength", 20);
|
||||
isBackupActivated = configFile.getBoolean("BackupSystem.ActivateBackup", false);
|
||||
isBackupOnStart = configFile.getBoolean("BackupSystem.OnServerStart", false);
|
||||
@ -191,22 +198,16 @@ public final class Settings extends YamlConfiguration {
|
||||
backupWindowsPath = configFile.getString("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
|
||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||
|
||||
allowCommands = new ArrayList<>();
|
||||
allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha"));
|
||||
for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) {
|
||||
allowCommands.add(cmd.toLowerCase());
|
||||
cmd = cmd.toLowerCase();
|
||||
if (!allowCommands.contains(cmd)) {
|
||||
allowCommands.add(cmd);
|
||||
}
|
||||
}
|
||||
if (!allowCommands.contains("/login"))
|
||||
allowCommands.add("/login");
|
||||
if (!allowCommands.contains("/register"))
|
||||
allowCommands.add("/register");
|
||||
if (!allowCommands.contains("/l"))
|
||||
allowCommands.add("/l");
|
||||
if (!allowCommands.contains("/reg"))
|
||||
allowCommands.add("/reg");
|
||||
if (!allowCommands.contains("/email"))
|
||||
allowCommands.add("/email");
|
||||
if (!allowCommands.contains("/captcha"))
|
||||
allowCommands.add("/captcha");
|
||||
|
||||
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
|
||||
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
||||
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
||||
@ -619,10 +620,6 @@ public final class Settings extends YamlConfiguration {
|
||||
set("Email.emailBlacklisted", new ArrayList<String>());
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Performances.useMultiThreading")) {
|
||||
set("Performances.useMultiThreading", null);
|
||||
changes = true;
|
||||
}
|
||||
if (contains("Performances")) {
|
||||
set("Performances", null);
|
||||
changes = true;
|
||||
|
@ -4,6 +4,7 @@ import com.maxmind.geoip.LookupService;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
@ -12,6 +13,8 @@ import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class GeoLiteAPI {
|
||||
|
||||
private static final String LICENSE = "[LICENSE] This product uses data from the GeoLite API created by MaxMind, " +
|
||||
"available at http://www.maxmind.com";
|
||||
private static final String GEOIP_URL = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry" +
|
||||
"/GeoIP.dat.gz";
|
||||
private static final Wrapper wrapper = new Wrapper(AuthMe.getInstance());
|
||||
@ -31,8 +34,7 @@ public class GeoLiteAPI {
|
||||
if (data.exists()) {
|
||||
try {
|
||||
lookupService = new LookupService(data);
|
||||
plugin.getLogger().info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, " +
|
||||
"available at http://www.maxmind.com");
|
||||
plugin.getLogger().info(LICENSE);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
// TODO ljacqu 20151123: Log the exception instead of just swallowing it
|
||||
@ -40,7 +42,7 @@ public class GeoLiteAPI {
|
||||
}
|
||||
}
|
||||
// Ok, let's try to download the data file!
|
||||
wrapper.getServer().getScheduler().runTaskAsynchronously(wrapper.getAuthMe(), new Runnable() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import com.maxmind.geoip.LookupService;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
@ -13,18 +12,14 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* Utility class for various operations used in the codebase.
|
||||
@ -36,12 +31,9 @@ public final class Utils {
|
||||
|
||||
private static boolean getOnlinePlayersIsCollection = false;
|
||||
private static Method getOnlinePlayers;
|
||||
private static LookupService lookupService;
|
||||
|
||||
static {
|
||||
plugin = AuthMe.getInstance();
|
||||
wrapper = new Wrapper(plugin);
|
||||
checkGeoIP();
|
||||
initializeOnlinePlayersIsCollectionField();
|
||||
}
|
||||
|
||||
@ -49,54 +41,6 @@ public final class Utils {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
// Check and Download GeoIP data if it doesn't exist
|
||||
public static boolean checkGeoIP() {
|
||||
if (lookupService != null) {
|
||||
return true;
|
||||
}
|
||||
final File data = new File(Settings.PLUGIN_FOLDER, "GeoIP.dat");
|
||||
if (data.exists()) {
|
||||
if (lookupService == null) {
|
||||
try {
|
||||
lookupService = new LookupService(data);
|
||||
ConsoleLogger.info("[LICENSE] This product uses data from the GeoLite API created by MaxMind, " +
|
||||
"available at http://www.maxmind.com");
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
wrapper.getServer().getScheduler().runTaskAsynchronously(wrapper.getAuthMe(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String url = "http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz";
|
||||
URL downloadUrl = new URL(url);
|
||||
URLConnection conn = downloadUrl.openConnection();
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.connect();
|
||||
InputStream input = conn.getInputStream();
|
||||
if (conn.getURL().toString().endsWith(".gz")) {
|
||||
input = new GZIPInputStream(input);
|
||||
}
|
||||
OutputStream output = new FileOutputStream(data);
|
||||
byte[] buffer = new byte[2048];
|
||||
int length = input.read(buffer);
|
||||
while (length >= 0) {
|
||||
output.write(buffer, 0, length);
|
||||
length = input.read(buffer);
|
||||
}
|
||||
output.close();
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the group of a player, by its AuthMe group type.
|
||||
*
|
||||
@ -157,7 +101,7 @@ public final class Utils {
|
||||
|
||||
/**
|
||||
* TODO: This method requires better explanation.
|
||||
* <p/>
|
||||
* <p>
|
||||
* Set the normal group of a player.
|
||||
*
|
||||
* @param player The player.
|
||||
@ -176,7 +120,8 @@ public final class Utils {
|
||||
assert permsMan != null;
|
||||
|
||||
// Remove old groups
|
||||
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup,
|
||||
Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
|
||||
// Add the normal group, return the result
|
||||
return permsMan.addGroup(player, group);
|
||||
@ -188,14 +133,13 @@ public final class Utils {
|
||||
return true;
|
||||
}
|
||||
|
||||
String name = player.getName().toLowerCase();
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
if (PlayerCache.getInstance().isAuthenticated(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Settings.isForcedRegistrationEnabled) {
|
||||
// TODO ljacqu 20151123: Use a setter to retrieve things from AuthMe
|
||||
if (!plugin.database.isAuthAvailable(name)) {
|
||||
if (!plugin.database.isAuthAvailable(player.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -334,20 +278,8 @@ public final class Utils {
|
||||
return wrapper.getServer().getPlayer(name);
|
||||
}
|
||||
|
||||
public static boolean isNPC(final Entity player) {
|
||||
try {
|
||||
if (player.hasMetadata("NPC")) {
|
||||
return true;
|
||||
} else if (plugin.combatTagPlus != null
|
||||
// TODO ljacqu 20151123: Use a getter for combatTagPlus in AuthMe instead of using direct field access
|
||||
&& player instanceof Player
|
||||
&& plugin.combatTagPlus.getNpcPlayerHelper().isNpc((Player) player)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
public static boolean isNPC(Player player) {
|
||||
return player.hasMetadata("NPC") || plugin.combatTagPlus != null && plugin.combatTagPlus.getNpcPlayerHelper().isNpc(player);
|
||||
}
|
||||
|
||||
public static void teleportToSpawn(Player player) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
name: AuthMe
|
||||
name: ${pluginName}
|
||||
authors: ${pluginAuthors}
|
||||
website: ${project.url}
|
||||
description: ${project.description}
|
||||
|
Loading…
Reference in New Issue
Block a user