-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Knockback #2094
Changes from 4 commits
5d695dd
b90fec9
0d9b374
0872a77
c6fcd00
a7fd1fb
648c987
d5f08e3
3c1ebe6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.denizenscript.denizen.paper.events; | ||
|
||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizen.objects.ItemTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
import com.denizenscript.denizencore.scripts.containers.ScriptContainer; | ||
import com.denizenscript.denizencore.utilities.CoreUtilities; | ||
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.util.Vector; | ||
|
||
public class EntityKnockbackByEntityScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// entity knocks back entity | ||
// entity knocks back <entity> | ||
// <entity> knocks back entity | ||
// <entity> knocks back <entity> | ||
// | ||
// @Regex ^on [^\s]+ knocks back [^\s]+$ | ||
// | ||
// @Switch in:<area> to only process the event if it occurred within a specified area. | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the blank line separating two switches |
||
// @Switch with:<item> to only process the event when the item used to cause damage (in the damager's hand) is a specified item. | ||
// | ||
// @Plugin Paper | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when an entity is knocked back from the hit of another entity. | ||
// | ||
// @Context | ||
// <context.entity> returns the EntityTag that was knocked back. | ||
// <context.attacker> returns the EntityTag of the one who knocked. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
// <context.acceleration> returns the knockback applied as a vector. | ||
// | ||
// @Player when the damager or damaged entity is a player. Cannot be both. | ||
// | ||
// @NPC when the damager or damaged entity is an NPC. Cannot be both. | ||
// | ||
// --> | ||
|
||
public EntityKnockbackByEntityScriptEvent() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
instance = this; | ||
} | ||
|
||
public static EntityKnockbackByEntityScriptEvent instance; | ||
|
||
public EntityTag entity; | ||
public EntityTag hitBy; | ||
public ItemTag held; | ||
public LocationTag acceleration; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
public EntityKnockbackByEntityEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
String lower = CoreUtilities.toLowerCase(s); | ||
return CoreUtilities.getXthArg(1, lower).equals("knocks") && | ||
CoreUtilities.getXthArg(2, lower).equals("back"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
String attacker = path.eventArgLowerAt(0); | ||
String target = path.eventArgLowerAt(3); | ||
|
||
if (!tryEntity(hitBy, attacker) || (!tryEntity(entity, target))) { | ||
return false; | ||
} | ||
|
||
if (!runInCheck(path, entity.getLocation())) { | ||
return false; | ||
} | ||
|
||
if (!runWithCheck(path, held)) { | ||
return false; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of stray newlines here, should all be removed (within this method) |
||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityKnocksbackEntityEvent"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The word |
||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
if (determinationObj instanceof LocationTag) { | ||
acceleration = new LocationTag(((LocationTag) determinationObj).toVector()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return true; | ||
} | ||
return super.applyDetermination(path, determinationObj); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData( | ||
hitBy.isPlayer() ? hitBy.getDenizenPlayer() : | ||
(entity.isPlayer() ? entity.getDenizenPlayer() : null), | ||
|
||
hitBy.isCitizensNPC() ? hitBy.getDenizenNPC() : | ||
(entity.isCitizensNPC() ? EntityTag.getNPCFrom(event.getHitBy()) : null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("entity")) { | ||
return entity.getDenizenObject(); | ||
} | ||
else if (name.equals("attacker")) { | ||
return hitBy.getDenizenObject(); | ||
} | ||
return super.getContext(name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You forgot to implement |
||
} | ||
|
||
@EventHandler | ||
public void onEntityKnockbackEntity(EntityKnockbackByEntityEvent event) { | ||
entity = new EntityTag(event.getEntity()); | ||
hitBy = new EntityTag(event.getHitBy()); | ||
acceleration = new LocationTag(event.getAcceleration()); | ||
held = hitBy.getItemInHand(); | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
There was a problem hiding this comment.
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