Use WorldGuardWrapper to support v7 and v6

https://github.com/CodeMC/WorldGuardWrapper
This commit is contained in:
Eric 2018-08-03 18:24:09 +02:00
parent 11c6af099b
commit f40b0b7418
8 changed files with 50 additions and 101 deletions

Binary file not shown.

12
pom.xml
View File

@ -113,6 +113,11 @@
<version>16.6</version> <version>16.6</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.palmergames</groupId> <groupId>com.palmergames</groupId>
<artifactId>Towny</artifactId> <artifactId>Towny</artifactId>
@ -127,13 +132,6 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/IslandWorld-7.0.jar</systemPath> <systemPath>${project.basedir}/lib/IslandWorld-7.0.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.1.3-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/worldguard-6.1.3-SNAPSHOT.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>me.wiefferink</groupId> <groupId>me.wiefferink</groupId>
<artifactId>areashop</artifactId> <artifactId>areashop</artifactId>

View File

@ -1,7 +1,6 @@
package de.epiceric.shopchest; package de.epiceric.shopchest;
import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.Towny;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.wasteofplastic.askyblock.ASkyBlock; import com.wasteofplastic.askyblock.ASkyBlock;
import de.epiceric.shopchest.command.ShopCommand; import de.epiceric.shopchest.command.ShopCommand;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
@ -44,6 +43,8 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.codemc.worldguardwrapper.WorldGuardWrapper;
import pl.islandworld.IslandWorld; import pl.islandworld.IslandWorld;
import us.talabrek.ultimateskyblock.api.uSkyBlockAPI; import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
@ -73,7 +74,7 @@ public class ShopChest extends JavaPlugin {
private String downloadLink = ""; private String downloadLink = "";
private ShopUtils shopUtils; private ShopUtils shopUtils;
private FileWriter fw; private FileWriter fw;
private WorldGuardPlugin worldGuard; private Plugin worldGuard;
private Towny towny; private Towny towny;
private AuthMe authMe; private AuthMe authMe;
private uSkyBlockAPI uSkyBlock; private uSkyBlockAPI uSkyBlock;
@ -129,9 +130,8 @@ public class ShopChest extends JavaPlugin {
debug("Loading ShopChest version " + getDescription().getVersion()); debug("Loading ShopChest version " + getDescription().getVersion());
Plugin worldGuardPlugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"); worldGuard = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
if (worldGuardPlugin instanceof WorldGuardPlugin) { if (worldGuard != null) {
worldGuard = (WorldGuardPlugin) worldGuardPlugin;
WorldGuardShopFlag.register(this); WorldGuardShopFlag.register(this);
} }
} }
@ -273,6 +273,10 @@ public class ShopChest extends JavaPlugin {
areaShop = (AreaShop) areaShopPlugin; areaShop = (AreaShop) areaShopPlugin;
} }
if (hasWorldGuard()) {
WorldGuardWrapper.getInstance().registerEvents(this);
}
if (hasPlotSquared()) { if (hasPlotSquared()) {
new PlotSquaredShopFlag().register(this); new PlotSquaredShopFlag().register(this);
} }
@ -369,7 +373,7 @@ public class ShopChest extends JavaPlugin {
getServer().getPluginManager().registerEvents(new ShopItemListener(this), this); getServer().getPluginManager().registerEvents(new ShopItemListener(this), this);
getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this); getServer().getPluginManager().registerEvents(new ShopInteractListener(this), this);
getServer().getPluginManager().registerEvents(new NotifyPlayerOnJoinListener(this), this); getServer().getPluginManager().registerEvents(new NotifyPlayerOnJoinListener(this), this);
getServer().getPluginManager().registerEvents(new ChestProtectListener(this, worldGuard), this); getServer().getPluginManager().registerEvents(new ChestProtectListener(this), this);
if (!Utils.getServerVersion().equals("v1_8_R1")) { if (!Utils.getServerVersion().equals("v1_8_R1")) {
getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this); getServer().getPluginManager().registerEvents(new BlockExplodeListener(this), this);
@ -527,13 +531,6 @@ public class ShopChest extends JavaPlugin {
return worldGuard != null && worldGuard.isEnabled(); return worldGuard != null && worldGuard.isEnabled();
} }
/**
* @return An instance of {@link WorldGuardPlugin} or {@code null} if WorldGuard is not enabled
*/
public WorldGuardPlugin getWorldGuard() {
return worldGuard;
}
/** /**
* @return ShopChest's {@link ShopUtils} containing some important methods * @return ShopChest's {@link ShopUtils} containing some important methods
*/ */

