Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fish hook tags/mecs and expand projectile hit event for hooking e…
…ntities (#2278) * Add fish hook tags/mecs and expand projectile hit event for hooking entities * Add cancellable tag on projectile hit events * Split projectile event into separate classes, fix 1.17 lure time
- Loading branch information
Showing
7 changed files
with
380 additions
and
9 deletions.
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
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
125 changes: 125 additions & 0 deletions
125
...rc/main/java/com/denizenscript/denizen/events/entity/ProjectileHitsEntityScriptEvent.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,125 @@ | ||
package com.denizenscript.denizen.events.entity; | ||
|
||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizen.objects.LocationTag; | ||
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; | ||
import com.denizenscript.denizen.events.BukkitScriptEvent; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.scripts.ScriptEntryData; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.ProjectileHitEvent; | ||
|
||
public class ProjectileHitsEntityScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// projectile hits entity | ||
// projectile hits <entity> | ||
// <projectile> hits entity | ||
// <projectile> hits <entity> | ||
// | ||
// @Switch shooter:<entity> | ||
// | ||
// @Regex ^on [^\s]+ hits [^\s]+$ | ||
// | ||
// @Group Entity | ||
// | ||
// @Location true | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a projectile hits an entity or a fish hook latches onto an entity. | ||
// | ||
// @Context | ||
// <context.projectile> returns the EntityTag of the projectile. | ||
// <context.shooter> returns the EntityTag of the shooter, if there is one. | ||
// <context.hit_entity> returns the EntityTag of the entity that was hit. | ||
// | ||
// @Player when the entity that was hit is a player. | ||
// | ||
// @NPC when the entity that was hit is an NPC. | ||
// | ||
// --> | ||
public ProjectileHitsEntityScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static ProjectileHitsEntityScriptEvent instance; | ||
public EntityTag projectile; | ||
public EntityTag shooter; | ||
public EntityTag hitEntity; | ||
public LocationTag location; | ||
public ProjectileHitEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptPath path) { | ||
String cmd = path.eventArgLowerAt(1); | ||
if (!cmd.equals("hits") && !cmd.equals("shoots")) { | ||
return false; | ||
} | ||
if (!couldMatchEntity(path.eventArgLowerAt(0))) { | ||
return false; | ||
} | ||
if (!couldMatchEntity(path.eventArgLowerAt(2))) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptPath path) { | ||
if (!tryEntity(projectile, path.eventArgLowerAt(0))) { | ||
return false; | ||
} | ||
if (!tryEntity(hitEntity, path.eventArgLowerAt(2))) { | ||
return false; | ||
} | ||
if (path.switches.containsKey("shooter") && !tryEntity(shooter, path.switches.get("shooter"))) { | ||
return false; | ||
} | ||
if (!runInCheck(path, location)) { | ||
return false; | ||
} | ||
return super.matches(path); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ProjectileHitsEntity"; | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(hitEntity); | ||
} | ||
|
||
@Override | ||
public ObjectTag getContext(String name) { | ||
if (name.equals("projectile")) { | ||
return projectile.getDenizenObject(); | ||
} | ||
else if (name.equals("hit_entity")) { | ||
return hitEntity.getDenizenObject(); | ||
} | ||
else if (name.equals("shooter") && shooter != null) { | ||
return shooter.getDenizenObject(); | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onProjectileHits(ProjectileHitEvent event) { | ||
Entity entity = event.getHitEntity(); | ||
if (entity == null) { | ||
return; | ||
} | ||
projectile = new EntityTag(event.getEntity()); | ||
shooter = projectile.getShooter(); | ||
hitEntity = new EntityTag(entity); | ||
location = hitEntity.getLocation(); | ||
this.event = event; | ||
fire(event); | ||
} | ||
} |
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
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
Oops, something went wrong.