Add config option to limit trading with shops via protections

This commit is contained in:
Phoenix616 2020-06-18 17:01:52 +01:00
parent e520544d3a
commit 3e061dda8d
4 changed files with 21 additions and 3 deletions

View File

@ -18,6 +18,7 @@ public class Messages {
@PrecededBySpace
public static String ACCESS_DENIED = "You don't have permission to access that shop's storage container!";
public static String TRADE_DENIED = "You don't have permission to trade with that shop!";
@PrecededBySpace
public static String NOT_ENOUGH_MONEY = "You don't have enough money!";

View File

@ -249,6 +249,9 @@ public class Properties {
@ConfigurationComment("Do you want to disable the hopper protection, which prevents Hopper-Minecarts from taking items out of shops?")
public static boolean TURN_OFF_HOPPER_PROTECTION = false;
@ConfigurationComment("Only allow users to buy/sell that have access to the sign's protection? (E.g. LWC protection)")
public static boolean CHECK_ACCESS_FOR_SHOP_USE = false;
@ConfigurationComment("Do you want to protect shop chests with LWC?")
public static boolean PROTECT_CHEST_WITH_LWC = false;

View File

@ -134,6 +134,11 @@ public class PlayerInteract implements Listener {
event.setCancelled(true);
}
if (Properties.CHECK_ACCESS_FOR_SHOP_USE && !Security.canAccess(player, block, true)) {
player.sendMessage(Messages.prefix(Messages.TRADE_DENIED));
return;
}
//Bukkit.getLogger().info("ChestShop - DEBUG - "+block.getWorld().getName()+": "+block.getLocation().getBlockX()+", "+block.getLocation().getBlockY()+", "+block.getLocation().getBlockZ());
PreTransactionEvent pEvent = preparePreTransactionEvent(sign, player, action);
if (pEvent == null)

View File

@ -1,5 +1,6 @@
package com.Acrobot.ChestShop.Plugins;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
@ -12,8 +13,11 @@ import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.Sign;
import org.bukkit.block.data.type.WallSign;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
@ -54,7 +58,12 @@ public class WorldGuardProtection implements Listener {
}
ApplicableRegionSet set = manager.getApplicableRegions(location.toVector().toBlockPoint());
if (!canAccess(localPlayer, (World) location.getExtent(), set)) {
StateFlag flag = Flags.CHEST_ACCESS;
if (BlockUtil.isSign(block)) {
flag = Flags.USE;
}
if (!canAccess(localPlayer, (World) location.getExtent(), set, flag)) {
event.setResult(Event.Result.DENY);
}
}
@ -66,9 +75,9 @@ public class WorldGuardProtection implements Listener {
|| !wcfg.getChestProtection().isProtected(location, player);
}
private boolean canAccess(LocalPlayer player, World world, ApplicableRegionSet set) {
private boolean canAccess(LocalPlayer player, World world, ApplicableRegionSet set, StateFlag flag) {
return new RegionPermissionModel(player).mayIgnoreRegionProtection(world)
|| set.testState(player, Flags.BUILD)
|| set.testState(player, Flags.CHEST_ACCESS);
|| set.testState(player, flag);
}
}