mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Add lightweight support for folia via MorePaperLib (#376)
This commit is contained in:
1 parent
5d9ac81bcd
commit
0606e49d02
10 files changed
+88
-25
No files matched your search
@@ -62,6 +62,7 @@ jobs:
|
||||
spigot
|
||||
paper
|
||||
purpur
|
||||
folia
|
||||
game-versions: |
|
||||
1.16.5
|
||||
1.17.1
|
||||
|
||||
@@ -50,6 +50,7 @@ jobs:
|
||||
spigot
|
||||
paper
|
||||
purpur
|
||||
folia
|
||||
game-versions: |
|
||||
1.16.5
|
||||
1.17.1
|
||||
|
||||
@@ -38,6 +38,7 @@ allprojects {
|
||||
maven { url 'https://libraries.minecraft.net/' }
|
||||
maven { url 'https://api.modrinth.com/maven' }
|
||||
maven { url 'https://repo.papermc.io/repository/maven-public/' }
|
||||
maven { url 'https://mvn-repo.arim.space/lesser-gpl3/' }
|
||||
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
|
||||
maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
|
||||
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@ dependencies {
|
||||
|
||||
implementation 'org.bstats:bstats-bukkit:3.0.2'
|
||||
implementation 'io.papermc:paperlib:1.0.8'
|
||||
implementation 'space.arim.morepaperlib:morepaperlib:0.4.2'
|
||||
implementation 'me.lucko:commodore:2.2'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.0'
|
||||
|
||||
@@ -12,7 +13,7 @@ dependencies {
|
||||
compileOnly 'net.william278:Annotaml:2.0.1'
|
||||
compileOnly 'net.william278:DesertWell:2.0.2'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
|
||||
compileOnly 'com.github.Emibergo02:RedisEconomy:4.0-SNAPSHOT'
|
||||
compileOnly 'com.github.Emibergo02:RedisEconomy:master-SNAPSHOT'
|
||||
compileOnly 'me.clip:placeholderapi:2.11.3'
|
||||
|
||||
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2'
|
||||
@@ -46,5 +47,6 @@ shadowJar {
|
||||
relocate 'net.kyori', 'net.william278.huskhomes.libraries'
|
||||
relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats'
|
||||
relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
relocate 'space.arim.morepaperlib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
relocate 'me.lucko.commodore', 'net.william278.huskhomes.libraries.commodore'
|
||||
}
|
||||
@@ -62,11 +62,15 @@ import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import space.arim.morepaperlib.MorePaperLib;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
import space.arim.morepaperlib.scheduling.ScheduledTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -76,6 +80,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
* Metrics ID for <a href="https://bstats.org/plugin/bukkit/HuskHomes/8430">HuskHomes on Bukkit</a>.
|
||||
*/
|
||||
private static final int METRICS_ID = 8430;
|
||||
private ConcurrentHashMap<Integer, ScheduledTask> tasks;
|
||||
private Set<SavedUser> savedUsers;
|
||||
private Settings settings;
|
||||
private Locales locales;
|
||||
@@ -94,6 +99,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
@Nullable
|
||||
private Broker broker;
|
||||
private BukkitAudiences audiences;
|
||||
private MorePaperLib paperLib;
|
||||
|
||||
private static BukkitHuskHomes instance;
|
||||
|
||||
@@ -122,6 +128,8 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
public void onEnable() {
|
||||
// Create adventure audience
|
||||
this.audiences = BukkitAudiences.create(this);
|
||||
this.paperLib = new MorePaperLib(this);
|
||||
this.tasks = new ConcurrentHashMap<>();
|
||||
this.savedUsers = new HashSet<>();
|
||||
this.globalPlayerList = new HashMap<>();
|
||||
this.currentlyOnWarmup = new HashSet<>();
|
||||
@@ -460,10 +468,21 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public GracefulScheduling getScheduler() {
|
||||
return paperLib.scheduling();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ConcurrentHashMap<Integer, ScheduledTask> getTasks() {
|
||||
return tasks;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HuskHomes getPlugin() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,7 +26,6 @@ import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.TeleportationException;
|
||||
import net.william278.huskhomes.util.BukkitAdapter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
@@ -35,6 +34,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ public class BukkitUser extends OnlineUser {
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return Position.at(BukkitAdapter.adaptLocation(player.getLocation())
|
||||
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
|
||||
.orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
|
||||
plugin.getServerName());
|
||||
|
||||
}
|
||||
@@ -105,23 +105,29 @@ public class BukkitUser extends OnlineUser {
|
||||
|
||||
@Override
|
||||
public void teleportLocally(@NotNull Location location, boolean asynchronous) throws TeleportationException {
|
||||
// Ensure the world exists
|
||||
final Optional<org.bukkit.Location> resolvedLocation = BukkitAdapter.adaptLocation(location);
|
||||
if (resolvedLocation.isEmpty() || resolvedLocation.get().getWorld() == null) {
|
||||
throw new TeleportationException(TeleportationException.Type.WORLD_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Ensure the coordinates are within the world limits
|
||||
final org.bukkit.Location bukkitLocation = resolvedLocation.get();
|
||||
if (!bukkitLocation.getWorld().getWorldBorder().isInside(resolvedLocation.get())) {
|
||||
throw new TeleportationException(TeleportationException.Type.ILLEGAL_TARGET_COORDINATES);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (asynchronous) {
|
||||
PaperLib.teleportAsync(player, bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
} else {
|
||||
player.teleport(bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
}
|
||||
});
|
||||
// Run on the appropriate thread scheduler for this platform
|
||||
plugin.getScheduler().entitySpecificScheduler(player).run(
|
||||
() -> {
|
||||
if (asynchronous || plugin.getScheduler().isUsingFolia()) {
|
||||
PaperLib.teleportAsync(player, bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
return;
|
||||
}
|
||||
player.teleport(bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
},
|
||||
() -> plugin.getLogger().log(Level.WARNING, "User offline when teleporting: " + player.getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,54 +19,76 @@
|
||||
|
||||
package net.william278.huskhomes.util;
|
||||
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
import space.arim.morepaperlib.scheduling.ScheduledTask;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface BukkitTaskRunner extends TaskRunner {
|
||||
|
||||
@Override
|
||||
default int runAsync(@NotNull Runnable runnable) {
|
||||
return Bukkit.getScheduler().runTaskAsynchronously((BukkitHuskHomes) getPlugin(), runnable).getTaskId();
|
||||
final int taskId = getTasks().size();
|
||||
getTasks().put(taskId, getScheduler().asyncScheduler().run(runnable));
|
||||
return taskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
default <T> CompletableFuture<T> supplyAsync(@NotNull Supplier<T> supplier) {
|
||||
final CompletableFuture<T> future = new CompletableFuture<>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously((BukkitHuskHomes) getPlugin(),
|
||||
() -> future.complete(supplier.get()));
|
||||
getScheduler().asyncScheduler().run(() -> future.complete(supplier.get()));
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
default void runSync(@NotNull Runnable runnable) {
|
||||
Bukkit.getScheduler().runTask((BukkitHuskHomes) getPlugin(), runnable).getTaskId();
|
||||
getScheduler().globalRegionalScheduler().run(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
default int runAsyncRepeating(@NotNull Runnable runnable, long period) {
|
||||
AtomicInteger taskId = new AtomicInteger();
|
||||
taskId.set(Bukkit.getScheduler().runTaskTimerAsynchronously((BukkitHuskHomes) getPlugin(),
|
||||
runnable, 0, period).getTaskId());
|
||||
return taskId.get();
|
||||
final int taskId = getTasks().size();
|
||||
getTasks().put(taskId, getScheduler().asyncScheduler().runAtFixedRate(
|
||||
runnable,
|
||||
Duration.ZERO,
|
||||
getDurationTicks(period)
|
||||
));
|
||||
return taskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
default void runLater(@NotNull Runnable runnable, long delay) {
|
||||
Bukkit.getScheduler().runTaskLater((BukkitHuskHomes) getPlugin(), runnable, delay).getTaskId();
|
||||
getScheduler().asyncScheduler().runDelayed(runnable, getDurationTicks(delay));
|
||||
}
|
||||
|
||||
@Override
|
||||
default void cancelTask(int taskId) {
|
||||
Bukkit.getScheduler().cancelTask(taskId);
|
||||
if (getTasks().containsKey(taskId)) {
|
||||
getTasks().get(taskId).cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default void cancelAllTasks() {
|
||||
Bukkit.getScheduler().cancelTasks((BukkitHuskHomes) getPlugin());
|
||||
getTasks().values().forEach(ScheduledTask::cancel);
|
||||
getTasks().clear();
|
||||
getScheduler().cancelGlobalTasks();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
GracefulScheduling getScheduler();
|
||||
|
||||
@NotNull
|
||||
ConcurrentHashMap<Integer, ScheduledTask> getTasks();
|
||||
|
||||
@NotNull
|
||||
default Duration getDurationTicks(long ticks) {
|
||||
return Duration.of(ticks * 50, ChronoUnit.MILLIS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,13 +26,22 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface TaskRunner {
|
||||
|
||||
int runAsync(@NotNull Runnable runnable);
|
||||
|
||||
<T> CompletableFuture<T> supplyAsync(@NotNull Supplier<T> supplier);
|
||||
|
||||
void runSync(@NotNull Runnable runnable);
|
||||
|
||||
int runAsyncRepeating(@NotNull Runnable runnable, long delay);
|
||||
|
||||
void runLater(@NotNull Runnable runnable, long delay);
|
||||
|
||||
void cancelTask(int taskId);
|
||||
|
||||
void cancelAllTasks();
|
||||
|
||||
@NotNull
|
||||
HuskHomes getPlugin();
|
||||
|
||||
}
|
||||
@@ -42,6 +42,7 @@ shadowJar {
|
||||
relocate 'net.kyori', 'net.william278.huskhomes.libraries'
|
||||
relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats'
|
||||
relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
relocate 'space.arim.morepaperlib', 'net.william278.huskhomes.libraries.paperlib'
|
||||
relocate 'me.lucko.commodore', 'net.william278.huskhomes.libraries.commodore'
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ main: 'net.william278.huskhomes.PaperHuskHomes'
|
||||
loader: 'net.william278.huskhomes.PaperHuskHomesLoader'
|
||||
version: '${version}'
|
||||
api-version: 1.19
|
||||
folia-supported: true
|
||||
dependencies:
|
||||
- name: Vault
|
||||
required: false
|
||||
|
||||
Reference in new issue
Block a user