View File

@ -1,29 +1,18 @@
package de.epiceric.shopchest.external; package de.epiceric.shopchest.external;
import com.google.common.collect.Lists; import org.codemc.worldguardwrapper.WorldGuardWrapper;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
public class WorldGuardShopFlag { public class WorldGuardShopFlag {
private static Flag<?>[] customFlagList;
public static final StateFlag CREATE_SHOP;
public static final StateFlag USE_SHOP;
public static final StateFlag USE_ADMIN_SHOP;
static {
CREATE_SHOP = new StateFlag("create-shop", Config.wgAllowCreateShopDefault);
USE_SHOP = new StateFlag("use-shop", Config.wgAllowUseShopDefault);
USE_ADMIN_SHOP = new StateFlag("use-admin-shop", Config.wgAllowUseAdminShopDefault);
customFlagList = new Flag[] {CREATE_SHOP, USE_SHOP, USE_ADMIN_SHOP};
}
public static void register(final ShopChest plugin) { public static void register(final ShopChest plugin) {
plugin.getWorldGuard().getFlagRegistry().registerAll(Lists.newArrayList(customFlagList)); WorldGuardWrapper wrapper = WorldGuardWrapper.getInstance();
plugin.debug("Flag create-shop: " + wrapper.registerStateFlag("create-shop", Config.wgAllowCreateShopDefault));
plugin.debug("Flag use-shop: " + wrapper.registerStateFlag("use-shop", Config.wgAllowUseShopDefault));
plugin.debug("Flag use-admin-shop: " + wrapper.registerStateFlag("use-admin-shop", Config.wgAllowUseAdminShopDefault));
} }
} }

View File

