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