From 4a22c916b1697b7cb530048d173f97afd1504614 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sun, 4 Oct 2015 14:37:06 +0200 Subject: [PATCH 01/11] cleanup --- src/main/java/fr/xephi/authme/AuthMe.java | 53 ++++++++++++----------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 8ea2a79d7..dcff35fde 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -1,8 +1,35 @@ package fr.xephi.authme; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; +import org.apache.logging.log4j.LogManager; + +import org.mcstats.Metrics; import com.comphenix.protocol.ProtocolLibrary; import com.earth2me.essentials.Essentials; import com.onarandombox.MultiverseCore.MultiverseCore; +import net.milkbowl.vault.permission.Permission; +import net.minelink.ctplus.CombatTagPlus; + import fr.xephi.authme.api.API; import fr.xephi.authme.api.NewAPI; import fr.xephi.authme.cache.auth.PlayerAuth; @@ -23,31 +50,6 @@ 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 net.milkbowl.vault.permission.Permission; -import net.minelink.ctplus.CombatTagPlus; -import org.apache.logging.log4j.LogManager; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitTask; -import org.mcstats.Metrics; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Logger; public class AuthMe extends JavaPlugin { @@ -136,7 +138,6 @@ public class AuthMe extends JavaPlugin { m = Messages.getInstance(); // Start the metrics service - // TODO: add a setting to disable metrics try { Metrics metrics = new Metrics(this); metrics.start(); From de5ecfcb933eff5514c90311bf3586aa6bbcc7c7 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Mon, 5 Oct 2015 22:28:31 +0200 Subject: [PATCH 02/11] Fix compatibility issues --- pom.xml | 10 ++++++++++ src/main/java/fr/xephi/authme/AuthMe.java | 3 +-- .../xephi/authme/listener/AuthMeInventoryListener.java | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 86fe315e0..cca09242c 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ com.sun.mail:javax.mail com.comphenix.attribute:AttributeStorage org.mcstats.bukkit:metrics + com.google.code.gson:gson @@ -241,6 +242,15 @@ true + + + com.google.code.gson + gson + 2.4 + compile + true + + diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index dcff35fde..086e16ec9 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -24,7 +24,6 @@ import org.bukkit.scheduler.BukkitTask; import org.apache.logging.log4j.LogManager; import org.mcstats.Metrics; -import com.comphenix.protocol.ProtocolLibrary; import com.earth2me.essentials.Essentials; import com.onarandombox.MultiverseCore.MultiverseCore; import net.milkbowl.vault.permission.Permission; @@ -474,7 +473,7 @@ public class AuthMe extends JavaPlugin { if (Settings.protectInventoryBeforeLogInEnabled) { if (server.getPluginManager().isPluginEnabled("ProtocolLib")) { inventoryProtector = new AuthMeInventoryListener(this); - ProtocolLibrary.getProtocolManager().addPacketListener(inventoryProtector); + inventoryProtector.register(); } else { ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it..."); Settings.protectInventoryBeforeLogInEnabled = false; diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java index 9b59a1483..bbaafbfa7 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java @@ -60,6 +60,10 @@ public class AuthMeInventoryListener extends PacketAdapter { } } + 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); From 9c477c590c4d3403dcb54d99fdc5792435688b82 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Mon, 5 Oct 2015 22:57:33 +0200 Subject: [PATCH 03/11] fix 1.7.10 compatibility issue --- src/main/java/fr/xephi/authme/AuthMe.java | 4 +++ .../authme/listener/AuthMePlayerListener.java | 8 ------ .../listener/AuthMePlayerListener18.java | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 086e16ec9..4d2421e71 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -258,6 +258,10 @@ public class AuthMe extends JavaPlugin { // Register events pm.registerEvents(new AuthMePlayerListener(this), this); + // Try to register 1.8 player listeners + ConsoleLogger.info("Trying to register bukkit 1.8 listeners, if an error is shown below please don't report it!"); + ConsoleLogger.info("It only means that you're using a previous version of the server."); + pm.registerEvents(new AuthMePlayerListener18(this), this); pm.registerEvents(new AuthMeBlockListener(this), this); pm.registerEvents(new AuthMeEntityListener(this), this); pm.registerEvents(new AuthMeServerListener(this), this); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 900a01cfd..801502e56 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -448,14 +448,6 @@ public class AuthMePlayerListener implements Listener { event.setCancelled(true); } - @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); - } - @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerDropItem(PlayerDropItemEvent event) { if (Utils.checkAuth(event.getPlayer())) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java new file mode 100644 index 000000000..0b88b4d16 --- /dev/null +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java @@ -0,0 +1,27 @@ +package fr.xephi.authme.listener; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +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.*; + +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); + } + +} From d7dfa3e4ac3b38b57a61b107a655dd9cecc006b0 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 6 Oct 2015 03:57:17 +0700 Subject: [PATCH 04/11] fill with air --- .../xephi/authme/listener/AuthMeInventoryListener.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java index bbaafbfa7..08ccacff3 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java @@ -22,20 +22,18 @@ import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; - import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.settings.Settings; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import java.lang.reflect.InvocationTargetException; - import java.util.Arrays; import java.util.Collections; import java.util.logging.Level; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - public class AuthMeInventoryListener extends PacketAdapter { private static final int PLAYER_INVENTORY = 0; @@ -72,6 +70,7 @@ public class AuthMeInventoryListener extends PacketAdapter { 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(); From 157b028712668abc184d0924f0c54784bee8a0e0 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 6 Oct 2015 04:07:49 +0700 Subject: [PATCH 05/11] check the class is exist --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 4d2421e71..7821fa89c 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -259,9 +259,11 @@ public class AuthMe extends JavaPlugin { // Register events pm.registerEvents(new AuthMePlayerListener(this), this); // Try to register 1.8 player listeners - ConsoleLogger.info("Trying to register bukkit 1.8 listeners, if an error is shown below please don't report it!"); - ConsoleLogger.info("It only means that you're using a previous version of the server."); - pm.registerEvents(new AuthMePlayerListener18(this), this); + try { + Class.forName("org.bukkit.event.player.PlayerInteractAtEntityEvent"); + pm.registerEvents(new AuthMePlayerListener18(this), this); + } catch (ClassNotFoundException ignore) { + } pm.registerEvents(new AuthMeBlockListener(this), this); pm.registerEvents(new AuthMeEntityListener(this), this); pm.registerEvents(new AuthMeServerListener(this), this); From 3f179ade81580ff32c97f47dea031fde3e49df23 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 6 Oct 2015 07:11:51 +0700 Subject: [PATCH 06/11] rename inventory listener class --- src/main/java/fr/xephi/authme/AuthMe.java | 56 +++++++++---------- ...java => AuthMeInventoryPacketAdapter.java} | 4 +- 2 files changed, 29 insertions(+), 31 deletions(-) rename src/main/java/fr/xephi/authme/listener/{AuthMeInventoryListener.java => AuthMeInventoryPacketAdapter.java} (97%) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 7821fa89c..b252d5ba3 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -1,34 +1,7 @@ package fr.xephi.authme; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitTask; -import org.apache.logging.log4j.LogManager; - -import org.mcstats.Metrics; import com.earth2me.essentials.Essentials; import com.onarandombox.MultiverseCore.MultiverseCore; -import net.milkbowl.vault.permission.Permission; -import net.minelink.ctplus.CombatTagPlus; - import fr.xephi.authme.api.API; import fr.xephi.authme.api.NewAPI; import fr.xephi.authme.cache.auth.PlayerAuth; @@ -49,6 +22,31 @@ 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 net.milkbowl.vault.permission.Permission; +import net.minelink.ctplus.CombatTagPlus; +import org.apache.logging.log4j.LogManager; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; +import org.mcstats.Metrics; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; public class AuthMe extends JavaPlugin { @@ -74,7 +72,7 @@ public class AuthMe extends JavaPlugin { public Essentials ess; public MultiverseCore multiverse; public CombatTagPlus combatTagPlus; - public AuthMeInventoryListener inventoryProtector; + public AuthMeInventoryPacketAdapter inventoryProtector; // Manager private ModuleManager moduleManager; @@ -478,7 +476,7 @@ public class AuthMe extends JavaPlugin { public void checkProtocolLib() { if (Settings.protectInventoryBeforeLogInEnabled) { if (server.getPluginManager().isPluginEnabled("ProtocolLib")) { - inventoryProtector = new AuthMeInventoryListener(this); + inventoryProtector = new AuthMeInventoryPacketAdapter(this); inventoryProtector.register(); } else { ConsoleLogger.showError("WARNING!!! The protectInventory feature requires ProtocolLib! Disabling it..."); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java similarity index 97% rename from src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java rename to src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java index 08ccacff3..c045a94eb 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java @@ -34,7 +34,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.logging.Level; -public class AuthMeInventoryListener extends PacketAdapter { +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) @@ -42,7 +42,7 @@ public class AuthMeInventoryListener extends PacketAdapter { private static final int PLAYER_CRAFTING_SIZE = 5; private static final int HOTBAR_SIZE = 9; - public AuthMeInventoryListener(AuthMe plugin) { + public AuthMeInventoryPacketAdapter(AuthMe plugin) { super(plugin, PacketType.Play.Server.SET_SLOT, PacketType.Play.Server.WINDOW_ITEMS); } From 4d4931af3f74daf86d23c1a935f56e85ae940aea Mon Sep 17 00:00:00 2001 From: DNx5 Date: Tue, 6 Oct 2015 08:08:32 +0700 Subject: [PATCH 07/11] added reload function into module manager --- src/main/java/fr/xephi/authme/AuthMe.java | 6 +++++- src/main/java/fr/xephi/authme/commands/AdminCommand.java | 3 ++- src/main/java/fr/xephi/authme/modules/ModuleManager.java | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index b252d5ba3..94c7b494d 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -348,6 +348,7 @@ public class AuthMe extends JavaPlugin { // Initialize and setup the database public void setupDatabase() throws Exception { + if (database != null) database.close(); // Backend MYSQL - FILE - SQLITE - SQLITEHIKARI boolean isSQLite = false; switch (Settings.getDataSource) { @@ -704,6 +705,10 @@ public class AuthMe extends JavaPlugin { return count >= Settings.getMaxJoinPerIp; } + public ModuleManager getModuleManager() { + return moduleManager; + } + /** * Get Player real IP through VeryGames method * @@ -736,5 +741,4 @@ public class AuthMe extends JavaPlugin { public String getCountryName(String ip) { return Utils.getCountryName(ip); } - } diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index 573d956fe..49042a433 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -110,11 +110,12 @@ public class AdminCommand implements CommandExecutor { } else if (args[0].equalsIgnoreCase("reload")) { try { Settings.reload(); + plugin.getModuleManager().reloadModules(); m.reloadMessages(); - plugin.database.close(); plugin.setupDatabase(); } catch (Exception e) { ConsoleLogger.showError("Fatal error occurred! Authme instance ABORTED!"); + ConsoleLogger.writeStackTrace(e); plugin.stopOrUnload(); return false; } diff --git a/src/main/java/fr/xephi/authme/modules/ModuleManager.java b/src/main/java/fr/xephi/authme/modules/ModuleManager.java index 32d4d1fa6..0d598fc49 100644 --- a/src/main/java/fr/xephi/authme/modules/ModuleManager.java +++ b/src/main/java/fr/xephi/authme/modules/ModuleManager.java @@ -112,6 +112,11 @@ public class ModuleManager { return count; } + public void reloadModules(){ + unloadModules(); + loadModules(); + } + public void unloadModule(String name) { Iterator it = modules.iterator(); while (it.hasNext()) { From aac4320f4698411ab09be28e683d2b05713eccd5 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 6 Oct 2015 17:11:14 +0200 Subject: [PATCH 08/11] Fix build --- src/main/java/fr/xephi/authme/AuthMe.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 894f17258..6d5f8ab57 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -24,7 +24,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; import org.mcstats.Metrics; -import com.comphenix.protocol.ProtocolLibrary; import net.milkbowl.vault.permission.Permission; import com.onarandombox.MultiverseCore.MultiverseCore; import com.earth2me.essentials.Essentials; @@ -57,8 +56,9 @@ import fr.xephi.authme.datasource.SQLite; import fr.xephi.authme.datasource.SQLite_HIKARI; import fr.xephi.authme.listener.AuthMeBlockListener; import fr.xephi.authme.listener.AuthMeEntityListener; -import fr.xephi.authme.listener.AuthMeInventoryListener; +import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter; import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.listener.AuthMePlayerListener18; import fr.xephi.authme.listener.AuthMeServerListener; import fr.xephi.authme.modules.ModuleManager; import fr.xephi.authme.plugin.manager.BungeeCordMessage; From 807d302b608dfc79179284bc49be41731143753a Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 6 Oct 2015 19:17:03 +0200 Subject: [PATCH 09/11] 1.5.2 compatibility --- pom.xml | 4 +- src/main/java/fr/xephi/authme/AuthMe.java | 7 ++++ .../java/fr/xephi/authme/DataManager.java | 32 +++++++++------ .../authme/listener/AuthMeEntityListener.java | 41 +++++++++++++++---- .../authme/listener/AuthMePlayerListener.java | 7 ---- .../listener/AuthMePlayerListener16.java | 27 ++++++++++++ .../xephi/authme/settings/OtherAccounts.java | 2 +- 7 files changed, 89 insertions(+), 31 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java diff --git a/pom.xml b/pom.xml index cca09242c..7bdad8cf9 100644 --- a/pom.xml +++ b/pom.xml @@ -276,8 +276,7 @@ true - + org.bukkit bukkit @@ -324,6 +323,7 @@ com.comphenix.protocol ProtocolLib 3.4.0 + provided true diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 6d5f8ab57..23c556c8f 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -58,6 +58,7 @@ import fr.xephi.authme.listener.AuthMeBlockListener; import fr.xephi.authme.listener.AuthMeEntityListener; import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter; import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.listener.AuthMePlayerListener16; import fr.xephi.authme.listener.AuthMePlayerListener18; import fr.xephi.authme.listener.AuthMeServerListener; import fr.xephi.authme.modules.ModuleManager; @@ -279,6 +280,12 @@ 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 (ClassNotFoundException ignore) { + } // Try to register 1.8 player listeners try { Class.forName("org.bukkit.event.player.PlayerInteractAtEntityEvent"); diff --git a/src/main/java/fr/xephi/authme/DataManager.java b/src/main/java/fr/xephi/authme/DataManager.java index 43782c5b3..9263443fb 100644 --- a/src/main/java/fr/xephi/authme/DataManager.java +++ b/src/main/java/fr/xephi/authme/DataManager.java @@ -103,21 +103,26 @@ public class DataManager { for (String name : cleared) { try { org.bukkit.OfflinePlayer player = getOfflinePlayer(name); - if (player == null) + File playerFile = null; + if (player == null) { continue; - String playerName = player.getName(); - File playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + playerName + ".dat"); + } + + try { + playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat"); + } catch(Exception ignore) { + } if (playerFile.exists()) { playerFile.delete(); i++; } else { - playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getUniqueId() + ".dat"); + playerFile = new File(plugin.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + player.getName() + ".dat"); if (playerFile.exists()) { playerFile.delete(); i++; } } - } catch (Exception e) { + } catch (Exception ignore) { } } ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files"); @@ -128,18 +133,19 @@ public class DataManager { int i = 0; for (String name : cleared) { try { - File playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); + File playerFile = null; + try { + playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + plugin.getServer().getOfflinePlayer(name).getUniqueId() + ".yml"); + } catch(Exception ignore) { + } if (playerFile.exists()) { playerFile.delete(); i++; } else { - try { - playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + Bukkit.getOfflinePlayer(name).getUniqueId() + ".yml"); - if (playerFile.exists()) { - playerFile.delete(); - i++; - } - } catch (Exception e) { // Don't do nothing if the method getUniqueId() isn't avariable ( MC version < 1.7.5 ) + playerFile = new File(plugin.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); + if (playerFile.exists()) { + playerFile.delete(); + i++; } } } catch (Exception e) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index 34b3b0f24..acd65e0c0 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -2,7 +2,11 @@ package fr.xephi.authme.listener; import fr.xephi.authme.AuthMe; import fr.xephi.authme.Utils; + +import java.lang.reflect.Method; + import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -14,9 +18,16 @@ import org.bukkit.projectiles.ProjectileSource; public class AuthMeEntityListener implements Listener { public AuthMe instance; + private static Method getShooter; + private static boolean shooterIsProjectileSource; public AuthMeEntityListener(AuthMe instance) { this.instance = instance; + try { + Method m = Projectile.class.getDeclaredMethod("getShooter"); + shooterIsProjectileSource = m.getReturnType() != LivingEntity.class; + } catch (Exception ignored) { + } } @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @@ -31,7 +42,7 @@ public class AuthMeEntityListener implements Listener { return; } player.setFireTicks(0); - event.setDamage(0.0); + event.setDamage(0); event.setCancelled(true); } @@ -90,7 +101,7 @@ public class AuthMeEntityListener implements Listener { return; } - event.setAmount(0.0); + event.setAmount(0); event.setCancelled(true); } @@ -126,15 +137,29 @@ public class AuthMeEntityListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile projectile = event.getEntity(); - if (projectile == null) - return; - - ProjectileSource shooter = projectile.getShooter(); - if (shooter == null || !(shooter instanceof Player)) { + Player player = null; + if (projectile == null) { return; } - if (Utils.checkAuth((Player) shooter)) { + if (shooterIsProjectileSource) { + ProjectileSource shooter = projectile.getShooter(); + if (shooter == null || !(shooter instanceof Player)) { + return; + } + player = (Player) shooter; + } else { + try { + if (getShooter == null) { + getShooter = Projectile.class.getMethod("getShooter"); + } + Object obj = getShooter.invoke(null); + player = (Player) obj; + } catch (Exception ignored) { + } + } + + if (Utils.checkAuth(player)) { return; } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 801502e56..5706ef669 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -519,11 +519,4 @@ public class AuthMePlayerListener implements Listener { event.setCancelled(true); } - @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/fr/xephi/authme/listener/AuthMePlayerListener16.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java new file mode 100644 index 000000000..2959b84fc --- /dev/null +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java @@ -0,0 +1,27 @@ +package fr.xephi.authme.listener; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +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.*; + +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/fr/xephi/authme/settings/OtherAccounts.java b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java index 697104d49..0154a3378 100644 --- a/src/main/java/fr/xephi/authme/settings/OtherAccounts.java +++ b/src/main/java/fr/xephi/authme/settings/OtherAccounts.java @@ -45,7 +45,7 @@ public class OtherAccounts extends CustomConfiguration { save(); } } catch (NoSuchMethodError | Exception e) { - //ingore + //ignore } } From a502a479b8f1ebf7baec33f39ef34afbab47fb2b Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Tue, 6 Oct 2015 21:04:06 +0200 Subject: [PATCH 10/11] Fix compatibility --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 23c556c8f..be4c104b8 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -73,9 +73,9 @@ import fr.xephi.authme.settings.Spawn; public class AuthMe extends JavaPlugin { private static AuthMe authme; + private static Server server; + private Logger authmeLogger; - private final Server server = getServer(); - private Logger authmeLogger = Logger.getLogger("AuthMe"); public Management management; public NewAPI api; public SendMailSSL mail; @@ -96,7 +96,7 @@ public class AuthMe extends JavaPlugin { public CombatTagPlus combatTagPlus; public AuthMeInventoryPacketAdapter inventoryProtector; - // Manager + // Module manager private ModuleManager moduleManager; // TODO: Create Manager for fields below @@ -124,6 +124,8 @@ public class AuthMe extends JavaPlugin { @Override public void onEnable() { // Set the Instance + server = getServer(); + authmeLogger = Logger.getLogger("AuthMe"); authme = this; // TODO: split the plugin in more modules From 193c9eda4379c93b1a7d1d5250a2dcb05c6c0750 Mon Sep 17 00:00:00 2001 From: "Gabriele C." Date: Thu, 8 Oct 2015 20:19:43 +0200 Subject: [PATCH 11/11] Update sqlite driver --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7bdad8cf9..bfdd8567b 100644 --- a/pom.xml +++ b/pom.xml @@ -215,7 +215,7 @@ org.xerial sqlite-jdbc - 3.8.11.1 + 3.8.11.2 compile true