Skip to content

Commit

Permalink
feat: support folia
Browse files Browse the repository at this point in the history
  • Loading branch information
NCT-skyouo committed Sep 29, 2024
1 parent 0a3496e commit 738fed4
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 69 deletions.
18 changes: 0 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,6 @@ shadowJar {
exclude('META-INF/**', 'LICENSE')
}

// Run task to build jar to another spot
tasks.register('server', Copy) {
from shadowJar
// Change this to wherever you want your jar to build
into '/Users/ShaneBee/Desktop/Server/Skript/1-21-1/plugins'
}

publishing {
publications {
maven(MavenPublication) {
groupId 'com.github.ShaneBeee'
artifactId 'SkBee'
version project.version
artifact shadowJar
artifact tasks.jar
}
}
}

javadoc {
destinationDir = file("${projectDir}/build/javadoc")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/shanebeestudios/skbee/AddonLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void loadSkriptElements() {

if (this.config.SETTINGS_DEBUG) {
// Print names of ClassInfos with missing lang entry
Bukkit.getScheduler().runTaskLater(this.plugin, () -> Classes.getClassInfos().forEach(classInfo -> {
Bukkit.getGlobalRegionScheduler().runDelayed(this.plugin, (ignored) -> Classes.getClassInfos().forEach(classInfo -> {
Noun name = classInfo.getName();
if (name.toString().contains("types.")) {
Util.log("ClassInfo missing lang entry for: &c%s", name);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/shanebeestudios/skbee/SkBee.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onEnable() {
Util.log("&ehttps://github.com/ShaneBeee/SkBee/issues");
}

new UpdateChecker(this);
// new UpdateChecker(this);
Util.log("&aSuccessfully enabled v%s&7 in &b%.2f seconds", version, (float) (System.currentTimeMillis() - start) / 1000);

// Load custom worlds if enabled in config
Expand All @@ -92,9 +92,9 @@ private void loadCommands() {
}

private void loadMetrics() { //6719
Metrics metrics = new Metrics(this, 6719);
/*Metrics metrics = new Metrics(this, 6719);
metrics.addCustomChart(new SimplePie("skript_version", () -> Skript.getVersion().toString()));
metrics.addCustomChart(new SimplePie("virtual_furnace", () -> String.valueOf(config.ELEMENTS_VIRTUAL_FURNACE)));
metrics.addCustomChart(new SimplePie("virtual_furnace", () -> String.valueOf(config.ELEMENTS_VIRTUAL_FURNACE)));*/
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ private void onEnterBed(PlayerBedEnterEvent event) {
private void onExitBed(PlayerBedLeaveEvent event) {
Player player = event.getPlayer();
Location from = event.getBed().getLocation();
Bukkit.getScheduler().runTaskLater(plugin, () -> {
player.getScheduler().runDelayed(plugin, (ignored) -> {
// Find player's new location after leaving bed
// have to add a delay as this isn't determinded in the event
Location to = player.getLocation();
if (preventBoundMovement(player, from, to)) {
player.teleport(from.clone().add(0, 1, 0));
}
}, 1);
}, null, 1);
}
}, plugin);

Expand All @@ -138,14 +138,14 @@ private void onMount(EntityMountEvent event) {
private void onDismount(EntityDismountEvent event) {
if (event.getEntity() instanceof Player player) {
Location from = event.getDismounted().getLocation().clone();
Bukkit.getScheduler().runTaskLater(plugin, () -> {
player.getScheduler().runDelayed(plugin, (ignored) -> {
Location to = player.getLocation();
if (preventBoundMovement(player, from, to)) {
from.setYaw(player.getLocation().getYaw());
from.setPitch(player.getLocation().getPitch());
player.teleport(from);
}
}, 1);
}, null, 1);
}
}
}, plugin);
Expand All @@ -168,14 +168,14 @@ private void onVehicleEnter(VehicleEnterEvent event) {
private void onVehicleExit(VehicleExitEvent event) {
Location from = event.getVehicle().getLocation().clone();
if (event.getExited() instanceof Player player) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
player.getScheduler().runDelayed(plugin, (ignored) -> {
Location to = player.getLocation();
if (preventBoundMovement(player, from, to)) {
from.setYaw(player.getLocation().getYaw());
from.setPitch(player.getLocation().getPitch());
player.teleport(from);
}
}, 1);
}, null, 1);
}
}
}, plugin);
Expand Down Expand Up @@ -204,15 +204,17 @@ private void onVehicleMove(VehicleMoveEvent event) {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onVehicleDestroy(VehicleDestroyEvent event) {
Location from = event.getVehicle().getLocation().clone();
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Bukkit.getRegionScheduler().runDelayed(plugin, from, (ignored) -> {
for (Entity passenger : event.getVehicle().getPassengers()) {
Location to = passenger.getLocation();
if (passenger instanceof Player player) {
if (preventBoundMovement(player, from, to)) {
from.setYaw(player.getLocation().getYaw());
from.setPitch(player.getLocation().getPitch());
player.teleport(from);
}
player.getScheduler().run(plugin, (ignored2) -> {
if (preventBoundMovement(player, from, to)) {
from.setYaw(player.getLocation().getYaw());
from.setPitch(player.getLocation().getPitch());
player.teleport(from);
}
} , null);
}
}
}, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public BoardManager() {
@EventHandler
private void onQuit(PlayerQuitEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
Bukkit.getScheduler().runTaskLater(PLUGIN, () -> removeBoard(uuid), 1);
Bukkit.getGlobalRegionScheduler().runDelayed(PLUGIN, (ignored) -> removeBoard(uuid), 1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (!player.hasPermission("skbee.update.check")) return;

Bukkit.getScheduler().runTaskLater(UpdateChecker.this.plugin, () -> getUpdateVersion(true).thenApply(version -> {
player.getScheduler().runDelayed(UpdateChecker.this.plugin, (ignored) -> getUpdateVersion(true).thenApply(version -> {
Util.sendColMsg(player, "&7[&bSk&3Bee&7] update available: &a" + version);
Util.sendColMsg(player, "&7[&bSk&3Bee&7] download at &bhttps://github.com/ShaneBeee/SkBee/releases");
return true;
}), 30);
}), null, 30);
}
}, this.plugin);
}
Expand Down Expand Up @@ -92,7 +92,7 @@ private CompletableFuture<Version> getUpdateVersion(boolean async) {
private CompletableFuture<Version> getLatestReleaseVersion(boolean async) {
CompletableFuture<Version> future = new CompletableFuture<>();
if (async) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
Bukkit.getAsyncScheduler().runNow(this.plugin, (ignored) -> {
Version lastest = getLastestVersionFromGitHub();
if (lastest == null) future.cancel(true);
future.complete(lastest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,20 @@
@Name("Task - Cancel Task")
@Description({"Stop tasks.",
"`stop all tasks` = Will stop all currently running tasks created with a task section.",
"`stop current task` = Will stop the task section this effect is in.",
"`stop task with id` = Will stop any task from an ID."})
"`stop current task` = Will stop the task section this effect is in."})
@Examples({"run 0 ticks later repeating every second:",
"\tset {-id} to current task id",
"\tadd 1 to {_a}",
"\tif {_a} > 10:",
"\t\tstop current task",
"",
"on unload:",
"\tstop all tasks",
"",
"on break:",
"\tstop task with id {-id}"})
"\tstop all tasks"})
@Since("3.3.0")
public class EffTaskStop extends Effect {

private static final BukkitScheduler SCHEDULER = Bukkit.getScheduler();

static {
Skript.registerEffect(EffTaskStop.class,
"(stop|cancel) all tasks", "(stop|cancel) current task", "(stop|cancel) task[s] with id[s] %numbers%");
"(stop|cancel) all tasks", "(stop|cancel) current task");
}

private int pattern;
Expand All @@ -51,9 +44,7 @@ public class EffTaskStop extends Effect {
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
this.pattern = matchedPattern;
if (matchedPattern == 2) {
this.ids = (Expression<Number>) exprs[0];
} else if (matchedPattern == 1) {
if (matchedPattern == 1) {
List<SecRunTaskLater> currentSections = getParser().getCurrentSections(SecRunTaskLater.class);
if (currentSections.isEmpty()) {
Skript.error("'" + parseResult.expr + "' can only be used in a run task section.");
Expand All @@ -70,19 +61,13 @@ protected void execute(Event event) {
switch (this.pattern) {
case 0 -> SecRunTaskLater.cancelTasks();
case 1 -> this.currentTask.stopCurrentTask();
case 2 -> {
for (Number id : this.ids.getArray(event)) {
SCHEDULER.cancelTask(id.intValue());
}
}
}
}

@Override
public @NotNull String toString(Event e, boolean d) {
return switch (this.pattern) {
case 1 -> "stop current task";
case 2 -> "stop task[s] with id[s] " + this.ids.toString(e, d);
default -> "stop all tasks";
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import ch.njol.skript.variables.Variables;
import ch.njol.util.Kleenean;
import com.shanebeestudios.skbee.SkBee;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.plugin.Plugin;
Expand All @@ -25,6 +26,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Name("Task - Run Task Later")
@Description({"Run a task later. Similar to Skript's delay effect, with the difference being everything in the",
Expand Down Expand Up @@ -52,7 +54,8 @@ public class SecRunTaskLater extends Section {
private static final Plugin PLUGIN = SkBee.getPlugin();

public static void cancelTasks() {
Bukkit.getScheduler().cancelTasks(PLUGIN);
Bukkit.getGlobalRegionScheduler().cancelTasks(PLUGIN);
Bukkit.getAsyncScheduler().cancelTasks(PLUGIN);
}

static {
Expand All @@ -64,6 +67,7 @@ public static void cancelTasks() {
private Expression<Timespan> timespan;
private Expression<Timespan> repeating;
private Trigger trigger;
private ScheduledTask scheduledTask;
private int currentTaskId;

@SuppressWarnings({"NullableProblems", "unchecked"})
Expand Down Expand Up @@ -93,7 +97,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
if (repeatingTimespan != null) repeat = repeatingTimespan.getTicks();
}

BukkitScheduler scheduler = Bukkit.getScheduler();
// BukkitScheduler scheduler = Bukkit.getScheduler();
Runnable runnable = () -> {
Variables.setLocalVariables(event, localVars);
assert first != null;
Expand All @@ -102,23 +106,23 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
Variables.removeLocals(event);
};

BukkitTask task;
ScheduledTask task;
if (repeat > 0 && async) {
task = scheduler.runTaskTimerAsynchronously(PLUGIN, runnable, delay, repeat);
task = Bukkit.getAsyncScheduler().runAtFixedRate(PLUGIN, (ignored) -> runnable.run(), delay * 50, repeat * 50, TimeUnit.MILLISECONDS);
} else if (repeat > 0) {
task = scheduler.runTaskTimer(PLUGIN, runnable, delay, repeat);
task = Bukkit.getGlobalRegionScheduler().runAtFixedRate(PLUGIN, (ignored) -> runnable.run(), delay, repeat);
} else if (async) {
task = scheduler.runTaskLaterAsynchronously(PLUGIN, runnable, delay);
task = Bukkit.getAsyncScheduler().runDelayed(PLUGIN, (ignored) -> runnable.run(), delay * 50, TimeUnit.MILLISECONDS);
} else {
task = scheduler.runTaskLater(PLUGIN, runnable, delay);
task = Bukkit.getGlobalRegionScheduler().runDelayed(PLUGIN, (ignored) -> runnable.run(), delay);
}
this.currentTaskId = task.getTaskId();
this.currentTaskId = task.hashCode();
if (last != null) last.setNext(null);
return super.walk(event, false);
}

public void stopCurrentTask() {
Bukkit.getScheduler().cancelTask(this.currentTaskId);
scheduledTask.cancel();
}

public int getCurrentTaskId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ch.njol.skript.util.slot.Slot;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;

import org.bukkit.event.block.CrafterCraftEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private CompletableFuture<WorldCreator> cloneWorld() {

// Let's clone files on another thread
CompletableFuture<WorldCreator> worldCompletableFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTaskAsynchronously(SkBee.getPlugin(), () -> {
Bukkit.getAsyncScheduler().runNow(SkBee.getPlugin(), (ignored) -> {
File cloneDirectory = new File(worldContainer, cloneName);
if (worldDirectorToClone.exists()) {
try {
Expand All @@ -269,10 +269,10 @@ private CompletableFuture<WorldCreator> cloneWorld() {
}
}
WorldCreator creator = getWorldCreator(cloneName, this.key);
Bukkit.getScheduler().runTaskLater(SkBee.getPlugin(), () -> {
Bukkit.getGlobalRegionScheduler().runDelayed(SkBee.getPlugin(), (ignored2) -> {
// Let's head back to the main thread
worldCompletableFuture.complete(creator);
}, 0);
}, 1);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 738fed4

Please sign in to comment.