Skip to content

Commit dc0e487

Browse files
authored
projectile launched: shooter support (#2701)
* - <context.shooter> added to "ProjectileLaunchedScriptEvent" - <context.entity> deprecated and replaced with <context.projectile> since there are technically multiple entities. * fixes * matcher removal * Aya update
1 parent 8b64f9c commit dc0e487

2 files changed

Lines changed: 31 additions & 26 deletions

File tree

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.denizenscript.denizen.events.entity;
22

33
import com.denizenscript.denizen.objects.EntityTag;
4-
import com.denizenscript.denizen.objects.LocationTag;
54
import com.denizenscript.denizen.events.BukkitScriptEvent;
5+
import com.denizenscript.denizen.objects.LocationTag;
6+
import com.denizenscript.denizen.utilities.BukkitImplDeprecations;
67
import com.denizenscript.denizencore.objects.ObjectTag;
78
import org.bukkit.entity.Entity;
89
import org.bukkit.event.EventHandler;
@@ -16,67 +17,68 @@ public class ProjectileLaunchedScriptEvent extends BukkitScriptEvent implements
1617
// projectile launched
1718
// <entity> launched
1819
//
19-
// @Regex ^on [^\s]+ launched$
20-
//
2120
// @Group Entity
2221
//
22+
// @Switch by:<entity> to only process the event if the projectile shooter matches the specified entity matcher.
23+
//
2324
// @Location true
2425
//
2526
// @Cancellable true
2627
//
2728
// @Triggers when a projectile is launched.
2829
//
2930
// @Context
30-
// <context.entity> returns the projectile.
31+
// <context.projectile> returns an EntityTag of the projectile.
32+
// <context.shooter> returns an EntityTag of the entity that shot the projectile, if any.
3133
//
3234
// -->
3335

3436
public ProjectileLaunchedScriptEvent() {
37+
registerCouldMatcher("<entity> launched");
38+
registerSwitches("by");
3539
}
3640

3741
public EntityTag projectile;
3842
private LocationTag location;
3943
public ProjectileLaunchEvent event;
44+
public EntityTag shooter;
4045

4146
@Override
42-
public boolean couldMatch(ScriptPath path) {
43-
if (!path.eventArgLowerAt(1).equals("launched")) {
44-
return false;
45-
}
46-
if (!couldMatchEntity(path.eventArgLowerAt(0))) {
47+
public boolean matches(ScriptPath path) {
48+
if (!runInCheck(path, location)) {
4749
return false;
4850
}
49-
return true;
50-
}
51-
52-
@Override
53-
public boolean matches(ScriptPath path) {
54-
String projTest = path.eventArgLowerAt(0);
55-
if (!projTest.equals("projectile") && !projectile.tryAdvancedMatcher(projTest, path.context)) {
51+
if (!path.tryArgObject(0, projectile)) {
5652
return false;
5753
}
58-
if (!runInCheck(path, location)) {
54+
if (!path.tryObjectSwitch("by", shooter)) {
5955
return false;
6056
}
6157
return super.matches(path);
6258
}
6359

6460
@Override
6561
public ObjectTag getContext(String name) {
66-
if (name.equals("entity")) {
67-
return projectile.getDenizenObject();
68-
}
69-
return super.getContext(name);
62+
return switch (name) {
63+
case "entity" -> {
64+
BukkitImplDeprecations.projectileLaunchedEntityContext.warn();
65+
yield projectile;
66+
}
67+
case "projectile" -> projectile;
68+
case "shooter" -> shooter.getDenizenObject();
69+
default -> super.getContext(name);
70+
};
7071
}
7172

7273
@EventHandler
7374
public void onProjectileLaunched(ProjectileLaunchEvent event) {
74-
Entity projectile = event.getEntity();
75-
EntityTag.rememberEntity(projectile);
76-
this.projectile = new EntityTag(projectile);
77-
location = new LocationTag(event.getEntity().getLocation());
75+
Entity entity = event.getEntity();
76+
EntityTag.rememberEntity(entity);
7877
this.event = event;
78+
projectile = new EntityTag(entity);
79+
location = projectile.getLocation();
80+
shooter = projectile.getShooter();
7981
fire(event);
80-
EntityTag.forgetEntity(projectile);
82+
EntityTag.forgetEntity(entity);
8183
}
8284
}

plugin/src/main/java/com/denizenscript/denizen/utilities/BukkitImplDeprecations.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ public class BukkitImplDeprecations {
449449
// Added 2025/01/04
450450
public static Warning playEffectSpecialDataListInput = new FutureWarning("playEffectSpecialDataListInput", "List input for the special_data argument in playeffect command is now deprecated. Please use a MapTag instead.");
451451

452+
// Added 2025/01/23
453+
public static Warning projectileLaunchedEntityContext = new FutureWarning("projectileLaunchedEntityContext", "'context.entity' in the 'projectile launched' event is deprecated in favor of 'context.projectile'.");
454+
452455
// ==================== PAST deprecations of things that are already gone but still have a warning left behind ====================
453456

454457
// Removed upstream 2023/10/29 without warning.

0 commit comments

Comments
 (0)