Skip to content

Commit

Permalink
entity shoots block hackevent: move 'with' to a switch
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 15, 2020
1 parent 3694a59 commit a46b38b
Showing 1 changed file with 7 additions and 8 deletions.
Expand Up @@ -40,9 +40,11 @@ public class ProjectileHitsScriptEvent extends BukkitScriptEvent implements List
// <--[event]
// @Events
// entity shoots block
// entity shoots <material> (with <projectile>)
// entity shoots <material>
// <entity> shoots block
// <entity> shoots <material> (with <projectile>)
// <entity> shoots <material>
//
// @Switch with:<projectile>
//
// @Regex ^on [^\s]+ shoots [^\s]+$
//
Expand Down Expand Up @@ -86,7 +88,6 @@ public boolean couldMatch(ScriptPath path) {
public boolean matches(ScriptPath path) {
String cmd = path.eventArgLowerAt(1);
String pTest = "";

if (cmd.equals("hits")) {
pTest = path.eventArgLowerAt(0);
}
Expand All @@ -101,11 +102,12 @@ else if (cmd.equals("shoots")) {
if (!pTest.isEmpty() && !pTest.equals("projectile") && !tryEntity(projectile, pTest)) {
return false;
}

if (path.switches.containsKey("with") && !tryEntity(projectile, path.switches.get("with"))) {
return false;
}
if (!tryMaterial(material, path.eventArgLowerAt(2))) {
return false;
}

if (!runInCheck(path, location)) {
return false;
}
Expand Down Expand Up @@ -146,13 +148,10 @@ public void onProjectileHits(ProjectileHitEvent event) {
if (projectile.getLocation() == null) {
return; // No, I can't explain how or why this would ever happen... nonetheless, it appears it does happen sometimes.
}

if (Double.isNaN(projectile.getLocation().getDirection().normalize().getX())) {
return; // I can't explain this one either. It also chooses to happen whenever it pleases.
}

Block block = event.getHitBlock();

if (block == null) {
return;
}
Expand Down

0 comments on commit a46b38b

Please sign in to comment.