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

EntityKnocksbackEntityScriptEvent <context.cause> added #2697

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
Expand All @@ -19,6 +20,8 @@ public class EntityKnocksbackEntityScriptEvent extends BukkitScriptEvent impleme
//
// @Location true
//
// @Warning this event may in some cases double-fire, requiring usage of the 'ratelimit' command (like 'ratelimit <player> 1t') to prevent doubling actions.
//
// @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
Expand All @@ -33,6 +36,7 @@ public class EntityKnocksbackEntityScriptEvent extends BukkitScriptEvent impleme
// <context.entity> returns the EntityTag that was knocked back.
// <context.damager> returns the EntityTag of the one who knocked.
// <context.acceleration> returns the knockback applied as a vector.
// <context.cause> returns the cause of the knockback (only on 1.20+). Causes list: <@link url https://jd.papermc.io/paper/1.21.1/io/papermc/paper/event/entity/EntityKnockbackEvent.Cause.html>
//
// @Determine
// LocationTag as a vector to change the acceleration applied.
Expand Down Expand Up @@ -88,15 +92,13 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
switch (name) {
case "entity":
return entity.getDenizenObject();
case "damager":
return hitBy.getDenizenObject();
case "acceleration":
return new LocationTag(event.getAcceleration());
}
return super.getContext(name);
return switch (name) {
case "entity" -> entity.getDenizenObject();
case "damager" -> hitBy.getDenizenObject();
case "acceleration" -> new LocationTag(event.getAcceleration());
case "cause" -> new ElementTag(event.getCause());
default -> super.getContext(name);
};
}

@EventHandler
Expand Down