diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt index 2608a03..ea335d6 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/LinkingListener.kt @@ -29,6 +29,15 @@ class LinkingListener : Listener { if (event.clickedBlock!!.type !in CONTAINERS) return if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return + val minion = linking.remove(event.player) ?: return + event.isCancelled = true + if (minion.getLocation() + .distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE() + ) { + event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_FAIL())) + return + } + val linkEvent = MinionChestLinkEvent( linking.getValue(event.player), event.player, @@ -39,15 +48,6 @@ class LinkingListener : Listener { return } - val minion = linking.remove(event.player) ?: return - event.isCancelled = true - if (minion.getLocation() - .distanceSquared(event.clickedBlock!!.location) > Config.MAX_LINKING_DISTANCE() * Config.MAX_LINKING_DISTANCE() - ) { - event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_FAIL())) - return - } - event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.LINK_SUCCESS())) minion.setLinkedChest(event.clickedBlock!!.location) }