Added AuthMe support

Closes #64
This commit is contained in:
Eric 2017-03-17 14:36:24 +01:00
parent 8efdd8768e
commit 39822fe8df
5 changed files with 45 additions and 0 deletions

10
pom.xml
View File

@ -106,6 +106,10 @@
<id>bstats-repo</id> <id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url> <url>http://repo.bstats.org/content/repositories/releases/</url>
</repository> </repository>
<repository>
<id>xephi-repo</id>
<url>http://ci.xephi.fr/plugin/repository/everything/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -138,6 +142,12 @@
<artifactId>bstats-bukkit</artifactId> <artifactId>bstats-bukkit</artifactId>
<version>1.1</version> <version>1.1</version>
</dependency> </dependency>
<dependency>
<groupId>fr.xephi</groupId>
<artifactId>authme</artifactId>
<version>5.2</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<distributionManagement> <distributionManagement>

View File

@ -17,6 +17,7 @@ import de.epiceric.shopchest.sql.SQLite;
import de.epiceric.shopchest.utils.*; import de.epiceric.shopchest.utils.*;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult; import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import de.epiceric.shopchest.worldguard.ShopFlag; import de.epiceric.shopchest.worldguard.ShopFlag;
import fr.xephi.authme.AuthMe;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bstats.Metrics; import org.bstats.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -46,6 +47,7 @@ public class ShopChest extends JavaPlugin {
private FileWriter fw; private FileWriter fw;
private WorldGuardPlugin worldGuard; private WorldGuardPlugin worldGuard;
private Towny towny; private Towny towny;
private AuthMe authMe;
private ShopUpdater updater; private ShopUpdater updater;
/** /**
@ -154,6 +156,11 @@ public class ShopChest extends JavaPlugin {
towny = (Towny) townyPlugin; towny = (Towny) townyPlugin;
} }
Plugin authMePlugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
if (authMePlugin instanceof AuthMe) {
authMe = (AuthMe) authMePlugin;
}
debug("Loading utils and extras..."); debug("Loading utils and extras...");
LanguageUtils.load(); LanguageUtils.load();
@ -368,6 +375,20 @@ public class ShopChest extends JavaPlugin {
this.updater = updater; this.updater = updater;
} }
/**
* @return Whether the plugin 'AuthMe' is enabled
*/
public boolean hasAuthMe() {
return authMe != null;
}
/**
* @return An instance of {@link AuthMe} or {@code null} if AuthMe is not enabled
*/
public AuthMe getAuthMe() {
return authMe;
}
/** /**
* @return Whether the plugin 'Towny' is enabled * @return Whether the plugin 'Towny' is enabled
*/ */

View File

@ -101,6 +101,9 @@ public class Config {
/** Whether Towny integration should be enabled **/ /** Whether Towny integration should be enabled **/
public boolean enable_towny_integration; public boolean enable_towny_integration;
/** Whether AuthMe integration should be enabled **/
public boolean enable_authme_integration;
/** Whether the vendor of the shop should get messages about buys and sells **/ /** Whether the vendor of the shop should get messages about buys and sells **/
public boolean enable_vendor_messages; public boolean enable_vendor_messages;
@ -338,6 +341,7 @@ public class Config {
enable_debug_log = plugin.getConfig().getBoolean("enable-debug-log"); enable_debug_log = plugin.getConfig().getBoolean("enable-debug-log");
enable_worldguard_integration = plugin.getConfig().getBoolean("enable-worldguard-integration"); enable_worldguard_integration = plugin.getConfig().getBoolean("enable-worldguard-integration");
enable_towny_integration = plugin.getConfig().getBoolean("enable-towny-integration"); enable_towny_integration = plugin.getConfig().getBoolean("enable-towny-integration");
enable_authme_integration = plugin.getConfig().getBoolean("enable-authme-integration");
enable_vendor_messages = plugin.getConfig().getBoolean("enable-vendor-messages"); enable_vendor_messages = plugin.getConfig().getBoolean("enable-vendor-messages");
explosion_protection = plugin.getConfig().getBoolean("explosion-protection"); explosion_protection = plugin.getConfig().getBoolean("explosion-protection");
only_show_shops_in_sight = plugin.getConfig().getBoolean("only-show-shops-in-sight"); only_show_shops_in_sight = plugin.getConfig().getBoolean("only-show-shops-in-sight");

View File

@ -25,6 +25,7 @@ import de.epiceric.shopchest.utils.Permissions;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.Utils; import de.epiceric.shopchest.utils.Utils;
import de.epiceric.shopchest.worldguard.ShopFlag; import de.epiceric.shopchest.worldguard.ShopFlag;
import fr.xephi.authme.AuthMe;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -76,6 +77,8 @@ public class ShopInteractListener implements Listener {
Player p = e.getPlayer(); Player p = e.getPlayer();
Block b = e.getClickedBlock(); Block b = e.getClickedBlock();
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(p)) return;
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
@ -361,6 +364,7 @@ public class ShopInteractListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent e) { public void onPlayerInteract(PlayerInteractEvent e) {
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(e.getPlayer())) return;
handleInteractEvent(e, true); handleInteractEvent(e, true);
} }
@ -370,6 +374,7 @@ public class ShopInteractListener implements Listener {
Entity entity = e.getRightClicked(); Entity entity = e.getRightClicked();
Player p = e.getPlayer(); Player p = e.getPlayer();
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(p)) return;
if (Utils.getMajorVersion() == 8 || e.getHand() == EquipmentSlot.HAND) { if (Utils.getMajorVersion() == 8 || e.getHand() == EquipmentSlot.HAND) {
if (entity instanceof ArmorStand) { if (entity instanceof ArmorStand) {
@ -404,6 +409,7 @@ public class ShopInteractListener implements Listener {
if (!(damager instanceof Player)) return; if (!(damager instanceof Player)) return;
Player p = (Player) damager; Player p = (Player) damager;
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(p)) return;
if (entity instanceof ArmorStand) { if (entity instanceof ArmorStand) {
ArmorStand armorStand = (ArmorStand) entity; ArmorStand armorStand = (ArmorStand) entity;

View File

@ -41,6 +41,10 @@ enable-worldguard-integration: true
# Of course, this only works if Towny is installed # Of course, this only works if Towny is installed
enable-towny-integration: true enable-towny-integration: true
# Set whether AuthMe integration should be enabled
# Of course, this only works if AuthMe is installed
enable-authme-integration: true
# Set whether the vendor of a shop should get messages when players # Set whether the vendor of a shop should get messages when players
# buy or sell something from/to his shop or if his shop is out of stock # buy or sell something from/to his shop or if his shop is out of stock
enable-vendor-messages: true enable-vendor-messages: true