folia
This commit is contained in:
3 files changed
+45
-5
No files matched your search
+1
-1
@@ -54,7 +54,7 @@ dependencies {
|
||||
}
|
||||
|
||||
compileOnly("org.checkerframework", "checker-qual", "3.32.0")
|
||||
compileOnly("io.papermc.paper", "paper-api", "1.19.2-R0.1-SNAPSHOT")
|
||||
compileOnly("dev.folia", "folia-api", "1.19.4-R0.1-SNAPSHOT")
|
||||
compileOnly("me.clip", "placeholderapi", "2.11.2")
|
||||
}
|
||||
|
||||
|
||||
@@ -173,6 +173,7 @@ public class Chat {
|
||||
this.plugin.audiences().player(player).sendActionBar(this.plugin.miniMessage().deserialize(text));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public BukkitTask sendActionBar(Player player, int durationSeconds, String text) {
|
||||
final BukkitTask task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.plugin, () -> this.sendActionBar(player, text), 0, 20L * 2);
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, task::cancel, 20L * durationSeconds);
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package xyz.jpenilla.pluginbase.legacy;
|
||||
|
||||
import io.papermc.paper.threadedregions.RegionizedServerInitEvent;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -16,6 +21,7 @@ public abstract class PluginBase extends JavaPlugin {
|
||||
private BukkitAudiences audiences;
|
||||
private final MiniMessage miniMessage;
|
||||
private Path dataPath;
|
||||
private final Queue<Runnable> initTasks = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public PluginBase() {
|
||||
super();
|
||||
@@ -29,19 +35,34 @@ public abstract class PluginBase extends JavaPlugin {
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
instance = this;
|
||||
this.setupInitListener();
|
||||
|
||||
this.dataPath = getDataFolder().toPath();
|
||||
this.dataPath = this.getDataFolder().toPath();
|
||||
this.audiences = BukkitAudiences.create(this);
|
||||
|
||||
this.checkForPlaceholderApi();
|
||||
// In case the softdepend is missing...
|
||||
this.getServer().getScheduler().runTask(this, this::checkForPlaceholderApi);
|
||||
this.initTasks.add(this::checkForPlaceholderApi);
|
||||
|
||||
this.chat = new Chat(this);
|
||||
|
||||
this.enable();
|
||||
}
|
||||
|
||||
public abstract void enable();
|
||||
|
||||
@Override
|
||||
public final void onDisable() {
|
||||
this.disable();
|
||||
instance = null;
|
||||
if (this.audiences != null) {
|
||||
this.audiences.close();
|
||||
this.audiences = null;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void disable();
|
||||
|
||||
private void checkForPlaceholderApi() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
this.placeholderApi = new PlaceholderAPIHook();
|
||||
@@ -50,8 +71,6 @@ public abstract class PluginBase extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void enable();
|
||||
|
||||
public @NonNull Chat chat() {
|
||||
return this.chat;
|
||||
}
|
||||
@@ -71,4 +90,24 @@ public abstract class PluginBase extends JavaPlugin {
|
||||
public @NonNull Path dataPath() {
|
||||
return this.dataPath;
|
||||
}
|
||||
|
||||
private void setupInitListener() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
this.getServer().getPluginManager().registerEvents(new Listener() {
|
||||
@EventHandler
|
||||
public void handle(final RegionizedServerInitEvent event) {
|
||||
PluginBase.this.onInit();
|
||||
}
|
||||
}, this);
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
this.getServer().getScheduler().runTask(this, this::onInit);
|
||||
}
|
||||
}
|
||||
|
||||
private void onInit() {
|
||||
for (Runnable task; (task = this.initTasks.poll()) != null; ) {
|
||||
task.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user