diff --git a/src/main/java/cn/citycraft/AuthMe/AuthMe.java b/src/main/java/cn/citycraft/AuthMe/AuthMe.java index ae668e3..df053f5 100644 --- a/src/main/java/cn/citycraft/AuthMe/AuthMe.java +++ b/src/main/java/cn/citycraft/AuthMe/AuthMe.java @@ -46,10 +46,7 @@ import cn.citycraft.AuthMe.datasource.SQLite; import cn.citycraft.AuthMe.datasource.SQLite_HIKARI; import cn.citycraft.AuthMe.listener.AuthMeBlockListener; import cn.citycraft.AuthMe.listener.AuthMeEntityListener; -import cn.citycraft.AuthMe.listener.AuthMeInventoryPacketAdapter; import cn.citycraft.AuthMe.listener.AuthMePlayerListener; -import cn.citycraft.AuthMe.listener.AuthMePlayerListener16; -import cn.citycraft.AuthMe.listener.AuthMePlayerListener18; import cn.citycraft.AuthMe.listener.AuthMeServerListener; import cn.citycraft.AuthMe.plugin.manager.BungeeCordMessage; import cn.citycraft.AuthMe.plugin.manager.EssSpawn; @@ -83,7 +80,6 @@ public class AuthMe extends JavaPlugin { public boolean delayedAntiBot = true; public Essentials ess; public Location essentialsSpawn; - public AuthMeInventoryPacketAdapter inventoryProtector; public Management management; public OtherAccounts otherAccounts; @@ -145,19 +141,6 @@ 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 { - ConsoleLogger.showError("警告!!! 服务器内未找到 ProtocolLib 插件 关闭背包保护功能..."); - Settings.protectInventoryBeforeLogInEnabled = false; - } - } - } - // Check the presence of the Vault plugin and a permissions provider public void checkVault() { if (server.getPluginManager().isPluginEnabled("Vault")) { @@ -364,10 +347,6 @@ public class AuthMe extends JavaPlugin { // Check Essentials checkEssentials(); - // Check if the protocollib is available. If so we could listen for - // inventory protection - checkProtocolLib(); - // Do backup on start if enabled if (Settings.isBackupActivated && Settings.isBackupOnStart) { // Do backup and check return value! @@ -431,18 +410,6 @@ public class AuthMe extends JavaPlugin { // Register events pm.registerEvents(new AuthMePlayerListener(this), this); - // Try to register 1.6 player listeners - try { - Class.forName("org.bukkit.event.player.PlayerEditBookEvent"); - pm.registerEvents(new AuthMePlayerListener16(this), this); - } catch (final ClassNotFoundException ignore) { - } - // Try to register 1.8 player listeners - try { - Class.forName("org.bukkit.event.player.PlayerInteractAtEntityEvent"); - pm.registerEvents(new AuthMePlayerListener18(this), this); - } catch (final ClassNotFoundException ignore) { - } pm.registerEvents(new AuthMeBlockListener(this), this); pm.registerEvents(new AuthMeEntityListener(this), this); pm.registerEvents(new AuthMeServerListener(this), this); diff --git a/src/main/java/cn/citycraft/AuthMe/cache/limbo/LimboCache.java b/src/main/java/cn/citycraft/AuthMe/cache/limbo/LimboCache.java index 297a3fc..15c7fb2 100644 --- a/src/main/java/cn/citycraft/AuthMe/cache/limbo/LimboCache.java +++ b/src/main/java/cn/citycraft/AuthMe/cache/limbo/LimboCache.java @@ -2,7 +2,6 @@ package cn.citycraft.AuthMe.cache.limbo; import java.util.concurrent.ConcurrentHashMap; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -12,21 +11,10 @@ import cn.citycraft.AuthMe.ConsoleLogger; import cn.citycraft.AuthMe.cache.backup.DataFileCache; import cn.citycraft.AuthMe.cache.backup.JsonCache; import cn.citycraft.AuthMe.settings.Settings; -import fr.xephi.authme.events.ResetInventoryEvent; -import fr.xephi.authme.events.StoreInventoryEvent; public class LimboCache { private volatile static LimboCache singleton; - public ConcurrentHashMap cache; - public AuthMe plugin; - private JsonCache playerData; - - private LimboCache(AuthMe plugin) { - this.plugin = plugin; - this.cache = new ConcurrentHashMap<>(); - this.playerData = new JsonCache(); - } public static LimboCache getInstance() { if (singleton == null) { @@ -35,8 +23,19 @@ public class LimboCache { return singleton; } - public void addLimboPlayer(Player player) { - String name = player.getName().toLowerCase(); + public ConcurrentHashMap cache; + public AuthMe plugin; + + private final JsonCache playerData; + + private LimboCache(final AuthMe plugin) { + this.plugin = plugin; + this.cache = new ConcurrentHashMap<>(); + this.playerData = new JsonCache(); + } + + public void addLimboPlayer(final Player player) { + final String name = player.getName().toLowerCase(); Location loc = player.getLocation(); GameMode gameMode = player.getGameMode(); boolean operator = false; @@ -44,33 +43,19 @@ public class LimboCache { boolean flying = false; if (playerData.doesCacheExist(player)) { - final StoreInventoryEvent event = new StoreInventoryEvent(player, playerData); - Bukkit.getServer().getPluginManager().callEvent(event); - if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) { - player.getInventory().setContents(event.getInventory()); - player.getInventory().setArmorContents(event.getArmor()); - } - - DataFileCache cache = playerData.readCache(player); + final DataFileCache cache = playerData.readCache(player); if (cache != null) { playerGroup = cache.getGroup(); operator = cache.getOperator(); flying = cache.isFlying(); } } else { - StoreInventoryEvent event = new StoreInventoryEvent(player); - Bukkit.getServer().getPluginManager().callEvent(event); - if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) { - player.getInventory().setContents(event.getInventory()); - player.getInventory().setArmorContents(event.getArmor()); - } - operator = player.isOp(); flying = player.isFlying(); if (plugin.permission != null) { try { playerGroup = plugin.permission.getPrimaryGroup(player); - } catch (UnsupportedOperationException e) { + } catch (final UnsupportedOperationException e) { ConsoleLogger.showError("Your permission system (" + plugin.permission.getName() + ") do not support Group system with that config... unhook!"); plugin.permission = null; } @@ -78,14 +63,6 @@ public class LimboCache { } if (Settings.isForceSurvivalModeEnabled) { - if (Settings.isResetInventoryIfCreative && gameMode == GameMode.CREATIVE) { - ResetInventoryEvent event = new ResetInventoryEvent(player); - Bukkit.getServer().getPluginManager().callEvent(event); - if (!event.isCancelled()) { - player.getInventory().clear(); - player.sendMessage("Your inventory has been cleaned!"); - } - } if (gameMode == GameMode.CREATIVE) { flying = false; } @@ -97,23 +74,23 @@ public class LimboCache { cache.put(name, new LimboPlayer(name, loc, gameMode, operator, playerGroup, flying)); } - public void addLimboPlayer(Player player, String group) { + public void addLimboPlayer(final Player player, final String group) { cache.put(player.getName().toLowerCase(), new LimboPlayer(player.getName().toLowerCase(), group)); } - public void deleteLimboPlayer(String name) { + public void deleteLimboPlayer(final String name) { cache.remove(name); } - public LimboPlayer getLimboPlayer(String name) { + public LimboPlayer getLimboPlayer(final String name) { return cache.get(name); } - public boolean hasLimboPlayer(String name) { + public boolean hasLimboPlayer(final String name) { return cache.containsKey(name); } - public void updateLimboPlayer(Player player) { + public void updateLimboPlayer(final Player player) { if (this.hasLimboPlayer(player.getName().toLowerCase())) { this.deleteLimboPlayer(player.getName().toLowerCase()); } diff --git a/src/main/java/cn/citycraft/AuthMe/commands/RegisterCommand.java b/src/main/java/cn/citycraft/AuthMe/commands/RegisterCommand.java index 82b5c17..bf98850 100644 --- a/src/main/java/cn/citycraft/AuthMe/commands/RegisterCommand.java +++ b/src/main/java/cn/citycraft/AuthMe/commands/RegisterCommand.java @@ -7,7 +7,6 @@ import org.bukkit.entity.Player; import cn.citycraft.AuthMe.AuthMe; import cn.citycraft.AuthMe.cache.auth.PlayerAuth; -import cn.citycraft.AuthMe.security.RandomString; import cn.citycraft.AuthMe.settings.Messages; import cn.citycraft.AuthMe.settings.Settings; @@ -15,14 +14,14 @@ public class RegisterCommand implements CommandExecutor { public PlayerAuth auth; public AuthMe plugin; - private Messages m = Messages.getInstance(); + private final Messages m = Messages.getInstance(); - public RegisterCommand(AuthMe plugin) { + public RegisterCommand(final AuthMe plugin) { this.plugin = plugin; } @Override - public boolean onCommand(CommandSender sender, Command cmnd, String label, String[] args) { + public boolean onCommand(final CommandSender sender, final Command cmnd, final String label, final String[] args) { if (!(sender instanceof Player)) { sender.sendMessage("Player Only! Use 'authme register ' instead"); return true; @@ -36,28 +35,30 @@ public class RegisterCommand implements CommandExecutor { m.send(player, "no_perm"); return true; } - if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { - if (Settings.doubleEmailCheck) { - if (args.length < 2 || !args[0].equals(args[1])) { - m.send(player, "usage_reg"); - return true; - } - } - final String email = args[0]; - if (!Settings.isEmailCorrect(email)) { - m.send(player, "email_invalid"); - return true; - } - RandomString rand = new RandomString(Settings.getRecoveryPassLength); - final String thePass = rand.nextString(); - plugin.management.performRegister(player, thePass, email); - return true; - } - if (args.length > 1 && Settings.getEnablePasswordVerifier) + // TODO 计划删除邮箱功能 + // if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { + // if (Settings.doubleEmailCheck) { + // if (args.length < 2 || !args[0].equals(args[1])) { + // m.send(player, "usage_reg"); + // return true; + // } + // } + // final String email = args[0]; + // if (!Settings.isEmailCorrect(email)) { + // m.send(player, "email_invalid"); + // return true; + // } + // RandomString rand = new RandomString(Settings.getRecoveryPassLength); + // final String thePass = rand.nextString(); + // plugin.management.performRegister(player, thePass, email); + // return true; + // } + if (args.length > 1 && Settings.getEnablePasswordVerifier) { if (!args[0].equals(args[1])) { m.send(player, "password_error"); return true; } + } plugin.management.performRegister(player, args[0], ""); return true; } diff --git a/src/main/java/cn/citycraft/AuthMe/listener/AuthMeInventoryPacketAdapter.java b/src/main/java/cn/citycraft/AuthMe/listener/AuthMeInventoryPacketAdapter.java deleted file mode 100644 index ab4b513..0000000 --- a/src/main/java/cn/citycraft/AuthMe/listener/AuthMeInventoryPacketAdapter.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2015 AuthMe-Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package cn.citycraft.AuthMe.listener; - -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.Collections; -import java.util.logging.Level; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.ProtocolManager; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; - -import cn.citycraft.AuthMe.AuthMe; -import cn.citycraft.AuthMe.cache.auth.PlayerCache; -import cn.citycraft.AuthMe.settings.Settings; - -public class AuthMeInventoryPacketAdapter extends PacketAdapter { - - private static final int HOTBAR_SIZE = 9; - // 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; - private static final int PLAYER_INVENTORY = 0; - - public AuthMeInventoryPacketAdapter(AuthMe plugin) { - super(plugin, PacketType.Play.Server.SET_SLOT, PacketType.Play.Server.WINDOW_ITEMS); - } - - @Override - public void onPacketSending(PacketEvent packetEvent) { - Player player = packetEvent.getPlayer(); - PacketContainer packet = packetEvent.getPacket(); - - byte windowId = packet.getIntegers().read(0).byteValue(); - if (windowId == PLAYER_INVENTORY && Settings.protectInventoryBeforeLogInEnabled && !PlayerCache.getInstance().isAuthenticated(player.getName())) { - packetEvent.setCancelled(true); - } - } - - public void register() { - ProtocolLibrary.getProtocolManager().addPacketListener(this); - } - - public void sendInventoryPacket(Player player) { - ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); - PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS); - - // we are sending our own inventory - inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY); - - ItemStack[] playerCrafting = new ItemStack[PLAYER_CRAFTING_SIZE]; - Arrays.fill(playerCrafting, new ItemStack(Material.AIR)); - ItemStack[] armorContents = player.getInventory().getArmorContents(); - ItemStack[] mainInventory = player.getInventory().getContents(); - - // bukkit saves the armor in reversed order - Collections.reverse(Arrays.asList(armorContents)); - - // same main inventory. The hotbar is at the beginning but it should be at the end of the array - ItemStack[] hotbar = Arrays.copyOfRange(mainInventory, 0, HOTBAR_SIZE); - ItemStack[] storedInventory = Arrays.copyOfRange(mainInventory, HOTBAR_SIZE, mainInventory.length); - - // concat all parts of the inventory together - int inventorySize = playerCrafting.length + armorContents.length + mainInventory.length; - ItemStack[] completeInventory = new ItemStack[inventorySize]; - - System.arraycopy(playerCrafting, 0, completeInventory, 0, playerCrafting.length); - System.arraycopy(armorContents, 0, completeInventory, playerCrafting.length, armorContents.length); - - // storedInventory and hotbar - System.arraycopy(storedInventory, 0, completeInventory, playerCrafting.length + armorContents.length, storedInventory.length); - System.arraycopy(hotbar, 0, completeInventory, playerCrafting.length + armorContents.length + storedInventory.length, hotbar.length); - - inventoryPacket.getItemArrayModifier().write(0, completeInventory); - try { - protocolManager.sendServerPacket(player, inventoryPacket, false); - } catch (InvocationTargetException invocationExc) { - plugin.getLogger().log(Level.WARNING, "Error during inventory recovery", invocationExc); - } - } -} diff --git a/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener.java b/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener.java index 9d0a073..82e7165 100644 --- a/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener.java +++ b/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.PatternSyntaxException; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -272,27 +271,9 @@ public class AuthMePlayerListener implements Listener { return; } - if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !plugin.authmePermissible(player, "authme.bypassantibot")) { - final String code = Utils.getCountryCode(event.getAddress().getHostAddress()); - if (((code == null) || 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 && !plugin.authmePermissible(player, "authme.bypassantibot")) { - final String code = Utils.getCountryCode(event.getAddress().getHostAddress()); - if (((code == null) || !Settings.countries.contains(code))) { - event.setKickMessage(m.send("country_banned")[0]); - event.setResult(PlayerLoginEvent.Result.KICK_OTHER); - return; - } - } - - // TODO: Add message to the messages file!!! if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) { if (Settings.antiBotInAction) { - event.setKickMessage("AntiBot service in action! You actually need to be registered!"); + event.setKickMessage(m.send("antibot_no_register")[0]); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } else { @@ -313,28 +294,12 @@ public class AuthMePlayerListener implements Listener { } 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 (final Exception exc) { - event.setKickMessage("allowed char : " + regex); - event.setResult(PlayerLoginEvent.Result.KICK_OTHER); - } - return; - } - } catch (final 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 (final Exception exc) { - event.setKickMessage("allowed char : " + regex); - event.setResult(PlayerLoginEvent.Result.KICK_OTHER); } + } catch (final Exception pse) { + event.setKickMessage("allowed char : " + regex); + event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } @@ -383,31 +348,10 @@ public class AuthMePlayerListener implements Listener { if (Utils.checkAuth(player)) { return; } - - if (!Settings.isMovementAllowed) { - final Location from = event.getFrom(); - from.setPitch(event.getTo().getPitch()); - from.setYaw(event.getTo().getYaw()); - - event.setTo(from); - return; - } - - if (Settings.getMovementRadius == 0) { - return; - } - - final int radius = Settings.getMovementRadius; - final Location spawn = plugin.getSpawnLocation(player); - if (spawn != null && spawn.getWorld() != null) { - if (!event.getPlayer().getWorld().equals(spawn.getWorld())) { - event.getPlayer().teleport(spawn); - return; - } - if ((spawn.distance(player.getLocation()) > radius)) { - event.getPlayer().teleport(spawn); - } - } + final Location from = event.getFrom(); + from.setPitch(event.getTo().getPitch()); + from.setYaw(event.getTo().getYaw()); + event.setTo(from); } @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) diff --git a/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener16.java b/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener16.java deleted file mode 100644 index 9cc5596..0000000 --- a/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener16.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.citycraft.AuthMe.listener; - -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.PlayerEditBookEvent; - -import cn.citycraft.AuthMe.AuthMe; -import cn.citycraft.AuthMe.Utils; - -public class AuthMePlayerListener16 implements Listener { - - public AuthMe plugin; - - public AuthMePlayerListener16(AuthMe plugin) { - this.plugin = plugin; - } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) - public void onPlayerEditBook(PlayerEditBookEvent event) { - Player player = event.getPlayer(); - if (player == null || Utils.checkAuth(player)) - return; - event.setCancelled(true); - } - -} diff --git a/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener18.java b/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener18.java deleted file mode 100644 index 3c17716..0000000 --- a/src/main/java/cn/citycraft/AuthMe/listener/AuthMePlayerListener18.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.citycraft.AuthMe.listener; - -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.PlayerInteractAtEntityEvent; - -import cn.citycraft.AuthMe.AuthMe; -import cn.citycraft.AuthMe.Utils; - -public class AuthMePlayerListener18 implements Listener { - - public AuthMe plugin; - - public AuthMePlayerListener18(AuthMe plugin) { - this.plugin = plugin; - } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) - public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { - Player player = event.getPlayer(); - if (player == null || Utils.checkAuth(player)) - return; - event.setCancelled(true); - } - -} diff --git a/src/main/java/cn/citycraft/AuthMe/listener/AuthMeServerListener.java b/src/main/java/cn/citycraft/AuthMe/listener/AuthMeServerListener.java index 321822a..5a29f7a 100644 --- a/src/main/java/cn/citycraft/AuthMe/listener/AuthMeServerListener.java +++ b/src/main/java/cn/citycraft/AuthMe/listener/AuthMeServerListener.java @@ -39,10 +39,6 @@ public class AuthMeServerListener implements Listener { plugin.permission = null; ConsoleLogger.showError("Vault has been disabled, unhook permissions!"); } - if (pluginName.equalsIgnoreCase("ProtocolLib")) { - plugin.inventoryProtector = null; - ConsoleLogger.showError("ProtocolLib has been disabled, unhook packet inventory protection!"); - } } @EventHandler(priority = EventPriority.HIGHEST) @@ -54,9 +50,6 @@ public class AuthMeServerListener implements Listener { if (pluginName.equalsIgnoreCase("Vault")) { plugin.checkVault(); } - if (pluginName.equalsIgnoreCase("ProtocolLib")) { - plugin.checkProtocolLib(); - } } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/cn/citycraft/AuthMe/process/join/AsyncronousJoin.java b/src/main/java/cn/citycraft/AuthMe/process/join/AsyncronousJoin.java index a0f0523..4ddc51f 100644 --- a/src/main/java/cn/citycraft/AuthMe/process/join/AsyncronousJoin.java +++ b/src/main/java/cn/citycraft/AuthMe/process/join/AsyncronousJoin.java @@ -12,7 +12,6 @@ import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; import cn.citycraft.AuthMe.AuthMe; -import cn.citycraft.AuthMe.ConsoleLogger; import cn.citycraft.AuthMe.Utils; import cn.citycraft.AuthMe.Utils.GroupType; import cn.citycraft.AuthMe.cache.auth.PlayerAuth; @@ -26,7 +25,6 @@ import cn.citycraft.AuthMe.settings.Spawn; import cn.citycraft.AuthMe.task.MessageTask; import cn.citycraft.AuthMe.task.TimeoutTask; import fr.xephi.authme.events.FirstSpawnTeleportEvent; -import fr.xephi.authme.events.ProtectInventoryEvent; import fr.xephi.authme.events.SpawnTeleportEvent; public class AsyncronousJoin { @@ -126,17 +124,6 @@ public class AsyncronousJoin { } placePlayerSafely(player, spawnLoc); LimboCache.getInstance().updateLimboPlayer(player); - // protect inventory - if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) { - final ProtectInventoryEvent ev = new ProtectInventoryEvent(player); - plugin.getServer().getPluginManager().callEvent(ev); - if (ev.isCancelled()) { - plugin.inventoryProtector.sendInventoryPacket(player); - if (!Settings.noConsoleSpam) { - ConsoleLogger.info("玩家 " + player.getName() + " 的背包保护事件已被取消..."); - } - } - } } else { if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { sched.scheduleSyncDelayedTask(plugin, new Runnable() { diff --git a/src/main/java/cn/citycraft/AuthMe/process/login/ProcessSyncronousPlayerLogin.java b/src/main/java/cn/citycraft/AuthMe/process/login/ProcessSyncronousPlayerLogin.java index ccd28c7..8e63ff1 100644 --- a/src/main/java/cn/citycraft/AuthMe/process/login/ProcessSyncronousPlayerLogin.java +++ b/src/main/java/cn/citycraft/AuthMe/process/login/ProcessSyncronousPlayerLogin.java @@ -19,7 +19,6 @@ import cn.citycraft.AuthMe.listener.AuthMePlayerListener; import cn.citycraft.AuthMe.settings.Settings; import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.events.LoginEvent; -import fr.xephi.authme.events.RestoreInventoryEvent; import fr.xephi.authme.events.SpawnTeleportEvent; public class ProcessSyncronousPlayerLogin implements Runnable { @@ -62,12 +61,6 @@ public class ProcessSyncronousPlayerLogin implements Runnable { * world inventory ! */ player.setGameMode(limbo.getGameMode()); - // Inventory - Make it after restore GameMode , cause we need to - // restore the - // right inventory in the right gamemode - if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) { - restoreInventory(); - } if (Settings.forceOnlyAfterLogin) { player.setGameMode(GameMode.SURVIVAL); } @@ -160,14 +153,6 @@ public class ProcessSyncronousPlayerLogin implements Runnable { Utils.packCoords(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), player); } - protected void restoreInventory() { - final RestoreInventoryEvent event = new RestoreInventoryEvent(player); - Bukkit.getServer().getPluginManager().callEvent(event); - if (!event.isCancelled()) { - plugin.inventoryProtector.sendInventoryPacket(player); - } - } - protected void restoreOpState() { player.setOp(limbo.getOperator()); if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { diff --git a/src/main/java/cn/citycraft/AuthMe/process/register/AsyncronousRegister.java b/src/main/java/cn/citycraft/AuthMe/process/register/AsyncronousRegister.java index 17735d5..975c30f 100644 --- a/src/main/java/cn/citycraft/AuthMe/process/register/AsyncronousRegister.java +++ b/src/main/java/cn/citycraft/AuthMe/process/register/AsyncronousRegister.java @@ -40,47 +40,48 @@ public class AsyncronousRegister { if (!allowRegister) { return; } - if (!email.isEmpty() && !email.equals("")) { - if (Settings.getmaxRegPerEmail > 0) { - if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { - m.send(player, "max_reg"); - return; - } - } - emailRegister(); - return; - } + // TODO 计划删除邮箱 + // if (!email.isEmpty() && !email.equals("")) { + // if (Settings.getmaxRegPerEmail > 0) { + // if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { + // m.send(player, "max_reg"); + // return; + // } + // } + // emailRegister(); + // return; + // } passwordRegister(); } - - protected void emailRegister() { - if (Settings.getmaxRegPerEmail > 0) { - if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { - m.send(player, "max_reg"); - return; - } - } - PlayerAuth auth; - try { - final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); - auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player - .getLocation() - .getWorld() - .getName(), email, player.getName()); - } catch (final NoSuchAlgorithmException e) { - ConsoleLogger.showError(e.getMessage()); - m.send(player, "error"); - return; - } - if (PasswordSecurity.userSalt.containsKey(name)) { - auth.setSalt(PasswordSecurity.userSalt.get(name)); - } - database.saveAuth(auth); - database.updateEmail(auth); - database.updateSession(auth); - final ProcessSyncronousEmailRegister syncronous = new ProcessSyncronousEmailRegister(player, plugin); - plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous); - } + // TODO 计划删除邮箱 + // protected void emailRegister() { + // if (Settings.getmaxRegPerEmail > 0) { + // if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { + // m.send(player, "max_reg"); + // return; + // } + // } + // PlayerAuth auth; + // try { + // final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); + // auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player + // .getLocation() + // .getWorld() + // .getName(), email, player.getName()); + // } catch (final NoSuchAlgorithmException e) { + // ConsoleLogger.showError(e.getMessage()); + // m.send(player, "error"); + // return; + // } + // if (PasswordSecurity.userSalt.containsKey(name)) { + // auth.setSalt(PasswordSecurity.userSalt.get(name)); + // } + // database.saveAuth(auth); + // database.updateEmail(auth); + // database.updateSession(auth); + // final ProcessSyncronousEmailRegister syncronous = new ProcessSyncronousEmailRegister(player, plugin); + // plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous); + // } protected String getIp() { return plugin.getIP(player); diff --git a/src/main/java/cn/citycraft/AuthMe/process/register/ProcessSyncronousPasswordRegister.java b/src/main/java/cn/citycraft/AuthMe/process/register/ProcessSyncronousPasswordRegister.java index c583d00..ec19354 100644 --- a/src/main/java/cn/citycraft/AuthMe/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/cn/citycraft/AuthMe/process/register/ProcessSyncronousPasswordRegister.java @@ -20,7 +20,6 @@ import cn.citycraft.AuthMe.task.TimeoutTask; import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RegisterTeleportEvent; -import fr.xephi.authme.events.RestoreInventoryEvent; public class ProcessSyncronousPasswordRegister implements Runnable { @@ -48,15 +47,6 @@ public class ProcessSyncronousPasswordRegister implements Runnable { Utils.safeTP(player, tpEvent.getTo()); } } - - if (Settings.protectInventoryBeforeLogInEnabled && plugin.inventoryProtector != null) { - final RestoreInventoryEvent event = new RestoreInventoryEvent(player); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()) { - plugin.inventoryProtector.sendInventoryPacket(player); - } - } - limbo.getTimeoutTaskId().cancel(); limbo.getMessageTaskId().cancel(); LimboCache.getInstance().deleteLimboPlayer(name); diff --git a/src/main/java/cn/citycraft/AuthMe/settings/Settings.java b/src/main/java/cn/citycraft/AuthMe/settings/Settings.java index cadbfb1..9ab2e82 100644 --- a/src/main/java/cn/citycraft/AuthMe/settings/Settings.java +++ b/src/main/java/cn/citycraft/AuthMe/settings/Settings.java @@ -52,11 +52,11 @@ public final class Settings { delayRecall, getMaxLoginPerIp, getMaxJoinPerIp, getMySQLMaxConnections; public static boolean isPermissionCheckEnabled, isRegistrationEnabled, isForcedRegistrationEnabled, isTeleportToSpawnEnabled, isSessionsEnabled, isChatAllowed, isAllowRestrictedIp, isMovementAllowed, isKickNonRegisteredEnabled, isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled, isSaveQuitLocationEnabled, isForceSurvivalModeEnabled, isResetInventoryIfCreative, - isCachingEnabled, isKickOnWrongPasswordEnabled, getEnablePasswordVerifier, protectInventoryBeforeLogInEnabled, isBackupActivated, isBackupOnStart, isBackupOnStop, isStopEnabled, - reloadSupport, rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, useCaptcha, emailRegistration, multiverse, bungee, banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange, - disableSocialSpy, forceOnlyAfterLogin, useEssentialsMotd, usePurge, purgePlayerDat, purgeEssentialsFile, supportOldPassword, purgeLimitedCreative, purgeAntiXray, purgePermissions, - enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect, - customAttributes, generateImage, isRemoveSpeedEnabled; + isCachingEnabled, isKickOnWrongPasswordEnabled, getEnablePasswordVerifier, isBackupActivated, isBackupOnStart, isBackupOnStop, isStopEnabled, reloadSupport, rakamakUseIp, noConsoleSpam, + removePassword, displayOtherAccounts, useCaptcha, emailRegistration, multiverse, bungee, banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange, disableSocialSpy, forceOnlyAfterLogin, + useEssentialsMotd, usePurge, purgePlayerDat, purgeEssentialsFile, supportOldPassword, purgeLimitedCreative, purgeAntiXray, purgePermissions, enableProtection, enableAntiBot, recallEmail, + useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, noTeleport, applyBlindEffect, customAttributes, generateImage, + isRemoveSpeedEnabled; public static final File LOG_FILE = new File(APLUGIN_FOLDER, "authme.log"); public static int purgeDelay = 60; public static final File SETTINGS_FILE = new File(APLUGIN_FOLDER, "config.yml"); @@ -69,11 +69,6 @@ public final class Settings { protected static FileConfig configFile; - public Settings(final AuthMe pl) { - plugin = pl; - configFile = (FileConfig) plugin.getConfig(); - } - /** * Config option for setting and check restricted user by username;ip , * return false if ip and name doesnt amtch with player that join the @@ -155,7 +150,6 @@ public final class Settings { isForceSpawnLocOnJoinEnabled = configFile.getBoolean("settings.restrictions.ForceSpawnLocOnJoinEnabled", false); isSaveQuitLocationEnabled = configFile.getBoolean("settings.restrictions.SaveQuitLocation", false); isForceSurvivalModeEnabled = configFile.getBoolean("settings.GameMode.ForceSurvivalMode", false); - isResetInventoryIfCreative = configFile.getBoolean("settings.GameMode.ResetInventoryIfCreative", false); getmaxRegPerIp = configFile.getInt("settings.restrictions.maxRegPerIp", 1); getPasswordHash = getPasswordHash(); getUnloggedinGroup = configFile.getString("settings.security.unLoggedinGroup", "unLoggedInGroup"); @@ -185,7 +179,6 @@ public final class Settings { 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); passwordMaxLength = configFile.getInt("settings.security.passwordMaxLength", 20); isBackupActivated = configFile.getBoolean("BackupSystem.ActivateBackup", false); isBackupOnStart = configFile.getBoolean("BackupSystem.OnServerStart", false); @@ -366,6 +359,11 @@ public final class Settings { } } + public Settings(final AuthMe pl) { + plugin = pl; + configFile = (FileConfig) plugin.getConfig(); + } + public void mergeConfig() { boolean changes = false; if (configFile.contains("Xenoforo.predefinedSalt")) { diff --git a/src/main/java/cn/citycraft/AuthMe/task/ChangePasswordTask.java b/src/main/java/cn/citycraft/AuthMe/task/ChangePasswordTask.java index ffbb3b8..e03897d 100644 --- a/src/main/java/cn/citycraft/AuthMe/task/ChangePasswordTask.java +++ b/src/main/java/cn/citycraft/AuthMe/task/ChangePasswordTask.java @@ -19,7 +19,7 @@ public class ChangePasswordTask implements Runnable { private final Player player; private final AuthMe plugin; - public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword) { + public ChangePasswordTask(final AuthMe plugin, final Player player, final String oldPassword, final String newPassword) { this.plugin = plugin; this.player = player; this.oldPassword = oldPassword; @@ -28,11 +28,11 @@ public class ChangePasswordTask implements Runnable { @Override public void run() { - Messages m = Messages.getInstance(); + final Messages m = Messages.getInstance(); try { - String name = player.getName().toLowerCase(); - String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, newPassword, name); - PlayerAuth auth = PlayerCache.getInstance().getAuth(name); + final String name = player.getName().toLowerCase(); + final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, newPassword, name); + final PlayerAuth auth = PlayerCache.getInstance().getAuth(name); if (PasswordSecurity.comparePasswordWithHash(oldPassword, auth.getHash(), player.getName())) { auth.setHash(hashnew); if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null) { @@ -47,11 +47,11 @@ public class ChangePasswordTask implements Runnable { plugin.database.updateSalt(auth); PlayerCache.getInstance().updatePlayer(auth); m.send(player, "pwd_changed"); - ConsoleLogger.info(player.getName() + " changed his password"); + ConsoleLogger.info(player.getName() + " 修改了账户密码!"); } else { m.send(player, "wrong_pwd"); } - } catch (NoSuchAlgorithmException ex) { + } catch (final NoSuchAlgorithmException ex) { ConsoleLogger.showError(ex.getMessage()); m.send(player, "error"); } diff --git a/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java b/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java deleted file mode 100644 index 8eb93ff..0000000 --- a/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -package fr.xephi.authme.events; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -/** - * - * This event is call just after store inventory into cache and will empty the - * player inventory. - * - * @author Xephi59 - */ -public class ProtectInventoryEvent extends CustomEvent { - - private ItemStack[] emptyArmor = null; - private ItemStack[] emptyInventory = null; - private Player player; - private ItemStack[] storedarmor; - private ItemStack[] storedinventory; - - public ProtectInventoryEvent(Player player) { - super(true); - this.player = player; - this.storedinventory = player.getInventory().getContents(); - this.storedarmor = player.getInventory().getArmorContents(); - this.emptyInventory = new ItemStack[36]; - this.emptyArmor = new ItemStack[4]; - } - - public ItemStack[] getEmptyArmor() { - return this.emptyArmor; - } - - public ItemStack[] getEmptyInventory() { - return this.emptyInventory; - } - - public Player getPlayer() { - return this.player; - } - - public ItemStack[] getStoredArmor() { - return this.storedarmor; - } - - public ItemStack[] getStoredInventory() { - return this.storedinventory; - } - - public void setNewArmor(ItemStack[] emptyArmor) { - this.emptyArmor = emptyArmor; - } - - public void setNewInventory(ItemStack[] emptyInventory) { - this.emptyInventory = emptyInventory; - } - -} diff --git a/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java b/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java deleted file mode 100644 index 7d59736..0000000 --- a/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package fr.xephi.authme.events; - -import org.bukkit.entity.Player; - -/** - * - * This event is call when a creative inventory is reseted. - * - * @author Xephi59 - */ -public class ResetInventoryEvent extends CustomEvent { - - private Player player; - - public ResetInventoryEvent(Player player) { - super(true); - this.player = player; - } - - public Player getPlayer() { - return this.player; - } - - public void setPlayer(Player player) { - this.player = player; - } - -} diff --git a/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java b/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java deleted file mode 100644 index 22f01b5..0000000 --- a/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -package fr.xephi.authme.events; - -import org.bukkit.entity.Player; - -/** - * This event restore the inventory. - * - * @author Xephi59 - */ -public class RestoreInventoryEvent extends CustomEvent { - - private Player player; - - public RestoreInventoryEvent(Player player) { - this.player = player; - } - - public RestoreInventoryEvent(Player player, boolean async) { - super(async); - this.player = player; - } - - public Player getPlayer() { - return this.player; - } - - public void setPlayer(Player player) { - this.player = player; - } -} diff --git a/src/main/java/fr/xephi/authme/events/StoreInventoryEvent.java b/src/main/java/fr/xephi/authme/events/StoreInventoryEvent.java deleted file mode 100644 index e58fbcb..0000000 --- a/src/main/java/fr/xephi/authme/events/StoreInventoryEvent.java +++ /dev/null @@ -1,54 +0,0 @@ -package fr.xephi.authme.events; - -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import cn.citycraft.AuthMe.cache.backup.JsonCache; - -/** - * This event is call just before write inventory content to cache - * - * @author Xephi59 - */ -public class StoreInventoryEvent extends CustomEvent { - - private ItemStack[] armor; - private ItemStack[] inventory; - private Player player; - - public StoreInventoryEvent(Player player) { - this.player = player; - this.inventory = player.getInventory().getContents(); - this.armor = player.getInventory().getArmorContents(); - } - - public StoreInventoryEvent(Player player, JsonCache jsonCache) { - this.player = player; - this.inventory = player.getInventory().getContents(); - this.armor = player.getInventory().getArmorContents(); - } - - public ItemStack[] getArmor() { - return this.armor; - } - - public ItemStack[] getInventory() { - return this.inventory; - } - - public Player getPlayer() { - return this.player; - } - - public void setArmor(ItemStack[] armor) { - this.armor = armor; - } - - public void setInventory(ItemStack[] inventory) { - this.inventory = inventory; - } - - public void setPlayer(Player player) { - this.player = player; - } -} diff --git a/src/main/resources/messages_zhcn.yml b/src/main/resources/messages_zhcn.yml index c8985b2..d659d19 100644 --- a/src/main/resources/messages_zhcn.yml +++ b/src/main/resources/messages_zhcn.yml @@ -54,4 +54,5 @@ email_changed: '&f邮箱已改变!' email_send: '&f恢复邮件已发送!' country_banned: '&f这个服务器禁止该国家登陆!' antibot_auto_enabled: '[AuthMe] 防机器人程序由于大量异常连接而启用!' +antibot_no_register: '[AuthMe] 防机器人程序已启用 目前仅限已注册玩家登录!' antibot_auto_disabled: '[AuthMe] 防机器人程序由于异常连接减少而在 %m 分钟后停止!' \ No newline at end of file