From 5749c84c2895a926dcbcd89dd08ccedeb86e672e Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sat, 20 Aug 2016 16:17:10 -0400 Subject: [PATCH] Fix and re-enable AuthMe hook --- pom.xml | 10 ++++---- .../java/com/Acrobot/ChestShop/ChestShop.java | 4 +++- .../ChestShop/Configuration/Properties.java | 9 ++++++- .../Listeners/AuthMeChestShopListener.java | 24 +++++++++++++++---- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 35861b2..06de8fc 100644 --- a/pom.xml +++ b/pom.xml @@ -69,9 +69,9 @@ - org.bukkit - bukkit - 1.10-R0.1-SNAPSHOT + org.spigotmc + spigot-api + 1.10.2-R0.1-SNAPSHOT provided @@ -144,11 +144,10 @@ - com.griefcraft.lwc diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index cc787b3..05147a7 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -43,6 +43,7 @@ import org.bukkit.Server; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.Event; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.mcstats.Metrics; @@ -213,7 +214,8 @@ public class ChestShop extends JavaPlugin { registerEvent(new ItemInfoListener()); registerEvent(new GarbageTextListener()); - if (this.getServer().getPluginManager().getPlugin("AuthMe") != null && this.getServer().getPluginManager().getPlugin("ChestShop").isEnabled()){ + Plugin authMe = getServer().getPluginManager().getPlugin("AuthMe"); + if (authMe != null && authMe.isEnabled()){ registerEvent(new AuthMeChestShopListener()); } diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index fd44ef3..0e71e55 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -127,7 +127,14 @@ public class Properties { @ConfigurationComment("Do you want ChestShop to respect WorldGuard's chest protection?") public static boolean WORLDGUARD_USE_PROTECTION = false; + @PrecededBySpace + @ConfigurationComment("Do you want to deny shop access to unlogged users?") + public static boolean AUTHME_HOOK = true; + + @ConfigurationComment("Do you want to allow shop access to unregistered users? (Example: registration is optional)") + public static boolean AUTHME_ALLOW_UNREGISTERED = false; + @PrecededBySpace @ConfigurationComment("How much Heroes exp should people get for creating a ChestShop?") public static double HEROES_EXP = 100; -} +} \ No newline at end of file diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java index 371e7d4..0bab71c 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/AuthMeChestShopListener.java @@ -1,27 +1,43 @@ package com.Acrobot.ChestShop.Listeners; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import com.Acrobot.ChestShop.Configuration.Properties; +import com.Acrobot.ChestShop.Events.PreTransactionEvent; +import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome; + +import fr.xephi.authme.api.NewAPI; + public class AuthMeChestShopListener implements Listener { - /*NewAPI AuthMeAPI = NewAPI.getInstance(); + NewAPI AuthMeAPI = NewAPI.getInstance(); @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPreTransaction(PreTransactionEvent event) { if (event.getClient() == null) { return; } - Player player = event.getClient(); + if (!Properties.AUTHME_HOOK) { + return; + } + if (AuthMeAPI.isUnrestricted(player)) { return; } + if (!AuthMeAPI.isRegistered(player.getName()) && Properties.AUTHME_ALLOW_UNREGISTERED) { + return; + } + if (AuthMeAPI.isAuthenticated(player)) { return; } event.setCancelled(TransactionOutcome.CLIENT_DOES_NOT_HAVE_PERMISSION); - }*/ -} + } +} \ No newline at end of file