Skip to content

Commit

Permalink
EffSecShoot (#7136)
Browse files Browse the repository at this point in the history
* Starter Commit

* ExprShooter Update

* Enhance Consumer

* Cleanup + Tests

* Requested Changes - 1

* Requested Changes - 2

* Fix ExprShooter

* Fix Test

* Update ExprShooter

* Efy Changes

* Suppres Change

* Consumer var

* Fix 1.19 LivingEntity#launchProjectile

* Changes

* Requested Changes

* Reduce Nesting

* Requested Changes

* Fix

* docs

---------

Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: Efnilite <35348263+Efnilite@users.noreply.github.com>
Co-authored-by: Moderocky <admin@moderocky.com>
  • Loading branch information
4 people authored Dec 24, 2024
1 parent 192c134 commit 084bc7f
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 138 deletions.
120 changes: 0 additions & 120 deletions src/main/java/ch/njol/skript/effects/EffShoot.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.lang.reflect.Array;

import ch.njol.skript.effects.EffFireworkLaunch;
import ch.njol.skript.sections.EffSecShoot;
import ch.njol.skript.sections.EffSecSpawn;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
Expand All @@ -19,7 +19,6 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.effects.EffDrop;
import ch.njol.skript.effects.EffLightning;
import ch.njol.skript.effects.EffShoot;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
Expand Down Expand Up @@ -82,7 +81,7 @@ protected Entity[] get(Event event) {
en = EffSecSpawn.lastSpawned;
break;
case 1:
en = EffShoot.lastSpawned;
en = EffSecShoot.lastSpawned;
break;
case 2:
en = EffDrop.lastSpawned;
Expand Down
35 changes: 20 additions & 15 deletions src/main/java/ch/njol/skript/expressions/ExprShooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.sections.EffSecShoot;
import ch.njol.util.Kleenean;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
Expand All @@ -28,42 +29,46 @@ public class ExprShooter extends PropertyExpression<Projectile, LivingEntity> {
static {
Skript.registerExpression(ExprShooter.class, LivingEntity.class, ExpressionType.SIMPLE, "[the] shooter [of %projectile%]");
}

@SuppressWarnings({"unchecked", "null"})

@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
setExpr((Expression<? extends Projectile>) exprs[0]);
return true;
}

@Override
protected LivingEntity[] get(final Event e, final Projectile[] source) {
protected LivingEntity @Nullable [] get(Event event, Projectile[] source) {
if (event instanceof EffSecShoot.ShootEvent shootEvent && getExpr().isDefault() && !(shootEvent.getProjectile() instanceof Projectile)) {
return new LivingEntity[]{shootEvent.getShooter()};
}

return get(source, projectile -> {
Object shooter = projectile != null ? projectile.getShooter() : null;
if (shooter instanceof LivingEntity)
return (LivingEntity) shooter;
if (shooter instanceof LivingEntity livingShooter)
return livingShooter;
return null;
});
}

@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
public @Nullable Class<?>[] acceptChange(ChangeMode mode) {
if (mode == ChangeMode.SET)
return new Class[] {LivingEntity.class};
return super.acceptChange(mode);
}

@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
if (mode == ChangeMode.SET) {
assert delta != null;
for (final Projectile p : getExpr().getArray(e)) {
assert p != null : getExpr();
p.setShooter((ProjectileSource) delta[0]);
ProjectileSource source = (ProjectileSource) delta[0];
for (Projectile projectile : getExpr().getArray(event)) {
assert projectile != null : getExpr();
projectile.setShooter(source);
}
} else {
super.change(e, delta, mode);
super.change(event, delta, mode);
}
}

Expand All @@ -73,8 +78,8 @@ public Class<LivingEntity> getReturnType() {
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "the shooter" + (getExpr().isDefault() ? "" : " of " + getExpr().toString(e, debug));
public String toString(@Nullable Event event, boolean debug) {
return "the shooter" + (getExpr().isDefault() ? "" : " of " + getExpr().toString(event, debug));
}

}
Loading

0 comments on commit 084bc7f

Please sign in to comment.