Jump to content

Unleash lead Event


daaan

Recommended Posts

 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?

Link to comment
Share on other sites

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());
                }
            }
        }
    }

 

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by daaan
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.