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

View File

@ -17,6 +17,7 @@ import de.epiceric.shopchest.sql.SQLite;
import de.epiceric.shopchest.utils.*;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import de.epiceric.shopchest.worldguard.ShopFlag;
import fr.xephi.authme.AuthMe;
import net.milkbowl.vault.economy.Economy;
import org.bstats.Metrics;
import org.bukkit.Bukkit;
@ -46,6 +47,7 @@ public class ShopChest extends JavaPlugin {
private FileWriter fw;
private WorldGuardPlugin worldGuard;
private Towny towny;
private AuthMe authMe;
private ShopUpdater updater;
/**
@ -154,6 +156,11 @@ public class ShopChest extends JavaPlugin {
towny = (Towny) townyPlugin;
}
Plugin authMePlugin = Bukkit.getServer().getPluginManager().getPlugin("AuthMe");
if (authMePlugin instanceof AuthMe) {
authMe = (AuthMe) authMePlugin;
}
debug("Loading utils and extras...");
LanguageUtils.load();
@ -368,6 +375,20 @@ public class ShopChest extends JavaPlugin {
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
*/

View File

@ -101,6 +101,9 @@ public class Config {
/** Whether Towny integration should be enabled **/
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 **/
public boolean enable_vendor_messages;
@ -338,6 +341,7 @@ public class Config {
enable_debug_log = plugin.getConfig().getBoolean("enable-debug-log");
enable_worldguard_integration = plugin.getConfig().getBoolean("enable-worldguard-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");
explosion_protection = plugin.getConfig().getBoolean("explosion-protection");
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.Utils;
import de.epiceric.shopchest.worldguard.ShopFlag;
import fr.xephi.authme.AuthMe;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
@ -76,6 +77,8 @@ public class ShopInteractListener implements Listener {
Player p = e.getPlayer();
Block b = e.getClickedBlock();
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(p)) return;
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
@ -361,6 +364,7 @@ public class ShopInteractListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(e.getPlayer())) return;
handleInteractEvent(e, true);
}
@ -370,6 +374,7 @@ public class ShopInteractListener implements Listener {
Entity entity = e.getRightClicked();
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 (entity instanceof ArmorStand) {
@ -404,6 +409,7 @@ public class ShopInteractListener implements Listener {
if (!(damager instanceof Player)) return;
Player p = (Player) damager;
if (config.enable_authme_integration && plugin.hasAuthMe() && !AuthMe.getApi().isAuthenticated(p)) return;
if (entity instanceof ArmorStand) {
ArmorStand armorStand = (ArmorStand) entity;

View File

@ -41,6 +41,10 @@ enable-worldguard-integration: true
# Of course, this only works if Towny is installed
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
# buy or sell something from/to his shop or if his shop is out of stock
enable-vendor-messages: true