Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented EntityDamageDoorEvent #10327

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

CMarcoo
Copy link
Contributor

@CMarcoo CMarcoo commented Mar 14, 2024

EntityDamageDoorEvent: Handle Door Damage Interactions

Description

I've introduced a new event called EntityDamageDoorEvent in the PaperMC server software. This event is triggered when an entity (currently limited to Zombies and Pillagers by default) damages a door. It provides essential information about the damaged door, the break time, and the total door break time.

This implementation takes into account differences in breaking time between zombies (240 ticks) and pillagers (60 ticks).

Event Details

  • Event Name: EntityDamageDoorEvent
  • Trigger: When an entity damages a door
  • Purpose: To allow developers to handle door damage interactions

Key Components

  1. Entity: The damaging entity (e.g., Zombie, Pillager).
  2. Door: The door being damaged.
  3. Break Time: The ticks spent breaking the door.
  4. Door Break Time: The total ticks required to break the door.

Usage Example

@EventHandler
public void onEntityDamageDoor(EntityDamageDoorEvent event) {
    Entity damagingEntity = event.getEntity();
    Door damagedDoor = event.getDamagedDoor();
    int breakTime = event.getBreakTime();
    int totalBreakTime = event.getDoorBreakTime();
    
    float percentage = ((float) breakTime / totalBreakTime) * 100f;
    if (percentage > 50.0f) {
        e.getNearbyEntities(5, 3, 5).stream()
            .filter(Player.class::isInstance)
            .map(Player.class::cast)
            .forEach(p -> p.sendMessage("Your home door is halfway broken, watch out dude :("));
    }
    // Additional logic...
}

@CMarcoo CMarcoo requested a review from a team as a code owner March 14, 2024 16:29
Copy link
Contributor

@lynxplay lynxplay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge the patches, instead of committing your changes as a new patch.
See our contribution.md for instructions.

Moving break time up also seems a bit meh in terms of diff.
What is stopping us from just passing this.breakTime + 1 to the event?

Looking through the code a bit more, I'd also add a notice in the javadocs that this even will be fired even if breaking the door is disallowed by the mob_griefing gamerule as that may be wrongly assumed to not be the case.

You also missed the import org.bukkit.craftbukkit.block.impl.CraftDoor; line in your import inlining.

Beyond that, is it worth to expose the "swing arm" part of the logic to the event?
E.g. allow plugins to define/overide if the entity will swing their arms in the damage tick.

@Leguan16
Copy link
Contributor

If you don't know what lynxplay is talking about: Read the contributing guidelines here: https://github.com/PaperMC/Paper/blob/master/CONTRIBUTING.md

@CMarcoo
Copy link
Contributor Author

CMarcoo commented Mar 14, 2024

yes I noticed I forgot to merge my patches :(

@lynxplay
Copy link
Contributor

Are you going to fix the patch situation or do you want me to do that?

@CMarcoo
Copy link
Contributor Author

CMarcoo commented Mar 17, 2024

Are you going to fix the patch situation or do you want me to do that?

Yes please. I truly don't know how to do it. I tried merging my patches and it became even worse.

Comment on lines 24 to 31
+/**
+ * Called for every tick an entity is damaging a door.
+ * <p>
+ * This event is only called when a new level of progress
+ * has been reached by the damaging entity.
+ */
+public class EntityDamageDoorEvent extends EntityEvent implements Cancellable {
+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the event is called every tick OR only when new damage progress level is displayed? This is a bit unclear, at least for me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every tick that the door is being progressively damaged to its destruction.

+ private final int doorBreakTime;
+ private boolean playEffect;
+
+ public EntityDamageDoorEvent(final @NotNull Entity what, final @NotNull BlockData damagedDoor, final int breakTime, final int doorBreakTime, boolean playEffect) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing internal annotation and what is not a good name here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not resolved yet

+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final BlockData damagedDoor;
+ private boolean cancelled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field should be at the bottom of this group

+ * Set the current progress in ticks that
+ * this entity has spent damaging the door.
+ * <p>
+ * To instantly break this door, supply {@link EntityDamageDoorEvent#getRequiredBreakTicks()} - 1 into this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to reference the event itself in that link since you're already in that class

+ /**
+ * Cancelling this event will reset the break progress of this door.
+ *
+ * @param cancel true if you wish to cancel this event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant with the interface

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: CMarcoo <cmarco.org@gmail.com>
Date: Thu, 14 Mar 2024 17:04:43 +0100
Subject: [PATCH] Added EntityDamageDoorEvent and implemented into Server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second part of the name is not needed and implicit and no dots are required at the end

@kashike kashike added the type: feature Request for a new Feature. label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Request for a new Feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants