From 7c1cb7f665d8a6312fcded67cb6a441f7e8becb7 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 17 Apr 2017 17:07:47 +0200 Subject: [PATCH] Added support for ASkyBlock Only members and the owner of an island are allowed to create a shop, but everyone is allowed to use it (if not restricted by other plugins like WorldGuard) Closes #50 --- pom.xml | 11 ++++++++++ .../java/de/epiceric/shopchest/ShopChest.java | 21 +++++++++++++++++++ .../de/epiceric/shopchest/config/Config.java | 4 ++++ .../listeners/ChestProtectListener.java | 7 +++++++ .../listeners/ShopInteractListener.java | 11 ++++++++++ src/main/resources/config.yml | 4 ++++ src/main/resources/plugin.yml | 2 +- 7 files changed, 59 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ea95358..6202eff 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,10 @@ uskyblock-repo https://raw.github.com/rlf/uSkyBlock/mvn-repo/ + + tastybento-repo + http://dl.bintray.com/tastybento/maven-repo + @@ -170,6 +174,13 @@ com.github.rlf uSkyBlock-API 2.6.4 + provided + + + com.wasteofplastic + askyblock + 3.0.6.2 + provided diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java index 54c9e6f..5342f70 100644 --- a/src/main/java/de/epiceric/shopchest/ShopChest.java +++ b/src/main/java/de/epiceric/shopchest/ShopChest.java @@ -2,6 +2,7 @@ package de.epiceric.shopchest; import com.palmergames.bukkit.towny.Towny; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.wasteofplastic.askyblock.ASkyBlock; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Regex; import de.epiceric.shopchest.event.ShopReloadEvent; @@ -51,6 +52,7 @@ public class ShopChest extends JavaPlugin { private Towny towny; private AuthMe authMe; private uSkyBlockAPI uSkyBlock; + private ASkyBlock aSkyBlock; private ShopUpdater updater; /** @@ -169,6 +171,11 @@ public class ShopChest extends JavaPlugin { uSkyBlock = (uSkyBlockAPI) uSkyBlockPlugin; } + Plugin aSkyBlockPlugin = Bukkit.getServer().getPluginManager().getPlugin("ASkyBlock"); + if (aSkyBlockPlugin instanceof ASkyBlock) { + aSkyBlock = (ASkyBlock) aSkyBlockPlugin; + } + if (hasPlotSquared()) { new PlotSquaredShopFlag().register(this); } @@ -394,6 +401,20 @@ public class ShopChest extends JavaPlugin { this.updater = updater; } + /** + * @return Whether the plugin 'ASkyBlock' is enabled + */ + public boolean hasASkyBlock() { + return aSkyBlock != null && aSkyBlock.isEnabled(); + } + + /** + * @return An instance of {@link ASkyBlock} or {@code null} if ASkyBlock is not enabled + */ + public ASkyBlock getASkyBlock() { + return aSkyBlock; + } + /** * @return Whether the plugin 'uSkyBlock' is enabled */ diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index 0b31f0d..c27d628 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -119,6 +119,9 @@ public class Config { /** Whether uSkyBlock integration should be enabled **/ public boolean enable_uskyblock_integration; + /** Whether ASkyBlock integration should be enabled **/ + public boolean enable_askyblock_integration; + /** Whether the vendor of the shop should get messages about buys and sells **/ public boolean enable_vendor_messages; @@ -362,6 +365,7 @@ public class Config { enable_authme_integration = plugin.getConfig().getBoolean("enable-authme-integration"); enable_plotsquared_integration = plugin.getConfig().getBoolean("enable-plotsquared-integration"); enable_uskyblock_integration = plugin.getConfig().getBoolean("enable-uskyblock-integration"); + enable_askyblock_integration = plugin.getConfig().getBoolean("enable-askyblock-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"); diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index c9044a8..c74a6b4 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -7,6 +7,8 @@ import com.palmergames.bukkit.towny.object.TownyUniverse; import com.sk89q.worldguard.bukkit.RegionContainer; import com.sk89q.worldguard.bukkit.RegionQuery; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.wasteofplastic.askyblock.ASkyBlockAPI; +import com.wasteofplastic.askyblock.Island; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.external.PlotSquaredShopFlag; @@ -192,6 +194,11 @@ public class ChestProtectListener implements Listener { externalPluginsAllowed &= islandInfo.getMembers().contains(p.getName()) || islandInfo.getLeader().equals(p.getName()); } + if (plugin.hasASkyBlock() && config.enable_askyblock_integration) { + Island island = ASkyBlockAPI.getInstance().getIslandAt(b.getLocation()); + externalPluginsAllowed &= island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId()); + } + if (externalPluginsAllowed || p.hasPermission(Permissions.EXTEND_PROTECTED)) { if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.EXTEND_OTHER)) { diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index f336e5a..3ce7c0f 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -10,6 +10,8 @@ import com.sk89q.worldguard.bukkit.RegionContainer; import com.sk89q.worldguard.bukkit.RegionQuery; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.flags.StateFlag; +import com.wasteofplastic.askyblock.ASkyBlockAPI; +import com.wasteofplastic.askyblock.Island; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Regex; @@ -170,6 +172,15 @@ public class ShopInteractListener implements Listener { } } + if (plugin.hasASkyBlock() && config.enable_askyblock_integration) { + for (Location loc : chestLocations) { + if (loc != null) { + Island island = ASkyBlockAPI.getInstance().getIslandAt(loc); + externalPluginsAllowed &= island.getMembers().contains(p.getUniqueId()) || island.getOwner().equals(p.getUniqueId()); + } + } + } + if ((e.isCancelled() || !externalPluginsAllowed) && !p.hasPermission(Permissions.CREATE_PROTECTED)) { p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); ClickType.removePlayerClickType(p); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index edaba98..c900c34 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -53,6 +53,10 @@ enable-plotsquared-integration: true # Of course, this only works if uSkyBlock is installed enable-uskyblock-integration: true +# Set whether ASkyBlock integration should be enabled +# Of course, this only works if ASkyBlock is installed +enable-askyblock-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 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a9acfaf..fd161d4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ main: de.epiceric.shopchest.ShopChest version: ${project.version} author: EpicEric website: ${project.url} -softdepend: [WorldGuard, Towny, AuthMe, PlotSquared, uSkyBlock] +softdepend: [WorldGuard, Towny, AuthMe, PlotSquared, uSkyBlock, ASkyBlock] depend: [Vault] permissions: