Skip to content

Commit

Permalink
Energie pour Folia et Spigot
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Mar 2, 2024
1 parent a72eb2d commit e23eee6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/CommonConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fun Project.applyCommonConfiguration() {
snapshotsOnly()
}
}
maven { url = uri("https://jitpack.io") }
}

configurations.all {
Expand Down
2 changes: 2 additions & 0 deletions worldedit-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies {
"implementation"("org.bstats:bstats-bukkit:2.2.1")
"implementation"("it.unimi.dsi:fastutil")
"testImplementation"("org.mockito:mockito-core:1.9.0-rc1")
"implementation"("com.github.Euphillya:Energie:26cdee42f4")

project.project(":worldedit-bukkit:adapters").subprojects.forEach {
"adapters"(project(it.path))
Expand Down Expand Up @@ -91,6 +92,7 @@ tasks.named<ShadowJar>("shadowJar") {
include(dependency("io.papermc:paperlib"))
include(dependency("it.unimi.dsi:fastutil"))
include(dependency("com.sk89q.lib:jlibnoise"))
include(dependency("com.github.Euphillya:Energie"))

exclude(dependency("$group:$name"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import fr.euphyllia.energie.Energie;
import fr.euphyllia.energie.model.SchedulerType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -156,11 +158,11 @@ public boolean isActive() {
updateActive();
} else {
// we should update it eventually
Bukkit.getScheduler().callSyncMethod(plugin,
() -> {
updateActive();
return null;
});
WorldEditPlugin.getEnergieTask().getScheduler(Energie.SchedulerSoft.MINECRAFT).execute(
SchedulerType.GLOBAL, schedulerTaskInter -> {
updateActive();
}
);
}
return active;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.sk89q.worldedit.util.lifecycle.Lifecycled;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.registry.Registries;
import fr.euphyllia.energie.Energie;
import fr.euphyllia.energie.model.SchedulerType;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
Expand All @@ -51,6 +53,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -121,7 +124,15 @@ public void reload() {

@Override
public int schedule(long delay, long period, Runnable task) {
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
AtomicInteger taskId = new AtomicInteger(0);
WorldEditPlugin.getEnergieTask().getScheduler(Energie.SchedulerSoft.MINECRAFT)
.runAtFixedRate(SchedulerType.GLOBAL, delay, period, schedulerTaskInter -> {
task.run();
if (schedulerTaskInter != null) {
taskId.set(schedulerTaskInter.getTaskId());
}
});
return taskId.get();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.sk89q.worldedit.world.item.ItemCategory;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.weather.WeatherTypes;
import fr.euphyllia.energie.Energie;
import io.papermc.lib.PaperLib;
import org.apache.logging.log4j.Logger;
import org.bstats.bukkit.Metrics;
Expand Down Expand Up @@ -116,6 +117,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
public static final String CUI_PLUGIN_CHANNEL = "worldedit:cui";
private static WorldEditPlugin INSTANCE;
private static final int BSTATS_PLUGIN_ID = 3328;
private static fr.euphyllia.energie.Energie energieTask; // Euphyllia

private final SimpleLifecycled<BukkitImplAdapter> adapter =
SimpleLifecycled.invalid();
Expand Down Expand Up @@ -154,6 +156,7 @@ public void onEnable() {
// Catch bad things being done by naughty plugins that include
// WorldEdit's classes
ClassSourceValidator verifier = new ClassSourceValidator(this);
energieTask = new Energie(this); // Euphyllia
verifier.reportMismatches(ImmutableList.of(World.class, CommandManager.class, EditSession.class, Actor.class));

WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent());
Expand Down Expand Up @@ -321,7 +324,8 @@ public void onDisable() {
if (config != null) {
config.unload();
}
this.getServer().getScheduler().cancelTasks(this);
getEnergieTask().getScheduler(Energie.SchedulerSoft.MINECRAFT).cancelAllTask();
getEnergieTask().getScheduler(Energie.SchedulerSoft.NATIVE).cancelAllTask();
}

/**
Expand Down Expand Up @@ -569,4 +573,10 @@ public void onAsyncTabComplete(com.destroystokyo.paper.event.server.AsyncTabComp
event.setHandled(true);
}
}

// Euphyllia start
public static Energie getEnergieTask() {
return energieTask;
}
// Euphyllia end
}
3 changes: 2 additions & 1 deletion worldedit-bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ load: STARTUP
api-version: 1.13
softdepend: [Vault]
author: EngineHub
website: https://enginehub.org/worldedit
website: https://enginehub.org/worldedit
folia-supported: true

0 comments on commit e23eee6

Please sign in to comment.