mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-10 12:59:34 +01:00
Use a less coarse can-interact-on-click check.
Fixes WORLDGUARD-3303.
This commit is contained in:
parent
223d22e79f
commit
37f39eaf66
@ -317,7 +317,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
placed = clicked.getRelative(event.getBlockFace());
|
||||
|
||||
// Only fire events for blocks that are modified when right clicked
|
||||
if (isBlockModifiedOnClick(clicked) || (item != null && isItemAppliedToBlock(item, clicked))) {
|
||||
if (isBlockModifiedOnClick(clicked, event.getAction() == Action.RIGHT_CLICK_BLOCK) || (item != null && isItemAppliedToBlock(item, clicked))) {
|
||||
if (Events.fireAndTestCancel(new UseBlockEvent(event, cause, clicked))) {
|
||||
event.setUseInteractedBlock(Result.DENY);
|
||||
}
|
||||
@ -866,8 +866,8 @@ private boolean hasInteractBypass(World world, ItemStack item) {
|
||||
return getWorldConfig(world).allowAllInteract.test(item);
|
||||
}
|
||||
|
||||
private boolean isBlockModifiedOnClick(Block block) {
|
||||
return Materials.isBlockModifiedOnClick(block.getType()) && !hasInteractBypass(block);
|
||||
private boolean isBlockModifiedOnClick(Block block, boolean rightClick) {
|
||||
return Materials.isBlockModifiedOnClick(block.getType(), rightClick) && !hasInteractBypass(block);
|
||||
}
|
||||
|
||||
private boolean isItemAppliedToBlock(ItemStack item, Block clicked) {
|
||||
|
@ -38,8 +38,9 @@
|
||||
*/
|
||||
public final class Materials {
|
||||
|
||||
private static final int MODIFIED_ON_CLICK = 1;
|
||||
private static final int MODIFIES_BLOCKS = 2;
|
||||
private static final int MODIFIED_ON_RIGHT = 1;
|
||||
private static final int MODIFIED_ON_LEFT = 2;
|
||||
private static final int MODIFIES_BLOCKS = 4;
|
||||
|
||||
private static final BiMap<EntityType, Material> ENTITY_ITEMS = HashBiMap.create();
|
||||
private static final Map<Material, Integer> MATERIAL_FLAGS = new HashMap<Material, Integer>();
|
||||
@ -89,10 +90,10 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.GLASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.LAPIS_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LAPIS_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.DISPENSER, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DISPENSER, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.SANDSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NOTE_BLOCK, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BED_BLOCK, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.NOTE_BLOCK, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BED_BLOCK, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.POWERED_RAIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.DETECTOR_RAIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.PISTON_STICKY_BASE, 0);
|
||||
@ -112,7 +113,7 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.DOUBLE_STEP, 0);
|
||||
MATERIAL_FLAGS.put(Material.STEP, 0);
|
||||
MATERIAL_FLAGS.put(Material.BRICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.TNT, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.TNT, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BOOKSHELF, 0);
|
||||
MATERIAL_FLAGS.put(Material.MOSSY_COBBLESTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.OBSIDIAN, 0);
|
||||
@ -120,37 +121,37 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.FIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.MOB_SPAWNER, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CHEST, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.CHEST, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_WIRE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DIAMOND_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.WORKBENCH, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.WORKBENCH, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.CROPS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SOIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.FURNACE, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BURNING_FURNACE, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.FURNACE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BURNING_FURNACE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.SIGN_POST, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_DOOR, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.WOODEN_DOOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.LADDER, 0);
|
||||
MATERIAL_FLAGS.put(Material.RAILS, 0);
|
||||
MATERIAL_FLAGS.put(Material.COBBLESTONE_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.WALL_SIGN, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEVER, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.LEVER, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.STONE_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_DOOR_BLOCK, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.IRON_DOOR_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.GLOWING_REDSTONE_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_TORCH_OFF, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_TORCH_ON, 0);
|
||||
MATERIAL_FLAGS.put(Material.STONE_BUTTON, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.STONE_BUTTON, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.SNOW, 0);
|
||||
MATERIAL_FLAGS.put(Material.ICE, 0);
|
||||
MATERIAL_FLAGS.put(Material.SNOW_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.CACTUS, 0);
|
||||
MATERIAL_FLAGS.put(Material.CLAY, 0);
|
||||
MATERIAL_FLAGS.put(Material.SUGAR_CANE_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.JUKEBOX, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.JUKEBOX, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHERRACK, 0);
|
||||
@ -158,11 +159,11 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.GLOWSTONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.PORTAL, 0);
|
||||
MATERIAL_FLAGS.put(Material.JACK_O_LANTERN, 0);
|
||||
MATERIAL_FLAGS.put(Material.CAKE_BLOCK, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DIODE_BLOCK_OFF, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DIODE_BLOCK_ON, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.CAKE_BLOCK, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.DIODE_BLOCK_OFF, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.DIODE_BLOCK_ON, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.STAINED_GLASS, 0);
|
||||
MATERIAL_FLAGS.put(Material.TRAP_DOOR, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.TRAP_DOOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.MONSTER_EGGS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SMOOTH_BRICK, 0);
|
||||
MATERIAL_FLAGS.put(Material.HUGE_MUSHROOM_1, 0);
|
||||
@ -173,7 +174,7 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.PUMPKIN_STEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.MELON_STEM, 0);
|
||||
MATERIAL_FLAGS.put(Material.VINE, 0);
|
||||
MATERIAL_FLAGS.put(Material.FENCE_GATE, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.FENCE_GATE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BRICK_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.SMOOTH_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.MYCEL, 0);
|
||||
@ -182,13 +183,13 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.NETHER_FENCE, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_BRICK_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.NETHER_WARTS, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENCHANTMENT_TABLE, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BREWING_STAND, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.CAULDRON, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.ENCHANTMENT_TABLE, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BREWING_STAND, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.CAULDRON, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_PORTAL, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_PORTAL_FRAME, 0);
|
||||
MATERIAL_FLAGS.put(Material.ENDER_STONE, 0);
|
||||
MATERIAL_FLAGS.put(Material.DRAGON_EGG, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DRAGON_EGG, MODIFIED_ON_LEFT | MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_LAMP_OFF, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_LAMP_ON, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_DOUBLE_STEP, 0);
|
||||
@ -203,28 +204,28 @@ public final class Materials {
|
||||
MATERIAL_FLAGS.put(Material.SPRUCE_WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.BIRCH_WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.JUNGLE_WOOD_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.COMMAND, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.BEACON, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.COMMAND, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.BEACON, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.COBBLE_WALL, 0);
|
||||
MATERIAL_FLAGS.put(Material.FLOWER_POT, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.FLOWER_POT, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.CARROT, 0);
|
||||
MATERIAL_FLAGS.put(Material.POTATO, 0);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_BUTTON, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.WOOD_BUTTON, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.SKULL, 0);
|
||||
MATERIAL_FLAGS.put(Material.ANVIL, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.TRAPPED_CHEST, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.ANVIL, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.TRAPPED_CHEST, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.GOLD_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.IRON_PLATE, 0);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_COMPARATOR_OFF, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_COMPARATOR_ON, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DAYLIGHT_DETECTOR, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_COMPARATOR_OFF, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_COMPARATOR_ON, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.DAYLIGHT_DETECTOR, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.REDSTONE_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ_ORE, 0);
|
||||
MATERIAL_FLAGS.put(Material.HOPPER, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.HOPPER, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ_BLOCK, 0);
|
||||
MATERIAL_FLAGS.put(Material.QUARTZ_STAIRS, 0);
|
||||
MATERIAL_FLAGS.put(Material.ACTIVATOR_RAIL, 0);
|
||||
MATERIAL_FLAGS.put(Material.DROPPER, MODIFIED_ON_CLICK);
|
||||
MATERIAL_FLAGS.put(Material.DROPPER, MODIFIED_ON_RIGHT);
|
||||
MATERIAL_FLAGS.put(Material.STAINED_CLAY, 0);
|
||||
MATERIAL_FLAGS.put(Material.STAINED_GLASS_PANE, 0);
|
||||
MATERIAL_FLAGS.put(Material.LEAVES_2, 0);
|
||||
@ -648,11 +649,14 @@ public static boolean isRedstoneOre(Material type) {
|
||||
* aware of.</p>
|
||||
*
|
||||
* @param material the material
|
||||
* @param rightClick whether it is a right click
|
||||
* @return true if the block is modified
|
||||
*/
|
||||
public static boolean isBlockModifiedOnClick(Material material) {
|
||||
public static boolean isBlockModifiedOnClick(Material material, boolean rightClick) {
|
||||
Integer flags = MATERIAL_FLAGS.get(material);
|
||||
return flags == null || (flags & MODIFIED_ON_CLICK) == MODIFIED_ON_CLICK;
|
||||
return flags == null
|
||||
|| (rightClick && (flags & MODIFIED_ON_RIGHT) == MODIFIED_ON_RIGHT)
|
||||
|| (!rightClick && (flags & MODIFIED_ON_LEFT) == MODIFIED_ON_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user