-
-
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
Merged
Merged
Knockback #2094
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d695dd
Implements Paper only knockback event
Ph4i1ur3 b90fec9
fix typo (1.14->1.15)
Ph4i1ur3 0d9b374
small cleanup
Ph4i1ur3 0872a77
Merge branch 'dev' of https://github.com/DenizenScript/Denizen into k…
Ph4i1ur3 c6fcd00
fixes!
Ph4i1ur3 a7fd1fb
Moar Fix!
Ph4i1ur3 648c987
first thing in the morning fixes.....
Ph4i1ur3 d5f08e3
learned the alphabet since the last update
Ph4i1ur3 3c1ebe6
more fix
Ph4i1ur3 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...c/main/java/com/denizenscript/denizen/paper/events/EntityKnocksbackEntityScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
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; | ||
|
||
public class EntityKnocksbackEntityScriptEvent 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. | ||
// @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.damager> returns the EntityTag of the one who knocked. | ||
// <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 EntityKnocksbackEntityScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static EntityKnocksbackEntityScriptEvent instance; | ||
|
||
public EntityTag entity; | ||
public EntityTag hitBy; | ||
public ItemTag held; | ||
public EntityKnockbackByEntityEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
return path.eventArgLowerAt(1).equals("knocks") && | ||
path.eventArgLowerAt(2).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; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "EntityKnocksbackEntity"; | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) { | ||
if (!isDefaultDetermination(determinationObj)) { | ||
String determination = determinationObj.toString(); | ||
if (LocationTag.matches(determination)) { | ||
event.getAcceleration().copy((LocationTag.valueOf(determination)).toVector()); | ||
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() ? entity.getDenizenNPC() : null) | ||
); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("entity")) { | ||
return entity.getDenizenObject(); | ||
} | ||
else if (name.equals("damager")) { | ||
return hitBy.getDenizenObject(); | ||
} | ||
else if (name.equals("acceleration")) { | ||
return new LocationTag(event.getAcceleration()); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onEntityKnockbackEntity(EntityKnockbackByEntityEvent event) { | ||
entity = new EntityTag(event.getEntity()); | ||
hitBy = new EntityTag(event.getHitBy()); | ||
held = hitBy.getItemInHand(); | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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?