diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 722da28c8..d5ba7b56a 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -27,6 +27,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; @@ -105,6 +106,10 @@ public class QuickShop extends JavaPlugin { public boolean priceChangeRequiresFee = false; /** Whether or not to limit players shop amounts */ public boolean limit = false; + + /** The plugin OpenInv (null if not present) */ + public Plugin openInvPlugin; + private HashMap limits = new HashMap(); /** Use SpoutPlugin to get item / block names */ public boolean useSpout = false; @@ -439,6 +444,9 @@ public class QuickShop extends JavaPlugin { }.runTaskTimer(this, 1L, displayItemCheckTicks); } + // added for compatibility reasons with OpenInv - see https://github.com/KaiKikuchi/QuickShop/issues/139 + this.openInvPlugin = Bukkit.getPluginManager().getPlugin("OpenInv"); + getLogger().info("QuickShop loaded!"); } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index f1b9c9e00..48b340a49 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -20,6 +20,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Sign; +import org.bukkit.plugin.RegisteredListener; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Database.Database; import org.maxgamer.quickshop.Util.MsgUtil; @@ -224,31 +225,48 @@ public class ShopManager { * @return True if they're allowed to place a shop there. */ public boolean canBuildShop(Player p, Block b, BlockFace bf) { - if (plugin.limit) { - int owned = 0; - Iterator it = getShopIterator(); - while (it.hasNext()) { - if (it.next().getOwner().equals(p.getUniqueId())) { - owned++; + RegisteredListener openInvRegisteredListener = null; // added for compatibility reasons with OpenInv - see https://github.com/KaiKikuchi/QuickShop/issues/139 + try { + if (plugin.openInvPlugin != null) { + for (RegisteredListener listener : PlayerInteractEvent.getHandlerList().getRegisteredListeners()) { + if (listener.getPlugin() == plugin.openInvPlugin) { + openInvRegisteredListener = listener; + PlayerInteractEvent.getHandlerList().unregister(listener); + break; + } } } - int max = plugin.getShopLimit(p); - if (owned + 1 > max) { - p.sendMessage(ChatColor.RED + "You have already created a maximum of " + owned + "/" + max + " shops!"); + + if (plugin.limit) { + int owned = 0; + Iterator it = getShopIterator(); + while (it.hasNext()) { + if (it.next().getOwner().equals(p.getUniqueId())) { + owned++; + } + } + int max = plugin.getShopLimit(p); + if (owned + 1 > max) { + p.sendMessage(ChatColor.RED + "You have already created a maximum of " + owned + "/" + max + " shops!"); + return false; + } + } + PlayerInteractEvent pie = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, AIR, b, bf); // PIE = PlayerInteractEvent - What else? + Bukkit.getPluginManager().callEvent(pie); + pie.getPlayer().closeInventory(); // If the player has chat open, this + // will close their chat. + if (pie.isCancelled()) { return false; } - } - PlayerInteractEvent pie = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, AIR, b, bf); // PIE = PlayerInteractEvent - What else? - Bukkit.getPluginManager().callEvent(pie); - pie.getPlayer().closeInventory(); // If the player has chat open, this - // will close their chat. - if (pie.isCancelled()) { - return false; - } - ShopPreCreateEvent spce = new ShopPreCreateEvent(p, b.getLocation()); - Bukkit.getPluginManager().callEvent(spce); - if (spce.isCancelled()) { - return false; + ShopPreCreateEvent spce = new ShopPreCreateEvent(p, b.getLocation()); + Bukkit.getPluginManager().callEvent(spce); + if (spce.isCancelled()) { + return false; + } + } finally { + if (plugin.openInvPlugin != null && openInvRegisteredListener != null) { + PlayerInteractEvent.getHandlerList().register(openInvRegisteredListener); + } } return true; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e92189610..972adcbe8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ version: ${version} authors: [Netherfoam, Timtower, KaiNoMood] description: Economy Shops plugin -softdepend: [Herochat, Vault, Essentials] +softdepend: [Herochat, Vault, Essentials, OpenInv] commands: qs: