mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 18:32:24 +00:00
Revised WorldGuard event hooks
Make sure the flag chest-access is granted when creating a shop.
This commit is contained in:
parent
188bf87eba
commit
e38fe9fe14
@ -38,16 +38,19 @@ public class WorldGuardListener implements Listener {
|
|||||||
private boolean isAllowed(Player player, Location location, Action action) {
|
private boolean isAllowed(Player player, Location location, Action action) {
|
||||||
Shop shop = plugin.getShopUtils().getShop(location);
|
Shop shop = plugin.getShopUtils().getShop(location);
|
||||||
|
|
||||||
if (action == Action.RIGHT_CLICK_BLOCK && shop != null) {
|
if (shop != null) {
|
||||||
if (shop.getVendor().getUniqueId().equals(player.getUniqueId()) && shop.getShopType() != Shop.ShopType.ADMIN) {
|
if (shop.getVendor().getUniqueId().equals(player.getUniqueId()) && shop.getShopType() != Shop.ShopType.ADMIN) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WorldGuardWrapper wgWrapper = WorldGuardWrapper.getInstance();
|
||||||
|
|
||||||
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 WorldGuardWrapper.getInstance().queryStateFlag(player, location, "create-shop").orElse(false);
|
return wgWrapper.queryStateFlag(player, location, "create-shop").orElse(false)
|
||||||
|
&& wgWrapper.queryStateFlag(player, location, "chest-access").orElse(false);
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
case INFO:
|
case INFO:
|
||||||
case OPEN:
|
case OPEN:
|
||||||
@ -56,7 +59,7 @@ public class WorldGuardListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
if (shop != null) {
|
if (shop != null) {
|
||||||
String flagName = (shop.getShopType() == Shop.ShopType.NORMAL ? "use-shop" : "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 wgWrapper.queryStateFlag(player, location, flagName).orElse(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,8 +72,7 @@ public class WorldGuardListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (event.getOriginalEvent() instanceof PlayerInteractAtEntityEvent) {
|
if (event.getOriginalEvent() instanceof PlayerInteractAtEntityEvent) {
|
||||||
PlayerInteractAtEntityEvent orig = (PlayerInteractAtEntityEvent) event.getOriginalEvent();
|
Entity e = event.getEntity();
|
||||||
Entity e = orig.getRightClicked();
|
|
||||||
|
|
||||||
if (e.getType() == EntityType.ARMOR_STAND) {
|
if (e.getType() == EntityType.ARMOR_STAND) {
|
||||||
if (!Hologram.isPartOfHologram((ArmorStand) e))
|
if (!Hologram.isPartOfHologram((ArmorStand) e))
|
||||||
@ -80,7 +82,6 @@ public class WorldGuardListener implements Listener {
|
|||||||
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.setResult(Result.ALLOW);
|
event.setResult(Result.ALLOW);
|
||||||
orig.setCancelled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -97,8 +98,7 @@ public class WorldGuardListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (event.getOriginalEvent() instanceof EntityDamageByEntityEvent) {
|
if (event.getOriginalEvent() instanceof EntityDamageByEntityEvent) {
|
||||||
EntityDamageByEntityEvent orig = (EntityDamageByEntityEvent) event.getOriginalEvent();
|
Entity e = event.getEntity();
|
||||||
Entity e = orig.getEntity();
|
|
||||||
|
|
||||||
if (e.getType() == EntityType.ARMOR_STAND) {
|
if (e.getType() == EntityType.ARMOR_STAND) {
|
||||||
if (!Hologram.isPartOfHologram((ArmorStand) e))
|
if (!Hologram.isPartOfHologram((ArmorStand) e))
|
||||||
@ -108,7 +108,6 @@ public class WorldGuardListener implements Listener {
|
|||||||
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.setResult(Result.ALLOW);
|
event.setResult(Result.ALLOW);
|
||||||
orig.setCancelled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -132,13 +131,6 @@ public class WorldGuardListener implements Listener {
|
|||||||
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.setResult(Result.ALLOW);
|
event.setResult(Result.ALLOW);
|
||||||
|
|
||||||
ClickType ct = ClickType.getPlayerClickType(player);
|
|
||||||
if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) {
|
|
||||||
// Don't un-cancel original event when trying to create shop.
|
|
||||||
// Flag "chest-access" has to be allowed too, so the original event won't be cancelled.
|
|
||||||
orig.setCancelled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,15 +138,8 @@ public class WorldGuardListener implements Listener {
|
|||||||
InventoryOpenEvent orig = (InventoryOpenEvent) event.getOriginalEvent();
|
InventoryOpenEvent orig = (InventoryOpenEvent) event.getOriginalEvent();
|
||||||
|
|
||||||
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.setResult(Result.ALLOW);
|
event.setResult(Result.ALLOW);
|
||||||
|
|
||||||
ClickType ct = ClickType.getPlayerClickType(player);
|
|
||||||
if (!(ct != null && ct.getClickType() == ClickType.EnumClickType.CREATE)) {
|
|
||||||
// Don't un-cancel original event when trying to create shop.
|
|
||||||
// Flag "chest-access" has to be allowed too, so the original event won't be cancelled.
|
|
||||||
orig.setCancelled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user