Added way to disable WorldGuard/Towny integration

+ Added permission to use shops in WorldGuard regions that deny shop use
This commit is contained in:
Eric 2016-11-23 16:05:33 +01:00
parent 1251d187ed
commit d097a15122
7 changed files with 49 additions and 26 deletions

View File

@ -74,6 +74,12 @@ public class Config {
/** Whether the debug log file should be created **/
public boolean enable_debug_log;
/** Whether WorldGuard integration should be enabled **/
public boolean enable_worldguard_integration;
/** Whether Towny integration should be enabled **/
public boolean enable_towny_integration;
/** Whether admin shops should be excluded of the shop limits **/
public boolean exclude_admin_shops;
@ -282,6 +288,8 @@ public class Config {
two_line_prices = plugin.getConfig().getBoolean("two-line-prices");
enable_hologram_interaction = plugin.getConfig().getBoolean("enable-hologram-interaction");
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");
explosion_protection = plugin.getConfig().getBoolean("explosion-protection");
exclude_admin_shops = plugin.getConfig().getBoolean("shop-limits.exclude-admin-shops");
append_potion_level_to_item_name = plugin.getConfig().getBoolean("append-potion-level-to-item-name");

View File

@ -135,13 +135,13 @@ public class ChestProtectListener implements Listener {
boolean externalPluginsAllowed = true;
if (plugin.hasWorldGuard()) {
if (plugin.hasWorldGuard() && plugin.getShopChestConfig().enable_worldguard_integration) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
externalPluginsAllowed = query.testState(b.getLocation(), p, ShopFlag.CREATE_SHOP);
}
if (plugin.hasTowny()) {
if (plugin.hasTowny() && plugin.getShopChestConfig().enable_towny_integration) {
TownBlock townBlock = TownyUniverse.getTownBlock(b.getLocation());
externalPluginsAllowed &= (townBlock != null && townBlock.getType() == TownBlockType.COMMERCIAL);
}

View File

@ -94,7 +94,7 @@ public class ShopInteractListener implements Listener {
chestLocations[1] = ((Chest) dc.getRightSide()).getLocation();
}
if (plugin.hasWorldGuard()) {
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
@ -105,7 +105,7 @@ public class ShopInteractListener implements Listener {
}
}
if (plugin.hasTowny()) {
if (plugin.hasTowny() && config.enable_towny_integration) {
for (Location loc : chestLocations) {
if (loc != null) {
TownBlock townBlock = TownyUniverse.getTownBlock(loc);
@ -237,26 +237,26 @@ public class ShopInteractListener implements Listener {
boolean worldGuardAllowed = true;
if (shop.getShopType() == ShopType.ADMIN) {
if (plugin.hasWorldGuard()) {
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
worldGuardAllowed = query.testState(b.getLocation(), p, ShopFlag.USE_ADMIN_SHOP);
}
if (worldGuardAllowed) {
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
buy(p, shop);
} else {
plugin.debug(p.getName() + " doesn't have worldguard permission");
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY));
}
} else {
if (plugin.hasWorldGuard()) {
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
worldGuardAllowed = query.testState(b.getLocation(), p, ShopFlag.USE_SHOP);
}
if (worldGuardAllowed) {
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
Chest c = (Chest) b.getState();
if (Utils.getAmount(c.getInventory(), shop.getProduct()) >= shop.getProduct().getAmount()) {
buy(p, shop);
@ -307,7 +307,7 @@ public class ShopInteractListener implements Listener {
if (p.hasPermission(Permissions.SELL)) {
boolean worldGuardAllowed = true;
if (plugin.hasWorldGuard()) {
if (plugin.hasWorldGuard() && config.enable_worldguard_integration) {
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
@ -315,7 +315,7 @@ public class ShopInteractListener implements Listener {
worldGuardAllowed = query.testState(b.getLocation(), p, flag);
}
if (worldGuardAllowed) {
if (worldGuardAllowed || p.hasPermission(Permissions.WORLDGUARD_BYPASS)) {
if (Utils.getAmount(p.getInventory(), shop.getProduct()) >= shop.getProduct().getAmount()) {
sell(p, shop);
} else {

View File

@ -84,6 +84,7 @@ public class WorldGuardListener implements Listener {
@EventHandler(priority = EventPriority.LOW)
public void onUseBlock(UseBlockEvent event) {
if (plugin.getShopChestConfig().enable_worldguard_integration) {
if (event.getCause().getFirstPlayer() == null) return;
if (event.getOriginalEvent() instanceof PlayerInteractEvent) {
@ -109,5 +110,6 @@ public class WorldGuardListener implements Listener {
}
}
}
}
}

View File

@ -16,5 +16,6 @@ public class Permissions {
public static final String CONFIG = "shopchest.config";
public static final String EXTEND_OTHER = "shopchest.extend.other";
public static final String EXTEND_PROTECTED = "shopchest.extend.protected";
public static final String WORLDGUARD_BYPASS = "shopchest.worldguard.bypass";
}

View File

@ -24,6 +24,14 @@ enable-hologram-interaction: true
# The file may get large! Please enable this setting when reporting bugs.
enable-debug-log: false
# Set whether WorldGuard integration should be enabled
# Of course, this only worls if WorldGuard is installed
enable-worldguard-integration: true
# Set whether Towny integration should be enabled
# Of course, this only worls if Towny is installed
enable-towny-integration: true
# Set whether the buy- and sell price should be arranged below each other.
# The first line will be the buy price with the message "message.hologram.only-buy",
# the second line will be the sell price with the message "message.hologram.only-sell".

View File

@ -25,6 +25,7 @@ permissions:
shopchest.config: true
shopchest.extend.other: true
shopchest.extend.protected: true
shopchest.worldguard.bypass: true
shopchest.create:
description: Allows you to create a shop.
default: true
@ -70,3 +71,6 @@ permissions:
shopchest.extend.protected:
description: Allows you to extend shops into a protected region.
default: op
shopchest.worlguard.bypass:
description: Allows you to to use shops in WorldGuard regions that deny shop use.
default: op