From 85e9ff23fdf1ae44633b867a08c4f25e2e8fc84d Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Wed, 26 Aug 2020 20:15:05 +0200 Subject: [PATCH] prevent double processing when clicking on a block with item function --- src/main/java/com/flemmli97/flan/Flan.java | 1 - .../flan/event/BlockInteractEvents.java | 5 ++-- .../flan/event/ItemInteractEvents.java | 29 +++++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/flemmli97/flan/Flan.java b/src/main/java/com/flemmli97/flan/Flan.java index 0fb0f94..c468997 100644 --- a/src/main/java/com/flemmli97/flan/Flan.java +++ b/src/main/java/com/flemmli97/flan/Flan.java @@ -15,7 +15,6 @@ import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.event.player.UseEntityCallback; import net.fabricmc.fabric.api.event.player.UseItemCallback; - public class Flan implements ModInitializer { @Override diff --git a/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java b/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java index ae34c61..8e88565 100644 --- a/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java +++ b/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java @@ -20,6 +20,7 @@ import net.minecraft.entity.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; @@ -92,10 +93,10 @@ public class BlockInteractEvents { DoubleBlockHalf half = state.get(DoorBlock.HALF); if (half == DoubleBlockHalf.LOWER) { BlockState other = world.getBlockState(hitResult.getBlockPos().up()); - player.world.updateListeners(hitResult.getBlockPos().up(), other, other, 2); + player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().up(), other)); } else { BlockState other = world.getBlockState(hitResult.getBlockPos().down()); - player.world.updateListeners(hitResult.getBlockPos().down(), other, other, 2); + player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().down(), other)); } } PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); diff --git a/src/main/java/com/flemmli97/flan/event/ItemInteractEvents.java b/src/main/java/com/flemmli97/flan/event/ItemInteractEvents.java index 31c5023..94b3644 100644 --- a/src/main/java/com/flemmli97/flan/event/ItemInteractEvents.java +++ b/src/main/java/com/flemmli97/flan/event/ItemInteractEvents.java @@ -18,6 +18,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.item.Items; +import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; @@ -81,21 +82,28 @@ public class ItemInteractEvents { return ActionResult.PASS; boolean actualInClaim = placePos.getY()>=claim.getDimensions()[4]; ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer(); - if (actualInClaim && context.getStack().getItem() == Items.END_CRYSTAL) { - if (claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, true)) + if (context.getStack().getItem() == Items.END_CRYSTAL) { + if (claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, false)) return ActionResult.PASS; - return ActionResult.FAIL; + else if(actualInClaim) { + player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true); + return ActionResult.FAIL; + } } - if (claim.canInteract(player, EnumPermission.PLACE, placePos, true)) { + if (claim.canInteract(player, EnumPermission.PLACE, placePos, false)) { if(!actualInClaim && context.getStack().getItem() instanceof BlockItem){ claim.extendDownwards(placePos); } return ActionResult.PASS; } - BlockState other = context.getWorld().getBlockState(placePos.up()); - player.world.updateListeners(placePos.up(), other, other, 2); - PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); - return ActionResult.FAIL; + else if(actualInClaim) { + player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true); + BlockState other = context.getWorld().getBlockState(placePos.up()); + player.networkHandler.sendPacket(new BlockUpdateS2CPacket(placePos.up(), other)); + PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); + return ActionResult.FAIL; + } + return ActionResult.PASS; } private static boolean cantClaimInWorld(ServerWorld world) { @@ -118,8 +126,11 @@ public class ItemInteractEvents { return; } ClaimStorage storage = ClaimStorage.get(player.getServerWorld()); - Claim claim = storage.getClaimAt(target); + Claim claim = storage.getClaimAt(target.add(0,255,0)); PlayerClaimData data = PlayerClaimData.get(player); + if(data.claimCooldown()) + return; + data.setClaimActionCooldown(); if (claim != null) { if (claim.canInteract(player, EnumPermission.EDITCLAIM, target)) { if (data.getEditMode() == EnumEditMode.SUBCLAIM) {