Skip to content
Merged
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
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ paperweight {
addServerDependencyTo = configurations.named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME).map { setOf(it) }
}

runPaper.folia.registerTask()

tasks {
runServer {
minecraftVersion(minecraftVersion)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package toutouchien.niveriaapi.menu.component.interactive;

import com.google.common.base.Preconditions;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
Expand Down Expand Up @@ -48,12 +49,12 @@ public class Button extends MenuComponent {
@Nullable private Function<MenuContext, ObjectList<ItemStack>> animationFrames;
private int animationInterval;
private boolean stopAnimationOnHide;
@Nullable private BukkitTask animationTask;
@Nullable private ScheduledTask animationTask;
private int currentFrame;

private int updateInterval;
private boolean stopUpdatesOnHide;
@Nullable private BukkitTask updateTask;
@Nullable private ScheduledTask updateTask;

/**
* Constructs a new Button with the specified configuration.
Expand Down Expand Up @@ -174,7 +175,7 @@ public Int2ObjectMap<ItemStack> items(MenuContext context) {
* @param context the menu context
*/
private void startAnimation(MenuContext context) {
this.animationTask = Task.syncRepeat(() -> {
this.animationTask = Task.syncRepeat(ignored -> {
if (!enabled() || (this.stopAnimationOnHide && !visible())) {
stopAnimation();
return;
Expand Down Expand Up @@ -213,7 +214,7 @@ private void stopAnimation() {
* @param context the menu context
*/
private void startUpdates(MenuContext context) {
this.updateTask = Task.syncRepeat(() -> {
this.updateTask = Task.syncRepeat(ignored -> {
if (!enabled() || (this.stopUpdatesOnHide && !visible())) {
stopUpdates();
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package toutouchien.niveriaapi.menu.component.interactive;

import com.google.common.base.Preconditions;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class DoubleDropButton extends MenuComponent {

@Nullable private Sound sound;

@Nullable private BukkitTask dropTask;
@Nullable private ScheduledTask dropTask;

/**
* Constructs a new DoubleDropButton with the specified configuration.
Expand Down Expand Up @@ -149,7 +150,7 @@ private void handleDropClick(NiveriaInventoryClickEvent event, MenuContext conte
if (this.onDoubleDrop != null)
this.onDoubleDrop.accept(event);
} else {
this.dropTask = Task.syncLater(() -> {
this.dropTask = Task.syncLater(ignored -> {
this.dropTask = null;
render(context);
}, NiveriaAPI.instance(), 3L, TimeUnit.SECONDS);
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/toutouchien/niveriaapi/utils/ParticleUtils.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package toutouchien.niveriaapi.utils;

import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
import org.bukkit.*;
import org.bukkit.craftbukkit.CraftParticle;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import toutouchien.niveriaapi.annotations.Shivery;

Expand Down Expand Up @@ -509,15 +509,15 @@ public static void drawCube(Location corner1, Location corner2, Particle particl
* @param speed particle speed
* @param durationTicks total duration in ticks, or -1 to run indefinitely
* @param interval interval in ticks between spawns
* @return the scheduled {@link BukkitTask}
* @return the scheduled {@link ScheduledTask}
*/
public static BukkitTask followEntity(Entity entity, Plugin plugin, Particle particle, int count, double offsetX, double offsetY, double offsetZ, double speed, long durationTicks, long interval) {
BukkitTask task = Task.syncRepeat(() -> {
public static ScheduledTask followEntity(Entity entity, Plugin plugin, Particle particle, int count, double offsetX, double offsetY, double offsetZ, double speed, long durationTicks, long interval) {
ScheduledTask task = Task.runRepeat(ignored -> {
if (!entity.isValid())
return;

spawnParticle(entity.getLocation().add(0, 1, 0), particle, count, offsetX, offsetY, offsetZ, speed, null, false);
}, plugin, 0, interval * 50L, TimeUnit.MILLISECONDS);
}, plugin, entity, 0, interval * 50L, TimeUnit.MILLISECONDS);

if (durationTicks == -1)
return task;
Expand Down Expand Up @@ -567,15 +567,20 @@ public static void drawParametricCurve(Location center, Particle particle, Doubl
public static void animateParticles(Plugin plugin, List<Location> frames, Particle particle, int count, double offsetX, double offsetY, double offsetZ, double speed, long ticksPerFrame, long durationTicks, boolean loop) {
final int[] currentFrame = {0};

BukkitTask task = Task.syncRepeat(() -> {
ScheduledTask task = Task.runRepeat(t -> {
if (currentFrame[0] >= frames.size() && loop)
currentFrame[0] = 0; // Loop animation (optional)

if (currentFrame[0] >= frames.size()) {
t.cancel();
return;
}

Location location = frames.get(currentFrame[0]);
spawnParticle(location, particle, count, offsetX, offsetY, offsetZ, speed, null, false);

currentFrame[0]++;
}, plugin, 0, ticksPerFrame * 50L, TimeUnit.MILLISECONDS);
}, plugin, frames.get(currentFrame[0]), 0, ticksPerFrame * 50L, TimeUnit.MILLISECONDS);
Comment thread
PuppyTransGirl marked this conversation as resolved.

if (durationTicks == -1)
return;
Expand Down Expand Up @@ -615,4 +620,4 @@ public static void drawGradient(Location start, Location end, int steps, DoubleF
spawnParticle(particleLocation, Particle.DUST, 1, offsetX, offsetY, offsetZ, speed, dustOptions, false);
}
}
}
}
Loading
Loading