Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EffSecShoot #7136

Open
wants to merge 21 commits into
base: dev/feature
Choose a base branch
from
Open
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
138 changes: 0 additions & 138 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 @@ -21,8 +21,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 @@ -37,7 +37,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 @@ -100,7 +99,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
52 changes: 19 additions & 33 deletions src/main/java/ch/njol/skript/expressions/ExprShooter.java
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.expressions;

import ch.njol.skript.Skript;
Expand All @@ -28,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 @@ -46,42 +29,45 @@ 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]);
for (Projectile projectile : getExpr().getArray(event)) {
assert projectile != null : getExpr();
TheAbsolutionism marked this conversation as resolved.
Show resolved Hide resolved
projectile.setShooter((ProjectileSource) delta[0]);
}
} else {
super.change(e, delta, mode);
super.change(event, delta, mode);
}
}

Expand All @@ -91,8 +77,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