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

Knockback #2094

Merged
merged 9 commits into from Dec 21, 2019
Merged

Knockback #2094

merged 9 commits into from Dec 21, 2019

Conversation

Ph4i1ur3
Copy link
Contributor

Adds Paper only knockback event

import org.bukkit.event.Listener;
import org.bukkit.util.Vector;

public class EntityKnockbackByEntityScriptEvent 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.

Stray doublespace ^
You should enable automatic formatting in IntelliJ btw, helps with this stuff

// @Regex ^on [^\s]+ knocks back [^\s]+$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
//
Copy link
Member

Choose a reason for hiding this comment

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

Remove the blank line separating two switches

//
// @Context
// <context.entity> returns the EntityTag that was knocked back.
// <context.attacker> returns the EntityTag of the one who knocked.
Copy link
Member

Choose a reason for hiding this comment

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

This should be damager, to align with existing events

else if (name.equals("attacker")) {
return hitBy.getDenizenObject();
}
return super.getContext(name);
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to implement acceleration context

(entity.isPlayer() ? entity.getDenizenPlayer() : null),

hitBy.isCitizensNPC() ? hitBy.getDenizenNPC() :
(entity.isCitizensNPC() ? EntityTag.getNPCFrom(event.getHitBy()) : null)
Copy link
Member

Choose a reason for hiding this comment

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

This was a mistake in existing events you referenced, please apply a matching correction to it a49f134

EDIT: Actually you used the wrong entity anyway, so the line still does contain a mistake on your own part

public EntityKnockbackByEntityEvent event;

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
Copy link
Member

Choose a reason for hiding this comment

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

You referenced existing entity events for this. Existing entity events have not yet been updated to a new method that all other events have. Please use the new (ScriptPath path) method

public EntityTag entity;
public EntityTag hitBy;
public ItemTag held;
public LocationTag acceleration;
Copy link
Member

Choose a reason for hiding this comment

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

This value has no reason to be tracked as a field - reference any of the semi-recent event cleanup commits, such as here: 86682fc#diff-3adfbdf9af2fb8177b5756a6594aafaaL50

if (!runWithCheck(path, held)) {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

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

Lots of stray newlines here, should all be removed (within this method)

//
// -->

public EntityKnockbackByEntityScriptEvent() {
Copy link
Member

Choose a reason for hiding this comment

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

The class name should probably be closer to the Denizen name, not an odd copy of the underlying Paper name. EntityKnocksbackEntityScriptEvent


@Override
public String getName() {
return "EntityKnocksbackEntityEvent";
Copy link
Member

Choose a reason for hiding this comment

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

The word Event should not appear here

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof LocationTag) {
acceleration = new LocationTag(((LocationTag) determinationObj).toVector());
Copy link
Member

Choose a reason for hiding this comment

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

As you mentioned you were aware of on Discord, this line doesn't actually do anything. This will be naturally fixed by the field removal I mentioned above

public EntityKnockbackByEntityEvent event;

@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
Copy link
Member

Choose a reason for hiding this comment

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

Original issue here still not corrected

if (!runWithCheck(path, held)) {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

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

Original issue here still not resolved


@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof LocationTag) {
Copy link
Member

Choose a reason for hiding this comment

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

Not a reliable check, the object is not guaranteed to be of the expected type when fed in, LocationTag.matches + valueOf are required.
Also, !isDefaultDetermination

public ObjectTag getContext(String name) {
if (name.equals("entity")) {
return entity.getDenizenObject();
} else if (name.equals("damager")) {
Copy link
Member

Choose a reason for hiding this comment

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

newline between } and else, not on the same line.

@Ph4i1ur3
Copy link
Contributor Author

Ok, I think I got it this time!

public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
if (!isDefaultDetermination(determinationObj)) {
if (determinationObj instanceof LocationTag && LocationTag.matches(determination)) {
Copy link
Member

Choose a reason for hiding this comment

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

Nope. ||. If it's already a LocationTag or it can become a LocationTag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhhh! I get it now!


@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
String determination = determinationObj.toString();
Copy link
Member

Choose a reason for hiding this comment

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

Goes inside the if, not outside it (only used inside)

String determination = determinationObj.toString();
if (!isDefaultDetermination(determinationObj)) {
if (determinationObj instanceof LocationTag && LocationTag.matches(determination)) {
event.getAcceleration().copy(((LocationTag) determinationObj).toVector());
Copy link
Member

Choose a reason for hiding this comment

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

need a valueOf, at least if instanceOf failed and matches passed instead.

Alternately you could remove the instanceOf and only do matches + valueOf (would be cleaner tbh)

@Ph4i1ur3
Copy link
Contributor Author

AM fixes applied....

@@ -15,6 +15,7 @@ public static void init() {
ScriptEvent.registerScriptEvent(new PlayerEquipsArmorScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerJumpsPaperScriptEventImpl());
ScriptEvent.registerScriptEvent(new PlayerSpectatesEntityScriptEvent());
ScriptEvent.registerScriptEvent(new EntityKnocksbackEntityScriptEvent());
Copy link
Member

Choose a reason for hiding this comment

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

This list should be alphabetized (just look at the order of events in your IntelliJ class listing)

@Ph4i1ur3
Copy link
Contributor Author

Fixed

return new BukkitScriptEntryData(
hitBy.isPlayer() ? hitBy.getDenizenPlayer() :
(entity.isPlayer() ? entity.getDenizenPlayer() : null),

Copy link
Member

Choose a reason for hiding this comment

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

Stray doublenewline ^
Also the newlines on the individual parts

I'm confused why this isn't formatted exactly the same as the EntityDamaged event, which I think is what you were referencing anyway?

        return new BukkitScriptEntryData(damager != null && damager.isPlayer() ? damager.getDenizenPlayer() : entity.isPlayer() ? entity.getDenizenPlayer() : null,
                damager != null && damager.isCitizensNPC() ? damager.getDenizenNPC() : entity.isCitizensNPC() ? entity.getDenizenNPC() : null);

@mcmonkey4eva mcmonkey4eva merged commit a31eabd into DenizenScript:dev Dec 21, 2019
@mcmonkey4eva
Copy link
Member

:D

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

2 participants