diff --git a/lib/AreaShop-2.4.0.jar b/lib/AreaShop-2.4.0.jar
new file mode 100644
index 0000000..bba2810
Binary files /dev/null and b/lib/AreaShop-2.4.0.jar differ
diff --git a/pom.xml b/pom.xml
index 8ce518e..af0f9b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -197,6 +197,13 @@
system
${project.basedir}/lib/worldguard-6.1.3-SNAPSHOT.jar
+
+ me.wiefferink
+ areashop
+ 2.4.0
+ system
+ ${project.basedir}/lib/AreaShop-2.4.0.jar
+
diff --git a/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java
index 64235fa..7d4c400 100644
--- a/src/main/java/de/epiceric/shopchest/ShopChest.java
+++ b/src/main/java/de/epiceric/shopchest/ShopChest.java
@@ -21,6 +21,7 @@ import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import de.epiceric.shopchest.external.WorldGuardShopFlag;
import fr.xephi.authme.AuthMe;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
+import me.wiefferink.areashop.AreaShop;
import net.milkbowl.vault.economy.Economy;
import org.bstats.Metrics;
import org.bukkit.Bukkit;
@@ -57,6 +58,7 @@ public class ShopChest extends JavaPlugin {
private ASkyBlock aSkyBlock;
private IslandWorld islandWorld;
private GriefPrevention griefPrevention;
+ private AreaShop areaShop;
private ShopUpdater updater;
/**
@@ -190,6 +192,11 @@ public class ShopChest extends JavaPlugin {
griefPrevention = (GriefPrevention) griefPreventionPlugin;
}
+ Plugin areaShopPlugin = Bukkit.getServer().getPluginManager().getPlugin("AreaShop");
+ if (areaShopPlugin instanceof AreaShop) {
+ areaShop = (AreaShop) areaShopPlugin;
+ }
+
if (hasPlotSquared()) {
new PlotSquaredShopFlag().register(this);
}
@@ -292,12 +299,18 @@ public class ShopChest extends JavaPlugin {
getServer().getPluginManager().registerEvents(new NotifyPlayerOnJoinListener(this), this);
getServer().getPluginManager().registerEvents(new ChestProtectListener(this, worldGuard), this);
- if (!Utils.getServerVersion().equals("v1_8_R1"))
+ if (!Utils.getServerVersion().equals("v1_8_R1")) {
getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this);
+ }
- if (hasWorldGuard())
+ if (hasWorldGuard()) {
getServer().getPluginManager().registerEvents(new WorldGuardListener(this), this);
+ if (hasAreaShop()) {
+ getServer().getPluginManager().registerEvents(new AreaShopListener(this), this);
+ }
+ }
+
initializeShops();
updater = new ShopUpdater(this);
@@ -401,6 +414,20 @@ public class ShopChest extends JavaPlugin {
this.updater = updater;
}
+ /**
+ * @return Whether the plugin 'AreaShop' is enabled
+ */
+ public boolean hasAreaShop() {
+ return areaShop != null && areaShop.isEnabled();
+ }
+
+ /**
+ * @return An instance of {@link AreaShop} or {@code null} if AreaShop is not enabled
+ */
+ public AreaShop getAreaShop() {
+ return areaShop;
+ }
+
/**
* @return Whether the plugin 'GriefPrevention' 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 8cd75b0..b1a156e 100644
--- a/src/main/java/de/epiceric/shopchest/config/Config.java
+++ b/src/main/java/de/epiceric/shopchest/config/Config.java
@@ -42,6 +42,9 @@ public class Config {
/** The types of town plots the king is allowed to create shops in **/
public List towny_shop_plots_king;
+ /** The events of AreaShop when shops in that region should be removed **/
+ public List areashop_remove_shop_events;
+
/** The hostname used in ShopChest's MySQL database **/
public String database_mysql_host;
@@ -128,6 +131,9 @@ public class Config {
/** Whether GriefPrevention integration should be enabled **/
public boolean enable_griefprevention_integration;
+ /** Whether AreaShop integration should be enabled **/
+ public boolean enable_areashop_integration;
+
/** Whether the vendor of the shop should get messages about buys and sells **/
public boolean enable_vendor_messages;
@@ -339,6 +345,7 @@ public class Config {
towny_shop_plots_residents = plugin.getConfig().getStringList("towny-shop-plots.residents");
towny_shop_plots_mayor = plugin.getConfig().getStringList("towny-shop-plots.mayor");
towny_shop_plots_king = plugin.getConfig().getStringList("towny-shop-plots.king");
+ areashop_remove_shop_events = plugin.getConfig().getStringList("areashop-remove-shops");
database_mysql_ping_interval = plugin.getConfig().getInt("database.mysql.ping-interval");
database_mysql_host = plugin.getConfig().getString("database.mysql.hostname");
database_mysql_port = plugin.getConfig().getInt("database.mysql.port");
@@ -366,6 +373,7 @@ public class Config {
enable_askyblock_integration = plugin.getConfig().getBoolean("enable-askyblock-integration");
enable_islandworld_integration = plugin.getConfig().getBoolean("enable-islandworld-integration");
enable_griefprevention_integration = plugin.getConfig().getBoolean("enable-griefprevention-integration");
+ enable_areashop_integration = plugin.getConfig().getBoolean("enable-areashop-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/AreaShopListener.java b/src/main/java/de/epiceric/shopchest/listeners/AreaShopListener.java
new file mode 100644
index 0000000..eaa758e
--- /dev/null
+++ b/src/main/java/de/epiceric/shopchest/listeners/AreaShopListener.java
@@ -0,0 +1,72 @@
+package de.epiceric.shopchest.listeners;
+
+import com.sk89q.worldguard.protection.managers.RegionManager;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
+import de.epiceric.shopchest.ShopChest;
+import de.epiceric.shopchest.config.Config;
+import de.epiceric.shopchest.shop.Shop;
+import me.wiefferink.areashop.events.notify.DeletedRegionEvent;
+import me.wiefferink.areashop.events.notify.ResoldRegionEvent;
+import me.wiefferink.areashop.events.notify.SoldRegionEvent;
+import me.wiefferink.areashop.events.notify.UnrentedRegionEvent;
+import me.wiefferink.areashop.regions.GeneralRegion;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+
+public class AreaShopListener implements Listener {
+
+ private ShopChest plugin;
+ private Config config;
+
+ public AreaShopListener(ShopChest plugin) {
+ this.plugin = plugin;
+ this.config = plugin.getShopChestConfig();
+ }
+
+ @EventHandler
+ public void onRegionDeleted(DeletedRegionEvent e) {
+ if (config.enable_areashop_integration && config.areashop_remove_shop_events.contains("DELETE")) {
+ removeShopsInRegion(e.getRegion());
+ }
+ }
+
+ @EventHandler
+ public void onRegionUnrented(UnrentedRegionEvent e) {
+ if (config.enable_areashop_integration && config.areashop_remove_shop_events.contains("UNRENT")) {
+ removeShopsInRegion(e.getRegion());
+ }
+ }
+
+ @EventHandler
+ public void onRegionResold(ResoldRegionEvent e) {
+ if (config.enable_areashop_integration && config.areashop_remove_shop_events.contains("RESELL")) {
+ removeShopsInRegion(e.getRegion());
+ }
+ }
+
+ @EventHandler
+ public void onRegionSold(SoldRegionEvent e) {
+ if (config.enable_areashop_integration && config.areashop_remove_shop_events.contains("SELL")) {
+ removeShopsInRegion(e.getRegion());
+ }
+ }
+
+ private void removeShopsInRegion(GeneralRegion generalRegion) {
+ if (!plugin.hasWorldGuard()) return;
+
+ RegionManager regionManager = plugin.getWorldGuard().getRegionManager(generalRegion.getWorld());
+
+ for (Shop shop : plugin.getShopUtils().getShops()) {
+ if (!shop.getLocation().getWorld().getName().equals(generalRegion.getWorldName())) continue;
+
+ for (ProtectedRegion r : regionManager.getApplicableRegions(shop.getLocation())) {
+ if (generalRegion.getName().equals(r.getId())) {
+ plugin.getShopUtils().removeShop(shop, true);
+ break;
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 7e2c8c2..3253703 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -65,6 +65,10 @@ enable-islandworld-integration: true
# Of course, this only works if GriefPrevention is installed
enable-griefprevention-integration: true
+# Set whether AreaShop integration should be enabled
+# Of course, this only works if AreaShop and WorldGuard is installed
+enable-areashop-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
@@ -197,6 +201,15 @@ blacklist:
# - "STONE:1"
# - "DIAMOND_BLOCK"
+# Set the events of AreaShop when shops on that region should be removed.
+# Important: You must have exactly 2 leading spaces in each line
+# Valid values are: DELETE, UNRENT, RESELL, SELL
+areashop-remove-shops:
+ - "DELETE"
+ - "UNRENT"
+ - "RESELL"
+ - "SELL"
+
# Set whether the custom WorldGuard flags should be allowed by default
# (true = Allowed by default, false = Denied by default)
# This can, of course, be overridden in specific regions and is only
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index e5b131b..aa680dc 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, ASkyBlock, IslandWorld]
+softdepend: [WorldGuard, Towny, AuthMe, PlotSquared, uSkyBlock, ASkyBlock, IslandWorld, AreaShop]
depend: [Vault]
permissions: