From 96798bbb908a436a61cb7220314270efd561d5ea Mon Sep 17 00:00:00 2001 From: Wyatt Childers Date: Sun, 1 May 2016 13:39:09 -0400 Subject: [PATCH] Fixed an issue where a block had to be clicked for WorldEdit to receive event information --- .../worldedit/sponge/SpongeWorldEdit.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java index 6c9cac5f0..27a2291b7 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java @@ -43,6 +43,8 @@ import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.scheduler.Task; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.text.channel.MessageChannel; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; @@ -136,6 +138,8 @@ public class SpongeWorldEdit { WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); } + private boolean ignoreLeftClickAir = false; + @Listener public void onPlayerInteract(InteractBlockEvent event) { if (platform == null) { @@ -156,15 +160,14 @@ public class SpongeWorldEdit { BlockSnapshot targetBlock = event.getTargetBlock(); Optional> optLoc = targetBlock.getLocation(); - if (!optLoc.isPresent()) { - return; - } - - Location loc = optLoc.get(); BlockType interactedType = targetBlock.getState().getType(); - if (event instanceof InteractBlockEvent.Primary) { if (interactedType != BlockTypes.AIR) { + if (!optLoc.isPresent()) { + return; + } + + Location loc = optLoc.get(); WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), loc.getX(), loc.getY(), loc.getZ()); if (we.handleBlockLeftClick(player, pos)) { @@ -174,9 +177,31 @@ public class SpongeWorldEdit { if (we.handleArmSwing(player)) { event.setCancelled(true); } + + if (!ignoreLeftClickAir) { + Task.builder().delayTicks(2).execute(() -> { + ignoreLeftClickAir = false; + + }).submit(this); + + ignoreLeftClickAir = true; + } + } else { + if (ignoreLeftClickAir) { + return; + } + + if (we.handleArmSwing(player)) { + event.setCancelled(true); + } } } else if (event instanceof InteractBlockEvent.Secondary) { if (interactedType != BlockTypes.AIR) { + if (!optLoc.isPresent()) { + return; + } + + Location loc = optLoc.get(); WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), loc.getX(), loc.getY(), loc.getZ()); if (we.handleBlockRightClick(player, pos)) {