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

Add elytra boost event, firework type and firework syntaxes #5956

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ public void onEnable() {
try {
getAddonInstance().loadClasses("ch.njol.skript",
"conditions", "effects", "events", "expressions", "entity", "sections", "structures");
getAddonInstance().loadClasses("org.skriptlang.skript", "elements");
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
} catch (final Exception e) {
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
setEnabled(false);
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.bukkit.enchantments.EnchantmentOffer;
import org.bukkit.entity.Cat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Panda.Gene;
Expand Down Expand Up @@ -1365,14 +1366,14 @@ public String toVariableNameString(final CachedServerIcon o) {
}
}));
}

Classes.registerClass(new EnumClassInfo<>(FireworkEffect.Type.class, "fireworktype", "firework types")
.user("firework ?types?")
.name("Firework Type")
.description("The type of a <a href='#fireworkeffect'>fireworkeffect</a>.")
.since("2.4")
.documentationId("FireworkType"));

Classes.registerClass(new ClassInfo<>(FireworkEffect.class, "fireworkeffect")
.user("firework ?effects?")
.name("Firework Effect")
Expand Down Expand Up @@ -1409,7 +1410,15 @@ public String toVariableNameString(FireworkEffect effect) {
return "firework effect " + effect.toString();
}
}));


Classes.registerClass(new ClassInfo<>(Firework.class, "firework")
.user("fireworks?")
.name("Firework")
.description("Firework entity")
.defaultExpression(new EventValueExpression<>(Firework.class))
.since("INSERT VERSION")
.changer(DefaultChangers.nonLivingEntityChanger));

Classes.registerClass(new EnumClassInfo<>(Difficulty.class, "difficulty", "difficulties")
.user("difficult(y|ies)")
.name("Difficulty")
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.slot.InventorySlot;
import ch.njol.skript.util.slot.Slot;

import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;

import io.papermc.paper.event.entity.EntityMoveEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.event.player.PlayerStonecutterRecipeSelectEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerTradeEvent;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.FireworkEffect;
Expand Down Expand Up @@ -172,9 +176,6 @@
import org.bukkit.potion.PotionEffectType;
import org.eclipse.jdt.annotation.Nullable;

/**
* @author Peter Güttinger
*/
@SuppressWarnings("deprecation")
public final class BukkitEventValues {

Expand Down Expand Up @@ -1530,8 +1531,8 @@ public SpawnReason get(CreatureSpawnEvent e) {
EventValues.registerEventValue(FireworkExplodeEvent.class, Firework.class, new Getter<Firework, FireworkExplodeEvent>() {
@Override
@Nullable
public Firework get(FireworkExplodeEvent e) {
return e.getEntity();
public Firework get(FireworkExplodeEvent event) {
return event.getEntity();
}
}, 0);
EventValues.registerEventValue(FireworkExplodeEvent.class, FireworkEffect.class, new Getter<FireworkEffect, FireworkExplodeEvent>() {
Expand Down Expand Up @@ -1831,6 +1832,23 @@ public ItemStack get(InventoryMoveItemEvent event) {
}
}, EventValues.TIME_NOW);

if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent")) {
EventValues.registerEventValue(PlayerElytraBoostEvent.class, Firework.class, new Getter<Firework, PlayerElytraBoostEvent>() {
@Override
@Nullable
public Firework get(PlayerElytraBoostEvent event) {
return event.getFirework();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(PlayerElytraBoostEvent.class, ItemStack.class, new Getter<ItemStack, PlayerElytraBoostEvent>() {
@Override
@Nullable
public ItemStack get(PlayerElytraBoostEvent event) {
return event.getItemStack();
}
}, EventValues.TIME_NOW);
}

}

}
40 changes: 25 additions & 15 deletions src/main/java/ch/njol/skript/events/SimpleEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@
*/
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptEventHandler;
import ch.njol.skript.lang.util.SimpleEvent;

import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
import com.destroystokyo.paper.event.entity.EntityJumpEvent;
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
import com.destroystokyo.paper.event.player.PlayerReadyArrowEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;

import io.papermc.paper.event.player.PlayerDeepSleepEvent;
import io.papermc.paper.event.player.PlayerInventorySlotChangeEvent;
import io.papermc.paper.event.player.PlayerStopUsingItemEvent;
import io.papermc.paper.event.player.PlayerTradeEvent;

import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockFertilizeEvent;
Expand All @@ -35,9 +48,9 @@
import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.block.SpongeAbsorbEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
import org.bukkit.event.block.SpongeAbsorbEvent;
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
import org.bukkit.event.entity.CreeperPowerEvent;
import org.bukkit.event.entity.EntityBreakDoorEvent;
Expand Down Expand Up @@ -108,19 +121,6 @@
import org.spigotmc.event.entity.EntityDismountEvent;
import org.spigotmc.event.entity.EntityMountEvent;

import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import com.destroystokyo.paper.event.entity.EntityJumpEvent;
import io.papermc.paper.event.player.PlayerTradeEvent;
import ch.njol.skript.Skript;
import ch.njol.skript.SkriptEventHandler;
import ch.njol.skript.lang.util.SimpleEvent;

/**
* @author Peter Güttinger
*/
public class SimpleEvents {
static {
Skript.registerEvent("Can Build Check", SimpleEvent.class, BlockCanBuildEvent.class, "[block] can build check")
Expand Down Expand Up @@ -741,6 +741,16 @@ public class SimpleEvents {
)
.since("2.7");

if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent"))
Skript.registerEvent("Elytra Boost", SimpleEvent.class, PlayerElytraBoostEvent.class, "[player] elytra boost [(with|by) [a] firework]")
.description("Called when a player boosts elytra flight with a firework.")
.examples(
"on player elytra boost:",
"\tsend \"You boosted an elytra with a level %max life of event-firework% firework!\" to player"
)
.requiredPlugins("Paper")
.since("INSERT VERSION");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* 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 org.skriptlang.skript.elements.fireworks;

import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Condition;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;

@Name("Elytra Boost Will Consume")
@Description("Checks if the firework will be consumed in an <a href='events.html#elytra_boost'>elytra boost event</a>.")
@Examples({
"on player elytra boost:",
"\twill consume firework",
"\tset to consume the firework"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid example

})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class CondElytraBoostConsume extends Condition {

static {
if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent"))
Skript.registerCondition(CondElytraBoostConsume.class, "[event] (will [:not]|not:won't) consume [the] firework");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be forced to include what is consuming the firework:

"[the] (event|player) (will [:not]|not:won't) consume [the] firework"

}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (getParser().isCurrentEvent(PlayerElytraBoostEvent.class)) {
Skript.error("You can only use the 'will consume firework' condition in the 'on elytra boost' event!");
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
setNegated(parseResult.hasTag("not"));
return true;
}

@Override
public boolean check(Event event) {
if (!(event instanceof PlayerElytraBoostEvent))
return false;
return isNegated() && !((PlayerElytraBoostEvent) event).shouldConsume();
Comment on lines +65 to +67
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!(event instanceof PlayerElytraBoostEvent))
return false;
return isNegated() && !((PlayerElytraBoostEvent) event).shouldConsume();
if (event instanceof PlayerElytraBoostEvent)
return ((PlayerElytraBoostEvent) event).shouldConsume() ^ isNegated();
return false;

}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "will " + (isNegated() ? " not " : "") + "consume the firework";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* 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 org.skriptlang.skript.elements.fireworks;

import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import com.destroystokyo.paper.event.player.PlayerElytraBoostEvent;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;

@Name("Elytra Boost Consume")
@Description("Change if the firework will be consumed in an <a href='events.html#elytra_boost'>elytra boost event</a>.")
@Examples({
"on player elytra boost:",
"\twill consume firework",
"\tset to consume the firework"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid example

})
@RequiredPlugins("Paper")
@Since("INSERT VERSION")
public class EffElytraBoostConsume extends Effect {

static {
if (Skript.classExists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent"))
Skript.registerEffect(EffElytraBoostConsume.class, "[not:do not] consume firework", "set consum(e|ption of) firework to %boolean%");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set consume of firework shouldn't be allowed.
also, what do you think about [un]cancel consumption of [the] firework or something similar?

}

@Nullable
private Expression<Boolean> expression;
private boolean consume;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (getParser().isCurrentEvent(PlayerElytraBoostEvent.class)) {
Skript.error("You can only use the 'consume firework' effect in the 'on elytra boost' event!");
TheLimeGlass marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
if (matchedPattern == 1) {
expression = (Expression<Boolean>) exprs[0];
} else {
consume = !parseResult.hasTag("not");
}
return true;
}

@Override
protected void execute(Event event) {
if (!(event instanceof PlayerElytraBoostEvent))
return;
PlayerElytraBoostEvent elytraBoostEvent = (PlayerElytraBoostEvent) event;
if (expression != null) {
Boolean consume = expression.getSingle(event);
if (consume == null)
return;
elytraBoostEvent.setShouldConsume(consume);
} else {
elytraBoostEvent.setShouldConsume(consume);
}
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return expression == null ? (consume ? "consume" : "do not consume") + " firework" : "set consume firework to " + expression.toString(event, debug);
}

}
Loading
Loading