Posted January 27, 20223 yr I'm trying to make the lead unbreakable/unleash-able, without success. Canceling the BreakEvent does work for blocks but not for lead tied in a fence. Also tried canceling the PlayerInteractEvent.RightClickBlock and PlayerInteractEvent.RightClickBlock events. Any suggestions?
January 27, 20223 yr Hi! Don't forget that the lead at the fence is an entity and if you right-click you aren't right-clicking the fence but the lead entity Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can Also: PLEASE use SPOILERS for logs!
January 31, 20223 yr Author On 1/27/2022 at 9:14 AM, diesieben07 said: Show your attempted code. Spoiler @SubscribeEvent public static void onPlayerBreakBlock(BlockEvent.BreakEvent event) { event.setCanceled(true); } There I've erased all the logic, basically it checks if the position of the event is inside a prism, but still not working, I cancels successfully the break of others blocks, for example cant break dirt, but the lead still breaking and now the horse is free. I've taken a look at other events (PlayerInteractEvent.RightClickBlock, PlayerInteractEvent.LeftClickBlock, PlayerInteractEvent, PlayerInteractEvent.EntityInteract ) and cant do things like read a book in a lectern, open doors and so, but none seams to work with the lead at fence. The complete method looks like this Spoiler @SubscribeEvent public static void onPlayerBreakBlock(BlockEvent.BreakEvent event) { Player p = event.getPlayer(); if( p.hasPermissions(1) ) return; Region r = RegionManger.insideAnyRegion(new Vec3(event.getPos().getX(), event.getPos().getY(), event.getPos().getZ()), p.level.dimension().location().getPath()); if (r != null) { if (!r.hasOwner(event.getPlayer().getGameProfile().getName())) { event.setCanceled(true); if (r.getName().equals("")) { p.sendMessage(new TextComponent("¡hey! that's not your region"), p.getUUID()); } else { p.sendMessage(new TextComponent("the region " + r.getName() + " is protected"), p.getUUID()); } } } }
January 31, 20223 yr Author 9 hours ago, diesieben07 said: PlayerInteractEvent.EntityInteract will fire for leash knots as they are entities. Just tried with EntityInteract, but still breaking, I'm thinking if it is an event hierarchy problem, because I have subscribed to other events, here is my code Spoiler @SubscribeEvent public static void onPlayerEntityInteract(PlayerInteractEvent.EntityInteract event) { Player p = event.getPlayer(); if (!p.hasPermissions(1)) event.setCanceled(true); } And here the evidence: https://drive.google.com/file/d/1w620jGN-AZ5kHKm1o6XqB2F7NnBeqmHe/view?usp=sharing Note that the "usu" player (bottom) has been /deop at the start of the video
January 31, 20223 yr Author 11 minutes ago, diesieben07 said: Are you sure the event handler is working? Check using the debugger. Ok I printed with LogManager like this: Spoiler @SubscribeEvent public static void onPlayerEntityInteract(PlayerInteractEvent.EntityInteract event) { Player p = event.getPlayer(); if (!p.hasPermissions(1)) { event.setCanceled(true); LogManager.getLogger().info("EntityInteract does cancel"); }else{ LogManager.getLogger().info("EntityInteract not cancel"); } } It prints "EntityInteract does cancel" twice when I use right click with standard player and the lead doesn't break, that's fine (although don't know why prints twice), but when I use left click prints nothing and the lead breaks.
January 31, 20223 yr Author 1 hour ago, diesieben07 said: Why is this the first time that you mention this...? Hanging entities like the leash knot also immediately drop upon attack. You can use AttackEntityEvent to prevent this. I see, if you left click an Entity you attack it, sounds logic, just added the following code and now it works Spoiler @SubscribeEvent public static void onAttackEntity(AttackEntityEvent event) { if (event.getTarget() instanceof HangingEntity) { event.setCanceled(true); } } Thank for your patience you helped me a lot. Edited January 31, 20223 yr by daaan
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.