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

Add Paper Only TargetHitScriptEvent #2604

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

Joo200
Copy link

@Joo200 Joo200 commented Mar 17, 2024

Add the Event from Paper when a Target block is hit by an arrow to Denizen.

public void onProjectileHit(TargetHitEvent event) {
this.event = event;
projectile = new EntityTag(event.getEntity());

Copy link
Member

Choose a reason for hiding this comment

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

stray newlines

if (projectile.getLocation() == null) {
return;
}
if (Double.isNaN(projectile.getLocation().getDirection().normalize().getX())) {
Copy link
Member

Choose a reason for hiding this comment

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

This is clearly copypasted from the projectile hit event - is it even relevant to have here?

Copy link
Member

Choose a reason for hiding this comment

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

Relatedly - is this actually a unique event? ie is it not already covered by the existing projectile hit event?

Copy link
Member

Choose a reason for hiding this comment

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

Glance at source code public class TargetHitEvent extends ProjectileHitEvent indicates it's not unique

Copy link
Author

Choose a reason for hiding this comment

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

I don't see a reason why this should be needed. I copied it from the ProjectileHitEvent. In paper the Location of an entity is marked with @NotNull so I removed those checks

Copy link
Author

Choose a reason for hiding this comment

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

Glance at source code public class TargetHitEvent extends ProjectileHitEvent indicates it's not unique

It has a different HandlerList so it's a different event

import org.bukkit.event.Listener;


public class TargetHitScriptEvent extends BukkitScriptEvent implements Listener {
Copy link
Member

Choose a reason for hiding this comment

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

classname should match the Denizen name not the paper name - ie TargetBlockHitScriptEvent


@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.matches("targetblock hit");
Copy link
Member

Choose a reason for hiding this comment

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

This is the legacy couldMatch handling, should use the modern register handling

projectile = new EntityTag(event.getEntity());
hitBlock = new LocationTag(event.getHitBlock().getLocation());
shooter = projectile.getShooter();
strength = new ElementTag(event.getSignalStrength());
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be read in advance, should just be in the getContext call

Copy link
Author

Choose a reason for hiding this comment

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

I moved the Strengh attribute to the getContext call. The other Tags are used in other methods. If you want to move them too I would have to create new Tags every call.

@Joo200
Copy link
Author

Joo200 commented Apr 7, 2024

Sorry for the delay of this PR.

I rebased this PR and applied all PR comments

@mcmonkey4eva
Copy link
Member

Why the rebase?

// @Context
// <context.projectile> returns an EntityTag of the projectile.
// <context.shooter> returns a EntityTag of the shooter of the projectile.
// <context.hit_block> returns a LocationTag of the block
Copy link
Member

Choose a reason for hiding this comment

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

Needs periods at end of line

Copy link
Member

Choose a reason for hiding this comment

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

... oh and, for that matter, the rest of the text lol.

@Joo200
Copy link
Author

Joo200 commented Apr 8, 2024

Why the rebase?

Force of habit

// <context.projectile> returns an EntityTag of the projectile.
// <context.shooter> returns a EntityTag of the shooter of the projectile.
// <context.hit_block> returns a LocationTag of the block.
// <context.hit_face> returns a LocationTag of the face.
Copy link
Member

Choose a reason for hiding this comment

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

These were copied from the projectile hits event, but cut short -- should probably just restore the full text from the other events docs into here


// <--[event]
// @Events
// targetblock hit
Copy link
Member

Choose a reason for hiding this comment

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

Event name should have a space (target block hit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants