diff --git a/src/main/java/com/shanebeestudios/skbee/elements/other/type/Types.java b/src/main/java/com/shanebeestudios/skbee/elements/other/type/Types.java index cf60ce4d..8485a8c9 100644 --- a/src/main/java/com/shanebeestudios/skbee/elements/other/type/Types.java +++ b/src/main/java/com/shanebeestudios/skbee/elements/other/type/Types.java @@ -12,15 +12,16 @@ import ch.njol.util.StringUtils; import ch.njol.yggdrasil.Fields; import com.shanebeestudios.skbee.api.registration.Registration; +import com.shanebeestudios.skbee.api.registration.RegistryClassInfo; import com.shanebeestudios.skbee.api.util.ItemUtils; import com.shanebeestudios.skbee.api.util.MathUtil; import com.shanebeestudios.skbee.api.util.SkriptUtils; import com.shanebeestudios.skbee.api.util.Util; -import com.shanebeestudios.skbee.api.registration.RegistryClassInfo; import io.papermc.paper.connection.PlayerConnection; import io.papermc.paper.event.entity.EntityKnockbackEvent; import io.papermc.paper.event.player.PlayerFailMoveEvent; import net.kyori.adventure.audience.Audience; +import org.apache.commons.lang3.time.DurationFormatUtils; import org.bukkit.Chunk.LoadLevel; import org.bukkit.Color; import org.bukkit.JukeboxSong; @@ -564,6 +565,35 @@ public boolean canParse(ParseContext context) { "set {_time} to timespan(1, hour) + timespan(10, minutes)") .since("3.9.0") .register(); + + reg.newFunction(DefaultFunction.builder(reg.getAddon(), "formattedTimespan", String.class) + .parameter("timespan", Timespan.class) + .parameter("format", String.class) + .build(args -> { + Timespan timespan = args.get("timespan"); + String format = args.get("format"); + return DurationFormatUtils.formatDuration(timespan.getAs(Timespan.TimePeriod.MILLISECOND), format); + })) + .name("Formatted Timespan") + .description("Formats a Timespan into a string using a format.", + "**Available Formats**:", + " - `y` = years", + " - `M` = months", + " - `d` = days", + " - `H` = hours", + " - `m` = minutes", + " - `s` = seconds", + " - `S` = milliseconds", + " - `'text'` = arbitrary text content", + "**Note**: It's not currently possible to include a single-quote in a format.", + "Token values are printed using decimal digits.", + "A token character can be repeated to ensure that the field occupies a certain minimum size.", + "Values will be left-padded with 0 unless padding is disabled in the method invocation.") + .examples("set {_formatted} to formattedTimespan(1 hour, \"HH:mm:ss\")", + "set {_formatted} to formattedTimespan(1 hour, \"HH:mm:ss.SSS\")", + "set {_formatted} to formattedTimespan({_ts}, \"H 'hours and' m 'minutes'\")") + .since("INSERT VERSION") + .register(); } } diff --git a/src/main/java/com/shanebeestudios/skbee/elements/recipe/events/EvtRecipe.java b/src/main/java/com/shanebeestudios/skbee/elements/recipe/events/EvtRecipe.java index f32239ce..7b34ff96 100644 --- a/src/main/java/com/shanebeestudios/skbee/elements/recipe/events/EvtRecipe.java +++ b/src/main/java/com/shanebeestudios/skbee/elements/recipe/events/EvtRecipe.java @@ -1,10 +1,13 @@ package com.shanebeestudios.skbee.elements.recipe.events; import ch.njol.skript.lang.util.SimpleEvent; +import ch.njol.skript.registrations.EventConverter; import ch.njol.skript.registrations.EventValues; import com.shanebeestudios.skbee.api.registration.Registration; +import org.bukkit.NamespacedKey; import org.bukkit.event.block.CrafterCraftEvent; import org.bukkit.event.player.PlayerRecipeDiscoverEvent; +import org.jspecify.annotations.Nullable; public class EvtRecipe extends SimpleEvent { @@ -12,15 +15,33 @@ public static void register(Registration reg) { reg.newEvent(EvtRecipe.class, PlayerRecipeDiscoverEvent.class, "recipe discover[y]") .name("Recipe - Discover Event") - .description("Called when a player unlocks a recipe. ", - "`event-string` = the recipe namespace (this will also include either \"minecraft:\" or \"mykeyhere:\")", - "Requires MC 1.13+") + .description("Called when a player unlocks a recipe.", + "**Event Values**:", + " - `event-namespacedkey` = The recipe NamespacedKey (this will also include either \"minecraft:\" or \"mykeyhere:\")", + " - `event-string` = The recipe NamespacedKey as a string (this will also include either \"minecraft:\" or \"mykeyhere:\")", + " - `event-boolean` = Whether or not to show a notification (toast) to the player (can be set).") .examples("on recipe discover:", "\tif event-string = \"minecraft:diamond_block\"", "\t\tcancel event") .since("1.0.0") .register(); - EventValues.registerEventValue(PlayerRecipeDiscoverEvent.class, String.class, event -> event.getRecipe().toString(), EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerRecipeDiscoverEvent.class, String.class, + event -> event.getRecipe().toString(), + EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerRecipeDiscoverEvent.class, NamespacedKey.class, + PlayerRecipeDiscoverEvent::getRecipe, + EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerRecipeDiscoverEvent.class, Boolean.class, new EventConverter<>() { + @Override + public void set(PlayerRecipeDiscoverEvent event, @Nullable Boolean value) { + event.shouldShowNotification(Boolean.TRUE.equals(value)); + } + + @Override + public Boolean convert(PlayerRecipeDiscoverEvent event) { + return event.shouldShowNotification(); + } + }, EventValues.TIME_NOW); reg.newEvent(EvtRecipe.class, CrafterCraftEvent.class, "crafter craft") .name("Recipe - Crafter Craft Event")