Skip to content
Merged
Show file tree
Hide file tree
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
@@ -1,8 +1,9 @@
package com.denizenscript.denizen.events.entity;

import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.utilities.BukkitImplDeprecations;
import com.denizenscript.denizencore.objects.ObjectTag;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
Expand All @@ -16,67 +17,68 @@ public class ProjectileLaunchedScriptEvent extends BukkitScriptEvent implements
// projectile launched
// <entity> launched
//
// @Regex ^on [^\s]+ launched$
//
// @Group Entity
//
// @Switch by:<entity> to only process the event if the projectile shooter matches the specified entity matcher.
//
// @Location true
//
// @Cancellable true
//
// @Triggers when a projectile is launched.
//
// @Context
// <context.entity> returns the projectile.
// <context.projectile> returns an EntityTag of the projectile.
// <context.shooter> returns an EntityTag of the entity that shot the projectile, if any.
//
// -->

public ProjectileLaunchedScriptEvent() {
registerCouldMatcher("<entity> launched");
registerSwitches("by");
}

public EntityTag projectile;
private LocationTag location;
public ProjectileLaunchEvent event;
public EntityTag shooter;

@Override
public boolean couldMatch(ScriptPath path) {
if (!path.eventArgLowerAt(1).equals("launched")) {
return false;
}
if (!couldMatchEntity(path.eventArgLowerAt(0))) {
public boolean matches(ScriptPath path) {
if (!runInCheck(path, location)) {
return false;
}
return true;
}

@Override
public boolean matches(ScriptPath path) {
String projTest = path.eventArgLowerAt(0);
if (!projTest.equals("projectile") && !projectile.tryAdvancedMatcher(projTest, path.context)) {
if (!path.tryArgObject(0, projectile)) {
return false;
}
if (!runInCheck(path, location)) {
if (!path.tryObjectSwitch("by", shooter)) {
return false;
}
return super.matches(path);
}

@Override
public ObjectTag getContext(String name) {
if (name.equals("entity")) {
return projectile.getDenizenObject();
}
return super.getContext(name);
return switch (name) {
case "entity" -> {
BukkitImplDeprecations.projectileLaunchedEntityContext.warn();
yield projectile;
}
case "projectile" -> projectile;
case "shooter" -> shooter.getDenizenObject();
default -> super.getContext(name);
};
}

@EventHandler
public void onProjectileLaunched(ProjectileLaunchEvent event) {
Entity projectile = event.getEntity();
EntityTag.rememberEntity(projectile);
Comment thread
mcmonkey4eva marked this conversation as resolved.
this.projectile = new EntityTag(projectile);
location = new LocationTag(event.getEntity().getLocation());
Entity entity = event.getEntity();
EntityTag.rememberEntity(entity);
this.event = event;
projectile = new EntityTag(entity);
location = projectile.getLocation();
shooter = projectile.getShooter();
fire(event);
EntityTag.forgetEntity(projectile);
EntityTag.forgetEntity(entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ public class BukkitImplDeprecations {
// Added 2025/01/04
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.");

// Added 2025/01/23
public static Warning projectileLaunchedEntityContext = new FutureWarning("projectileLaunchedEntityContext", "'context.entity' in the 'projectile launched' event is deprecated in favor of 'context.projectile'.");

// ==================== PAST deprecations of things that are already gone but still have a warning left behind ====================

// Removed upstream 2023/10/29 without warning.
Expand Down