@ -1,7 +1,5 @@
package de.epiceric.shopchest.listeners; 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.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
@ -12,6 +10,8 @@ import me.wiefferink.areashop.events.notify.UnrentedRegionEvent;
import me.wiefferink.areashop.regions.GeneralRegion; import me.wiefferink.areashop.regions.GeneralRegion;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.codemc.worldguardwrapper.WorldGuardWrapper;
import org.codemc.worldguardwrapper.implementation.AbstractRegion;
public class AreaShopListener implements Listener { public class AreaShopListener implements Listener {
@ -52,12 +52,10 @@ public class AreaShopListener implements Listener {
private void removeShopsInRegion(GeneralRegion generalRegion) { private void removeShopsInRegion(GeneralRegion generalRegion) {
if (!plugin.hasWorldGuard()) return; if (!plugin.hasWorldGuard()) return;
RegionManager regionManager = plugin.getWorldGuard().getRegionManager(generalRegion.getWorld());
for (Shop shop : plugin.getShopUtils().getShops()) { for (Shop shop : plugin.getShopUtils().getShops()) {
if (!shop.getLocation().getWorld().getName().equals(generalRegion.getWorldName())) continue; if (!shop.getLocation().getWorld().getName().equals(generalRegion.getWorldName())) continue;
for (ProtectedRegion r : regionManager.getApplicableRegions(shop.getLocation())) { for (AbstractRegion r : WorldGuardWrapper.getInstance().getRegions(shop.getLocation())) {
if (generalRegion.getLowerCaseName().equals(r.getId())) { if (generalRegion.getLowerCaseName().equals(r.getId())) {
plugin.getShopUtils().removeShop(shop, true); plugin.getShopUtils().removeShop(shop, true);
break; break;

View File

@ -4,15 +4,11 @@ import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyUniverse; 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.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island; import com.wasteofplastic.askyblock.Island;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.external.WorldGuardShopFlag;
import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.Message; import de.epiceric.shopchest.language.Message;
import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.nms.Hologram;
@ -41,6 +37,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.codemc.worldguardwrapper.WorldGuardWrapper;
import pl.islandworld.api.IslandWorldApi; import pl.islandworld.api.IslandWorldApi;
import us.talabrek.ultimateskyblock.api.IslandInfo; import us.talabrek.ultimateskyblock.api.IslandInfo;
@ -51,12 +48,10 @@ public class ChestProtectListener implements Listener {
private ShopChest plugin; private ShopChest plugin;
private ShopUtils shopUtils; private ShopUtils shopUtils;
private WorldGuardPlugin worldGuard;
public ChestProtectListener(ShopChest plugin, WorldGuardPlugin worldGuard) { public ChestProtectListener(ShopChest plugin) {
this.plugin = plugin; this.plugin = plugin;
this.shopUtils = plugin.getShopUtils(); this.shopUtils = plugin.getShopUtils();
this.worldGuard = worldGuard;
} }
private void remove(final Shop shop, final Block b, final Player p) { private void remove(final Shop shop, final Block b, final Player p) {
@ -191,9 +186,7 @@ public class ChestProtectListener implements Listener {
boolean externalPluginsAllowed = true; boolean externalPluginsAllowed = true;
if (plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { if (plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
RegionContainer container = worldGuard.getRegionContainer(); externalPluginsAllowed = WorldGuardWrapper.getInstance().queryStateFlag(p, b.getLocation(), "create-shop").orElse(false);
RegionQuery query = container.createQuery();
externalPluginsAllowed = query.testState(b.getLocation(), p, WorldGuardShopFlag.CREATE_SHOP);
} }
if (externalPluginsAllowed && plugin.hasTowny() && Config.enableTownyIntegration) { if (externalPluginsAllowed && plugin.hasTowny() && Config.enableTownyIntegration) {

View File

@ -7,10 +7,6 @@ import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.TownyUniverse; 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.sk89q.worldguard.protection.flags.StateFlag;
import com.wasteofplastic.askyblock.ASkyBlockAPI; import com.wasteofplastic.askyblock.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island; import com.wasteofplastic.askyblock.Island;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
@ -22,7 +18,6 @@ import de.epiceric.shopchest.event.ShopInfoEvent;
import de.epiceric.shopchest.event.ShopOpenEvent; import de.epiceric.shopchest.event.ShopOpenEvent;
import de.epiceric.shopchest.event.ShopRemoveEvent; import de.epiceric.shopchest.event.ShopRemoveEvent;
import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.external.WorldGuardShopFlag;
import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.Message; import de.epiceric.shopchest.language.Message;
import de.epiceric.shopchest.language.Replacement; import de.epiceric.shopchest.language.Replacement;
@ -66,6 +61,8 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.codemc.worldguardwrapper.WorldGuardWrapper;
import pl.islandworld.api.IslandWorldApi; import pl.islandworld.api.IslandWorldApi;
import us.talabrek.ultimateskyblock.api.IslandInfo; import us.talabrek.ultimateskyblock.api.IslandInfo;
@ -86,14 +83,12 @@ public class ShopInteractListener implements Listener {
private Economy econ; private Economy econ;
private Database database; private Database database;
private ShopUtils shopUtils; private ShopUtils shopUtils;
private WorldGuardPlugin worldGuard;
public ShopInteractListener(ShopChest plugin) { public ShopInteractListener(ShopChest plugin) {
this.plugin = plugin; this.plugin = plugin;
this.econ = plugin.getEconomy(); this.econ = plugin.getEconomy();
this.database = plugin.getShopDatabase(); this.database = plugin.getShopDatabase();
this.shopUtils = plugin.getShopUtils(); this.shopUtils = plugin.getShopUtils();
this.worldGuard = plugin.getWorldGuard();
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -163,12 +158,10 @@ public class ShopInteractListener implements Listener {
if (plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { if (plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
plugin.debug("Checking if WorldGuard allows shop creation..."); plugin.debug("Checking if WorldGuard allows shop creation...");
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
for (Location loc : chestLocations) { for (Location loc : chestLocations) {
if (loc != null) { if (loc != null) {
externalPluginsAllowed &= query.testState(loc, p, WorldGuardShopFlag.CREATE_SHOP); externalPluginsAllowed &= WorldGuardWrapper.getInstance().queryStateFlag(p, loc, "create-shop").orElse(false);
} }
} }
@ -463,10 +456,8 @@ public class ShopInteractListener implements Listener {
} }
if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
StateFlag flag = (shop.getShopType() == ShopType.ADMIN ? WorldGuardShopFlag.USE_ADMIN_SHOP : WorldGuardShopFlag.USE_SHOP); String flagName = (shop.getShopType() == ShopType.ADMIN ? "use-admin-shop" : "use-shop");
RegionContainer container = worldGuard.getRegionContainer(); externalPluginsAllowed = WorldGuardWrapper.getInstance().queryStateFlag(p, b.getLocation(), flagName).orElse(false);
RegionQuery query = container.createQuery();
externalPluginsAllowed = query.testState(b.getLocation(), p, flag);
} }
if (shop.getShopType() == ShopType.ADMIN) { if (shop.getShopType() == ShopType.ADMIN) {
@ -574,11 +565,8 @@ public class ShopInteractListener implements Listener {
} }
if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) { if (externalPluginsAllowed && plugin.hasWorldGuard() && Config.enableWorldGuardIntegration) {
RegionContainer container = worldGuard.getRegionContainer(); String flagName = (shop.getShopType() == ShopType.ADMIN ? "use-admin-shop" : "use-shop");
RegionQuery query = container.createQuery(); externalPluginsAllowed = WorldGuardWrapper.getInstance().queryStateFlag(p, b.getLocation(), flagName).orElse(false);
StateFlag flag = (shop.getShopType() == ShopType.ADMIN ? WorldGuardShopFlag.USE_ADMIN_SHOP : WorldGuardShopFlag.USE_SHOP);
externalPluginsAllowed = query.testState(b.getLocation(), p, flag);
} }
if (externalPluginsAllowed || p.hasPermission(Permissions.BYPASS_EXTERNAL_PLUGIN)) { if (externalPluginsAllowed || p.hasPermission(Permissions.BYPASS_EXTERNAL_PLUGIN)) {

View File

@ -1,20 +1,10 @@
package de.epiceric.shopchest.listeners; package de.epiceric.shopchest.listeners;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.RegionQuery;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
import com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent;
import com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent;
import com.sk89q.worldguard.protection.flags.StateFlag;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.nms.Hologram;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.utils.ClickType; import de.epiceric.shopchest.utils.ClickType;
import de.epiceric.shopchest.utils.Permissions;
import de.epiceric.shopchest.external.WorldGuardShopFlag;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
@ -25,27 +15,27 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.codemc.worldguardwrapper.WorldGuardWrapper;
import org.codemc.worldguardwrapper.event.DamageEntityEvent;
import org.codemc.worldguardwrapper.event.UseBlockEvent;
import org.codemc.worldguardwrapper.event.UseEntityEvent;
public class WorldGuardListener implements Listener { public class WorldGuardListener implements Listener {
private ShopChest plugin; private ShopChest plugin;
private WorldGuardPlugin worldGuard;
public WorldGuardListener(ShopChest plugin) { public WorldGuardListener(ShopChest plugin) {
this.plugin = plugin; this.plugin = plugin;
this.worldGuard = plugin.getWorldGuard();
} }
private boolean isAllowed(Player player, Location location, Action action) { private boolean isAllowed(Player player, Location location, Action action) {
LocalPlayer localPlayer = worldGuard.wrapPlayer(player);
RegionContainer container = worldGuard.getRegionContainer();
RegionQuery query = container.createQuery();
Shop shop = plugin.getShopUtils().getShop(location); Shop shop = plugin.getShopUtils().getShop(location);
if (action == Action.RIGHT_CLICK_BLOCK && shop != null) { if (action == Action.RIGHT_CLICK_BLOCK && shop != null) {
@ -57,7 +47,7 @@ public class WorldGuardListener implements Listener {
if (ClickType.getPlayerClickType(player) != null) { if (ClickType.getPlayerClickType(player) != null) {
switch (ClickType.getPlayerClickType(player).getClickType()) { switch (ClickType.getPlayerClickType(player).getClickType()) {
case CREATE: case CREATE:
return query.testState(location, localPlayer, WorldGuardShopFlag.CREATE_SHOP); return WorldGuardWrapper.getInstance().queryStateFlag(player, location, "create-shop").orElse(false);
case REMOVE: case REMOVE:
case INFO: case INFO:
case OPEN: case OPEN:
@ -65,9 +55,8 @@ public class WorldGuardListener implements Listener {
} }
} else { } else {
if (shop != null) { if (shop != null) {
StateFlag flag = (shop.getShopType() == Shop.ShopType.NORMAL ? WorldGuardShopFlag.USE_SHOP : WorldGuardShopFlag.USE_ADMIN_SHOP); String flagName = (shop.getShopType() == Shop.ShopType.NORMAL ? "use-shop" : "use-admin-shop");
return WorldGuardWrapper.getInstance().queryStateFlag(player, location, flagName).orElse(false);
return query.testState(location, localPlayer, flag);
} }
} }
@ -77,8 +66,7 @@ public class WorldGuardListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onUseEntity(UseEntityEvent event) { public void onUseEntity(UseEntityEvent event) {
if (Config.enableWorldGuardIntegration) { if (Config.enableWorldGuardIntegration) {
Player player = event.getCause().getFirstPlayer(); Player player = event.getPlayer();
if (player == null) return;
if (event.getOriginalEvent() instanceof PlayerInteractAtEntityEvent) { if (event.getOriginalEvent() instanceof PlayerInteractAtEntityEvent) {
PlayerInteractAtEntityEvent orig = (PlayerInteractAtEntityEvent) event.getOriginalEvent(); PlayerInteractAtEntityEvent orig = (PlayerInteractAtEntityEvent) event.getOriginalEvent();
@ -91,7 +79,7 @@ public class WorldGuardListener implements Listener {
for (Shop shop : plugin.getShopUtils().getShops()) { for (Shop shop : plugin.getShopUtils().getShops()) {
if (shop.getHologram() != null && shop.getHologram().contains((ArmorStand) e)) { if (shop.getHologram() != null && shop.getHologram().contains((ArmorStand) e)) {
if (isAllowed(player, shop.getLocation(), Action.RIGHT_CLICK_BLOCK)) { if (isAllowed(player, shop.getLocation(), Action.RIGHT_CLICK_BLOCK)) {
event.setAllowed(true); event.setResult(Result.ALLOW);
orig.setCancelled(false); orig.setCancelled(false);
} }
@ -106,8 +94,7 @@ public class WorldGuardListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onDamageEntity(DamageEntityEvent event) { public void onDamageEntity(DamageEntityEvent event) {
if (Config.enableWorldGuardIntegration) { if (Config.enableWorldGuardIntegration) {
Player player = event.getCause().getFirstPlayer(); Player player = event.getPlayer();
if (player == null) return;
if (event.getOriginalEvent() instanceof EntityDamageByEntityEvent) { if (event.getOriginalEvent() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent orig = (EntityDamageByEntityEvent) event.getOriginalEvent(); EntityDamageByEntityEvent orig = (EntityDamageByEntityEvent) event.getOriginalEvent();
@ -120,7 +107,7 @@ public class WorldGuardListener implements Listener {
for (Shop shop : plugin.getShopUtils().getShops()) { for (Shop shop : plugin.getShopUtils().getShops()) {
if (shop.getHologram() != null && shop.getHologram().contains((ArmorStand) e)) { if (shop.getHologram() != null && shop.getHologram().contains((ArmorStand) e)) {
if (isAllowed(player, shop.getLocation(), Action.LEFT_CLICK_BLOCK)) { if (isAllowed(player, shop.getLocation(), Action.LEFT_CLICK_BLOCK)) {
event.setAllowed(true); event.setResult(Result.ALLOW);
orig.setCancelled(false); orig.setCancelled(false);
} }
@ -135,8 +122,7 @@ public class WorldGuardListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onUseBlock(UseBlockEvent event) { public void onUseBlock(UseBlockEvent event) {
if (Config.enableWorldGuardIntegration) { if (Config.enableWorldGuardIntegration) {
Player player = event.getCause().getFirstPlayer(); Player player = event.getPlayer();
if (player == null) return;
if (event.getOriginalEvent() instanceof PlayerInteractEvent) { if (event.getOriginalEvent() instanceof PlayerInteractEvent) {
PlayerInteractEvent orig = (PlayerInteractEvent) event.getOriginalEvent(); PlayerInteractEvent orig = (PlayerInteractEvent) event.getOriginalEvent();
@ -145,7 +131,7 @@ public class WorldGuardListener implements Listener {
Material type = orig.getClickedBlock().getType(); Material type = orig.getClickedBlock().getType();
if (type == Material.CHEST || type == Material.TRAPPED_CHEST) { if (type == Material.CHEST || type == Material.TRAPPED_CHEST) {
if (isAllowed(player, orig.getClickedBlock().getLocation(), orig.getAction())) { if (isAllowed(player, orig.getClickedBlock().getLocation(), orig.getAction())) {
event.setAllowed(true); event.setResult(Result.ALLOW);
ClickType ct = ClickType.getPlayerClickType(player); ClickType ct = ClickType.getPlayerClickType(player);
if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) { if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) {
@ -161,7 +147,7 @@ public class WorldGuardListener implements Listener {
if (orig.getInventory().getHolder() instanceof Chest) { if (orig.getInventory().getHolder() instanceof Chest) {
if (isAllowed(player, ((Chest)orig.getInventory().getHolder()).getLocation(), Action.RIGHT_CLICK_BLOCK)) { if (isAllowed(player, ((Chest)orig.getInventory().getHolder()).getLocation(), Action.RIGHT_CLICK_BLOCK)) {
event.setAllowed(true); event.setResult(Result.ALLOW);
ClickType ct = ClickType.getPlayerClickType(player); ClickType ct = ClickType.getPlayerClickType(player);
if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) { if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) {