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

Added Firework Launch Effect Section and removed Firework Launch effect. #4793

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
be31180
Added Firework Launch Effect Section and removed Firework Launch effect.
TFSMads Jun 9, 2022
e90f26e
Merge branch 'master' into feature/laucnhEffSec
TFSMads Jun 9, 2022
08c9164
Update src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
TFSMads Jun 9, 2022
2c89cba
Update src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
TFSMads Jun 9, 2022
ef7885b
Update src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
TFSMads Jun 10, 2022
50e0a26
Update src/test/skript/tests/syntaxes/sections/EffSecFireworkLaunch.sk
TFSMads Jun 10, 2022
d3bf799
Update src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
TFSMads Jun 10, 2022
33d8f6a
Update EffSecFireworkLaunch.java
TFSMads Jun 10, 2022
99be168
Update EffSecFireworkLaunch.java
TFSMads Jun 10, 2022
ae10ac5
Merge branch 'master' into feature/laucnhEffSec
TFSMads Jun 10, 2022
b13ad8c
Merge branch 'master' into feature/laucnhEffSec
TheLimeGlass Jun 30, 2022
9b189d6
Changed from %number% to %-number%
TFSMads Jul 14, 2022
6dc151c
Update EffSecFireworkLaunch.java
TFSMads Jul 14, 2022
6235d08
Update src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
TFSMads Jul 14, 2022
6f0157d
Update src/test/skript/tests/syntaxes/sections/EffSecFireworkLaunch.sk
TFSMads Jul 14, 2022
c46239a
Merge branch 'master' into feature/laucnhEffSec
TFSMads Jul 14, 2022
6157d51
Update src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
TFSMads Jul 15, 2022
456282a
Update src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
TFSMads Jul 15, 2022
8fc13c0
Update EffSecFireworkLaunch.java
TFSMads Jul 15, 2022
242717b
Check if varibles from section is carried over to the initial section
TFSMads Jul 15, 2022
ff2a955
Added requested changes:
TFSMads Jul 18, 2022
a4d5d81
Merge branch 'master' into feature/laucnhEffSec
TFSMads Jul 18, 2022
251c06e
Apply suggestions from code review
TFSMads Jul 28, 2022
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
85 changes: 0 additions & 85 deletions src/main/java/ch/njol/skript/effects/EffFireworkLaunch.java

This file was deleted.

166 changes: 166 additions & 0 deletions src/main/java/ch/njol/skript/sections/EffSecFireworkLaunch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* 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.sections;

import ch.njol.skript.Skript;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.EffectSection;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.Trigger;
import ch.njol.skript.lang.TriggerItem;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Getter;
import ch.njol.skript.variables.Variables;
import ch.njol.util.Kleenean;
import org.bukkit.FireworkEffect;
import org.bukkit.Location;
import org.bukkit.entity.Firework;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.util.Consumer;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.List;

@Name("Launch Firework")
@Description({"Launch firework effects at the given location(s).",
"This can be used as an effect and as a section.",
"If it is used as a section, the section is run before the entity is added to the world.",
"You can modify the firework in this section, using for example 'event-entity' or 'event-firework'.",
"Do note that other event values, such as 'player', won't work in this section."})
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
@Examples({"launch ball large coloured red, purple and white fading to light green and black at player's location with duration 1",
"",
"#Firework launch section example",
"on damage:",
"\tif damage cause is entity explosion:",
"\t\tif metadata value \"cancelDamage\" of event-projectile is true:",
"\t\t\tcancel event",
"",
"command /firework:",
"\ttrigger:",
"\t\tlaunch a firework with effects ball large coloured red at player:",
"\t\t\tset metadata value \"cancelDamage\" of event-firework to true"})
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
@Since("2.4, INSERT VERSION (with section)")
public class EffSecFireworkLaunch extends EffectSection {

public static class FireworkLaunchEvent extends Event {
private final Firework firework;
TFSMads marked this conversation as resolved.
Show resolved Hide resolved

public FireworkLaunchEvent(Firework firework) {
this.firework = firework;
}

public Firework getFirework() {
return firework;
}

@Override
public HandlerList getHandlers() {
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalStateException();
}
}
TFSMads marked this conversation as resolved.
Show resolved Hide resolved

static {
Skript.registerSection(EffSecFireworkLaunch.class, "(launch|deploy) [[a] firework [with effect[s]]] %fireworkeffects% at %locations% [([with] (duration|power)|timed) %-number%]");
EventValues.registerEventValue(FireworkLaunchEvent.class, Firework.class, new Getter<Firework, FireworkLaunchEvent>() {
@Override
public Firework get(FireworkLaunchEvent fireworkLaunchEvent) {
return fireworkLaunchEvent.getFirework();
}
}, 0);
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
}

@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<FireworkEffect> effects;
@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<Location> locations;
@Nullable
@SuppressWarnings("NotNullFieldNotInitialized")
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
private Expression<Number> lifetime;

@Nullable
private Trigger trigger;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs,
int matchedPattern,
Kleenean isDelayed,
SkriptParser.ParseResult parseResult,
@Nullable SectionNode sectionNode,
@Nullable List<TriggerItem> triggerItems) {
effects = (Expression<FireworkEffect>) exprs[0];
locations = (Expression<Location>) exprs[1];
lifetime = (Expression<Number>) exprs[2];

if (sectionNode != null) {
trigger = loadCode(sectionNode, "fireworklaunch", FireworkLaunchEvent.class);
}
TFSMads marked this conversation as resolved.
Show resolved Hide resolved

return true;
}

@Override
@Nullable
@SuppressWarnings({"unchecked", "rawtypes"})
protected TriggerItem walk(Event e) {
Object localVars = Variables.copyLocalVariables(e);

Consumer<? extends Firework> consumer;
if (trigger != null) {
consumer = o -> {
FireworkLaunchEvent fireworkLaunchEvent = new FireworkLaunchEvent(o);
// Copy the local variables from the calling code to this section
Variables.setLocalVariables(fireworkLaunchEvent, localVars);
trigger.execute(fireworkLaunchEvent);
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
};
} else {
consumer = null;
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
}

Number power = lifetime.getSingle(e);
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
if (power == null)
power = 1;
for (Location location : locations.getArray(e)) {
Firework firework = location.getWorld().spawn(location, Firework.class, (Consumer) consumer);
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
FireworkMeta meta = firework.getFireworkMeta();
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
meta.addEffects(effects.getArray(e));
meta.setPower(power.intValue());
firework.setFireworkMeta(meta);
}

return super.walk(e, false);
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "Launch firework(s) " + effects.toString(e, debug) +
" at location(s) " + locations.toString(e, debug) +
" timed " + lifetime.toString(e, debug);
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
}
TFSMads marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test "firework launch section" when running minecraft "1.11":
TFSMads marked this conversation as resolved.
Show resolved Hide resolved
set {_foo} to true
launch a firework with effects ball large coloured red at spawn of "world":
assert {_foo} is true with "variables from previous section wasn't carried over"
assert event-entity is a firework with "entity should be a firework but is %event-entity%"
assert location of event-entity is set with "location of firework is not set"
set metadata value "test" of event-entity to true
assert metadata value "test" of event-entity is true with "metadata value not true (check from section)"