From 9f9522c82e3a91f76d12e9054c7b971cfdc0aeda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 9 Aug 2014 00:08:08 +0200 Subject: [PATCH] Added guard against recursive player interaction events in FMP placement handler, should fix #478. --- .../oc/common/multipart/EventHandler.scala | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/multipart/EventHandler.scala b/src/main/scala/li/cil/oc/common/multipart/EventHandler.scala index 7174d002e..f63345424 100644 --- a/src/main/scala/li/cil/oc/common/multipart/EventHandler.scala +++ b/src/main/scala/li/cil/oc/common/multipart/EventHandler.scala @@ -17,12 +17,23 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action import net.minecraftforge.event.entity.player.{PlayerDestroyItemEvent, PlayerInteractEvent} object EventHandler { + private var currentlyPlacing = false + @ForgeSubscribe def playerInteract(event: PlayerInteractEvent) { - val player = event.entityPlayer - if (event.action == Action.RIGHT_CLICK_BLOCK && player.getEntityWorld.isRemote) { - if (place(player)) { - event.setCanceled(true) + this.synchronized { + if (currentlyPlacing) return + try { + currentlyPlacing = true + val player = event.entityPlayer + if (event.action == Action.RIGHT_CLICK_BLOCK && player.getEntityWorld.isRemote) { + if (place(player)) { + event.setCanceled(true) + } + } + } + finally { + currentlyPlacing = false } } }